diff --git a/process/updateClassifications_serverProcess/process.js b/process/updateClassifications_serverProcess/process.js index 9bdf040f4cdf01020e69f43c32cce5f1b3817992..09cb9c387900f25f3190f72a9dbd1f95dbda4ec3 100644 --- a/process/updateClassifications_serverProcess/process.js +++ b/process/updateClassifications_serverProcess/process.js @@ -30,6 +30,7 @@ var classificationStorageObject = {}; //object to store the classificationstorag var groupObject = {}; //groupObject is another helper object to store all the groupIds var outdatedClassificationTypeObj = {};//object to store all outdated classificationtypes (need so we can add empty persisted data later var alreadyUpdatedTypesObj = {}; +var storedClassificationValues = {}; //arrays mainly used for filling the objects var objectTypes = []; @@ -43,6 +44,7 @@ var scoreArray = []; var objectTypesThatNeedUpdate = []; var outdatedStoredClassifications = []; var objectRowIdArray = []; +var objectsThatWillBeUpdated = []; var object_type, classificationGroupId, classificationTypeId, classificationScoreId, classificationScore, classificationGradingId, score, cond, classificationGradingMaxScore, classificationGrading, chainedGrading, currentObjectColumn, currentObjectTable, isOrganisation, bestValue, minPercent, @@ -127,12 +129,20 @@ if(!singleRefresh) { if(recalculateAll) { - outdatedStoredClassifications = newSelect("CLASSIFICATIONSTORAGE.OBJECT_TYPE, CLASSIFICATIONSTORAGE.OBJECT_ROWID, \n\ - CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID, CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE") - .from("CLASSIFICATIONSTORAGE") - .where("CLASSIFICATIONSTORAGE.OUTDATED", 1) - .orderBy("OBJECT_TYPE") - .table(); + outdatedStoredClassifications = newSelect("CLASSIFICATION.OBJECT_TYPE, CLASSIFICATION.OBJECT_ROWID\n\ + ,"+ SqlBuilder.caseWhen(newWhere("CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID is null")) + .then("''") + .elseValue("CLASSIFICATIONSTORAGE.CLASSIFICATIONSTORAGEID") + .toString()+ "\n\ + ,"+ SqlBuilder.caseWhen(newWhere("CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE is null")) + .then("''") + .elseValue("CLASSIFICATIONSTORAGE.CLASSIFICATIONVALUE") + .toString()+ + ", CLASSIFICATION.CLASSIFICATIONTYPE_ID, CLASSIFICATION.VALUE, CLASSIFICATION.SCOREPOINTS") + .from("CLASSIFICATION") + .leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CLASSIFICATION.OBJECT_ROWID") + .orderBy("CLASSIFICATION.OBJECT_TYPE, CLASSIFICATION.OBJECT_ROWID") + .table(); } else { @@ -144,6 +154,18 @@ if(!singleRefresh) .orderBy("OBJECT_TYPE") .table(); } + + var storedClassificationStorageValues = {}; + if(recalculateAll) + { + let storedValuesArray = newSelect("CLASSIFICATIONSTORAGE.OBJECT_ROWID") + .from("CLASSIFICATIONSTORAGE") + .arrayColumn(); + storedValuesArray.map(function(objRowId){ + storedClassificationStorageValues[objRowId] = ""; + }); + } + helperObject = {}; if(outdatedStoredClassifications) { @@ -152,13 +174,17 @@ if(!singleRefresh) { for (ii = 0; ii < outdatedStoredClassifications[i].length; ii++) { - [object_type, object_rowId, classificationStorageId, classificationScore] = outdatedStoredClassifications[i]; + [object_type, object_rowId, classificationStorageId, classificationScore, classificationTypeId, classificationValue, classificationScorePoints] = outdatedStoredClassifications[i]; if(!helperObject.hasOwnProperty(object_type)) //objectType { classificationStorageObject[object_type] = {}; //puts objectType in classificationStorageObject and already initializes the object that later get's filled with the groups and their types helperObject[object_type] = ""; objectTypes.push(object_type); //also push all the objectTypes in an Array for later (the updating happens one objectType at a time) + if(recalculateAll) + { + storedClassificationValues[object_type] = {}; + } } if(!helperObject.hasOwnProperty(object_rowId)) //objectRowId @@ -166,13 +192,21 @@ if(!singleRefresh) classificationStorageObject[object_type][object_rowId] = [classificationStorageId, classificationScore]; //same logic as before helperObject[object_rowId] = ""; objectRowIdArray.push(object_rowId); //also push all the objectTypes in an Array for later + if(recalculateAll) + { + storedClassificationValues[object_type][object_rowId] = {"classificationTypeId": classificationTypeId, "classificationValue": classificationValue, "classificationScorePoints":classificationScorePoints}; + if(!storedClassificationStorageValues.hasOwnProperty(object_rowId))//if the dataset doesn't have an classificationStorage dataset but does have classification datasets -> insert it here + { + db.insertData("CLASSIFICATIONSTORAGE", ["CLASSIFICATIONSTORAGEID", "CLASSIFICATIONVALUE", "OBJECT_ROWID", "OBJECT_TYPE", "OUTDATED"], null, [util.getNewUUID(), "-", object_rowId, object_type, 1]) + } + } } } } } -} - -if(outdatedStoredClassifications.length > 0) +} + +if(outdatedStoredClassifications.length > 0 && !recalculateAll) { storedClassificationFlag = true; //this variable can easily be checked to see what we are updating runUpdating++; } @@ -530,13 +564,13 @@ for (xyz = 0; xyz < runUpdating; xyz++) { correctCondition = newWhere(currentObjectColumn, vars.get("$local.ObjectRowid_param")); } - else if(!storedClassificationFlag) + else if(storedClassificationFlag) { - correctCondition = newWhere("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID", groupsThatNeedUpdate, SqlBuilder.IN()); + correctCondition = newWhere(currentObjectColumn, objectRowIdArray, SqlBuilder.IN()); } else { - correctCondition = newWhere(currentObjectColumn, objectRowIdArray, SqlBuilder.IN()); + correctCondition = newWhere("CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID", groupsThatNeedUpdate, SqlBuilder.IN()); } achievedScoresStmt = newSelect(currentObjectColumn + ", CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID, \n\ @@ -568,9 +602,12 @@ for (xyz = 0; xyz < runUpdating; xyz++) .where(correctCondition); if(isOrganisation) bestPossibleScoreStmt.and("CONTACT.PERSON_ID is null"); - + + bestPossibleScoreStmt.orderBy(currentObjectColumn + ", CLASSIFICATIONTYPE.CLASSIFICATIONGROUP_ID"); + + bestPossibleScoresGroupObj = {}; helperObject = {}; bestPossibleScoreStmt.pageSize(100) @@ -602,6 +639,10 @@ for (xyz = 0; xyz < runUpdating; xyz++) break; } } + while(chainedGrading.length < position + 1) + { + chainedGrading += "-" + } if(achievedScoresObj[row_Id][groupId]["Grade"] != undefined) chainedGrading = StringUtils.replaceAt(chainedGrading, position, achievedScoresObj[row_Id][groupId]["Grade"]); //update the stored classificationString for each dataset else