Skip to content
Snippets Groups Projects
Commit 1413ddc9 authored by Johannes Hörmann's avatar Johannes Hörmann
Browse files

Documentation of classification and deprecation of data lib

parent e26535a4
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
<neonContext xmlns="http://www.adito.de/2018/ao/Model" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" VERSION="1.1.0" xsi:schemaLocation="http://www.adito.de/2018/ao/Model adito://models/xsd/neonContext/1.1.0">
<name>Classification</name>
<majorModelMode>DISTRIBUTED</majorModelMode>
<documentation>%aditoprj%/neonContext/Classification/documentation.adoc</documentation>
<editview>ClassificatonAdminEdit_view</editview>
<entity>Classification_entity</entity>
<references>
......
This entity has two modes: normal mode and admin mode. If just called over #PROVIDER it is in admin mode. Use the respective views and providers.
\ No newline at end of file
How to use the DataLib (state: 21.01.2019)
==========================================
:toc2: left
:numbered:
== What is the DataLib ==
The data lib provides objects for a more easy data structure creation.
Currently the lib provides
* DataTree
** an object for building a tree structure
* ReferencingData
** a wrapper for DataTree
** the programmer doesn't have to decide if the tree is needed, or if a simple array is sufficient. This Class will use the tree only if needed.
== DataTree ==
See the library comments for further explanations.
The purpose of this lib is
* creating a tree object
* creating an array with uid and parent from the tree object (e.g. for treetables and charts)
* resolve problems with adding the same item multiple times (by creating new uuids)
=== usage ===
* import the lib:
[source,javascript]
----
import("Data_lib");
----
* create an object
[source,javascript]
----
var myDescriptiveNameOfTheTree = new DataTree(alias);
// or
var myDescriptiveNameOfTheTree = DataTree.begin(alias);
----
* use the object, add conditions with add(uid, parent, itemArray)
[source,javascript]
----
var myTree = myDescriptiveNameOfTheTree.add("1", "myRoot", ["itemId1", "value"])
.add("2", "myRoot", ["itemId2", "value"])
.add("3", "2", ["itemId3", "value"])
.add("4", "2", ["itemId4", "value"])
.add("5", "4", ["itemId5", "value"])
.add("5", "3", ["itemId5", "value"]) // Now you added id "5" a second time, overrides previous entry with id 5
.getTreeObject();
var myArray = myDescriptiveNameOfTheTree.toArray();
----
Note that if you add an item two times, only the data-array of the second item is used! It will overwrite the data from the first one!
== ReferencingData ==
See the library comments for further explanations.
The purpose of this lib is
* creating an array with uid and parent from the tree object (e.g. for treetables and charts)
* resolve problems with adding the same item multiple times (by creating new uuids)
It is a wrapper for DataTree, but only uses the tree if needed. Otherwise the data is just concatenated to an array.
It does not provide getTreeObject() because the tree is not always built.
=== usage ===
* import the lib:
[source,javascript]
----
import("Data_lib");
----
* create an object
[source,javascript]
----
var myDescriptiveName = new ReferencingData(alias);
// or
var myDescriptiveName = ReferencingData.begin(alias);
----
* use the object, add conditions
[source,javascript]
----
var myTree = myDescriptiveName.add("1", "myRoot", ["itemId1", "value"])
.add("2", "myRoot", ["itemId2", "value"])
.add("3", "2", ["itemId3", "value"])
.add("4", "2", ["itemId4", "value"])
.add("5", "4", ["itemId5", "value"])
.add("5", "3", ["itemId5", "value"]) // Now you added id "5" a seccond time. After this line the tree is used.
.toArray();
----
Note that if you add an item two times, only the data-array of the second item is used! It will overwrite the data from the first one!
== When to use which ==
If you only need an array with parent - child - structure e.g. for the treetable or charts, use
ReferencingData
If you need a tree object for your logic, use DataTree.
\ No newline at end of file
import("system.logging");
import("system.vars");
import("system.db");
import("Sql_lib");
......@@ -12,10 +11,14 @@ import("Sql_lib");
function ClassificationUtils() {}
/**
* Get the id of the current context
* TODO: use a UUID of the current context which doesn't change
* Get the score of the classification. You can get all groups at once or only the score for one group.
*
* @param {String} pClassificationType the classification-type (usage) e.g. the Keyid from Keyord ClassificationType
* @param {String} pObjectType the object type
* @param {String} pObjectRowid the rowid
* @param {String} [pClassificationGroup=undefined] the classification group. If it is undefined, the classification for all groups are returned as Object(-map)
*
* @return {String} Id of the current context
* @return {Object} return all scores as Object-map. E.g. {"scoreGroup1": "A", "scoreGroup2": "C"}
*/
ClassificationUtils.getScore = function(pClassificationType, pObjectType, pObjectRowid, pClassificationGroup)
{
......@@ -31,10 +34,7 @@ ClassificationUtils.getScore = function(pClassificationType, pObjectType, pObjec
left join CLASSIFICATIONSCORE on CLASSIFICATIONSCORE_ID = CLASSIFICATIONSCOREID",
"1=2",
"group by CLASSIFICATIONTYPE.CLASSIFICATIONGROUP order by CLASSIFICATIONTYPE.CLASSIFICATIONGROUP asc"));
if (score.length == 1)
return score[0][1];
var scores = {};
score.forEach(function(pRow)
{
......@@ -43,6 +43,15 @@ ClassificationUtils.getScore = function(pClassificationType, pObjectType, pObjec
return scores;
}
/**
* get all classifications for one dataset as String. Each char represents one classification.
*
* @param {String} pClassificationType the classification-type (usage) e.g. the Keyid from Keyord ClassificationType
* @param {String} pObjectType the object type
* @param {String} pObjectRowid the rowid
*
* @return {String} the resulting classification. E.g. "ACB"
*/
ClassificationUtils.getClass = function(pClassificationType, pObjectType, pObjectRowid)
{
var score = ClassificationUtils.getScore(pClassificationType, pObjectType, pObjectRowid);
......@@ -52,9 +61,20 @@ ClassificationUtils.getClass = function(pClassificationType, pObjectType, pObjec
}).join("");
}
/**
* get the classification for a score.
* The classes are hardcoded like this:
* >=0 to 25: D
* > 25 to 50: C
* > 50 to 75: B
* > 75 to 100: A
* < 0 || > 100: _
*
* @return {String}
*/
ClassificationUtils.mapToClass = function(pScore)
{
if(pScore >= 0 && pScore <= 50)
if(pScore >= 0 && pScore <= 25)
return "D";
if(pScore > 25 && pScore <= 50)
return "C";
......@@ -66,18 +86,31 @@ ClassificationUtils.mapToClass = function(pScore)
return "_";
}
ClassificationUtils.getAllGroups = function(pClassificationtype, twoCol)
/**
* Get all possible groupnames for a classificationtype
* Either as [["group", "group"]] (for the possible items process)
* Or as [["group"]].
*
* @param {String} pClassificationtype the classificationtype
* @param {Boolean} pTwoCol use two columns (for possible items process)
*/
ClassificationUtils.getAllGroups = function(pClassificationtype, pTwoCol)
{
var sql = SqlCondition.begin()
.andPrepare("CLASSIFICATIONTYPE.CLASSIFICATIONTYPE", pClassificationtype)
.buildSql("select distinct CLASSIFICATIONGROUP" + (twoCol ? ", CLASSIFICATIONGROUP" : "") + " from CLASSIFICATIONTYPE", "", " order by CLASSIFICATIONGROUP")
.buildSql("select distinct CLASSIFICATIONGROUP" + (pTwoCol ? ", CLASSIFICATIONGROUP" : "") + " from CLASSIFICATIONTYPE", "", " order by CLASSIFICATIONGROUP")
if (twoCol)
if (pTwoCol)
return db.table(sql);
else
return db.array(db.COLUMN, sql);
}
/**
* Load the classificationgroup for a classificaitonTypeId from the db.
*
* @param {String} pClassificationtypeId the id
*/
ClassificationUtils.getGroupFromDb = function(pClassificationtypeId)
{
return db.cell(SqlCondition.begin()
......@@ -85,6 +118,14 @@ ClassificationUtils.getGroupFromDb = function(pClassificationtypeId)
.buildSql("select CLASSIFICATIONGROUP from CLASSIFICATIONTYPE", "", " order by CLASSIFICATIONGROUP"))
}
/**
* Update the groupname. Checks if it is already used and only updates it, if not.
* TODO: message to the user if it failed? (or return value - bool?)
*
* @param {String} pOldName the name it was before
* @param {String} pNewName the new name
* @param {String} pClassificationType the classificationtype
*/
ClassificationUtils.changeGroupName = function(pOldName, pNewName, pClassificationType)
{
var groups = ClassificationUtils.getAllGroups(pClassificationType, false)
......@@ -95,6 +136,13 @@ ClassificationUtils.changeGroupName = function(pOldName, pNewName, pClassificati
}
}
/**
* get the classificationType for the current classification (either vom parameter or selection-variable)
* @param {String} pParamField the parameter field name. e.G. "$param.ClassificationType_param"
* @param {String} pSelectionField the parameter field name. e.G. "$sys.selectionRows"
*
* @return {String} the type (or undefined)
*/
ClassificationUtils.getUsageType = function(pParamField, pSelectionField)
{
if (vars.exists(pParamField) && vars.get(pParamField))
......@@ -111,10 +159,13 @@ ClassificationUtils.getUsageType = function(pParamField, pSelectionField)
return classificationType;
}
/**
* Update the coreName of a type
*
* @param {String} pNewScoreName
* @param {String} pClassificationTypeId
*/
ClassificationUtils.changeScoreName = function(pNewScoreName, pClassificationTypeId)
{
logging.log(pNewScoreName)
logging.log(pClassificationTypeId)
db.updateData("CLASSIFICATIONTYPE", ["SCORETYPE"], null, [pNewScoreName], SqlCondition.equals("CLASSIFICATIONTYPE.CLASSIFICATIONTYPEID", pClassificationTypeId, "1=2"));
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment