Hi Johann
jcompagner:
robert, what you have is very weird,
that really should go pretty fast, i guess somehow it is hitting a memory limit (that you should be able to see in the about dialog)
I absolutly agree with you. Memory usage is NOT shown while running the loop - only after it is finished the memory is shown. It seems to have 517’760 K allocated - not that much. The machine has 6 GB of physical RAM installed. See attached screenshot.
jcompagner:
What kinds of queries are all generated when you do that loop?
I see nothing except one query in the performance data menu of the Servoy Application Server - see attached screenshot. The server log page has no entry at all.
jcompagner:
So flush the performance page on the admin pages when it is looping, what do you all see happening?
I guess that it is a bit more then just the update statements for the stored calculated column.
Where should I be able to see that?
This is our loop:
function handleCalculateTable() {
var tableNamesArray = databaseManager.getTableNames(databaseManager.getDataSourceServerName(currentcontroller.getDataSource()));
var selectedTable = plugins.dialogs.showSelectDialog('Calculations', 'Select a table to execute the Calculations: ', tableNamesArray);
if (selectedTable) {
var currentFoundset = databaseManager.getFoundSet(databaseManager.getDataSourceServerName(currentcontroller.getDataSource()), selectedTable);
currentFoundset.loadAllRecords();
var countCurrentFoundset = databaseManager.getFoundSetCount(currentFoundset);
application.output(new Date() + ': Start executing of ' + selectedTable + '(' + countCurrentFoundset + ')');
//for (var j = 0; j < countCurrentFoundset; j += 200) {
for (var i = 0; i < 400; i++) {
application.output(new Date() + ': Record ' + (i + 1) + '/' + countCurrentFoundset + ' of table ' + selectedTable);
var currentRecord = currentFoundset.getRecord(i)
databaseManager.recalculate(currentRecord);
if (!databaseManager.saveData(currentRecord)) {
//var exception = currentRecord.exception.getMessage();
application.output('Faild-Record: ' + databaseManager.getFailedRecords());
//application.output('Exception: ' + exception);
}
}
//}
application.output(new Date() + ': Finished executing of ' + selectedTable + '(' + countCurrentFoundset + ')');
plugins.dialogs.showInfoDialog('Calculations', 'All Calculations are Executed', 'OK');
}
}
And this is one of our calcs involved. I should note that there are calc dependencies as the whole thing is a chain for calculating a school promotion for the period of 6 semesters. HS and FS just means Herbstsemester and Frühlingssemester, these are the first and second semesters within a year. The code is here to get an idea that this calcs are not just very simple calcs.
function promotion_code() {
if (!utils.hasRecords(_class_members_enroled_for_profile_positions)) {
return null;
}
// Should the period promotion be calculated?
// For the Maturitätsschule this should be done for level_number and fraction_name:
// 1 HS
// 1 FS
// 2 HS
// 2 FS
// 3 HS (for negative promoted students only)
// 3 FS (since a promotion is done for 1 year, the former promotion code is the one a year ago for positive promoted students)
// For the FMS this should be done for level_number and fraction_name:
// 1 HS
// 1 FS
// 2 HS (for negative promoted students only)
// 2 FS (since a promotion is done for 1 year, the former promotion code is the one a year ago for positive promoted students)
var currentLevelAndFractionName = class_level_number + ' ' + class_period_fraction_name;
var currentProfile = _class_members_enroled_for_profile_positions.profile_positions_referenced_by_profile_definitions.profile_definitions_typified_by_profiles;
if (!utils.hasRecords(currentProfile.profiles_hosted_by_school_units)) {
// Since the profile is not hosted by any school_unit, the type of school is not defined.
// And without type of school the regulation - which is the legal basis - is undefined.
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, 'Für das Profil ist kein Schultyp definiert.');
return null;
}
// Find the promotion the student startet this period with:
// If a promotion_code_start exists, use that one.
// If we are in 3 FS in MS or 2 FS in FMS
// - Use promotion_code start if set
// - Use def if student started last period positive.
// - Use former promotion code if student started negative.
// Else
// - Check, if a start code exists. If not, use the former promotion code. Or - if set - the overwrite former promotion code.
var schoolType = currentProfile.profiles_hosted_by_school_units.school_type_code;
var initialPromotionCode = null;
if (promotion_code_start) {
initialPromotionCode = promotion_code_start;
}
else {
initialPromotionCode = _promotion_code_former;
}
// Do not promote the student if we are in 3 HS in MS or 2 HS in FMS and the student was positively promoted
if (schoolType == 'MS') {
// The basis is Maturitätsschulverordnung
var periodsForPromotionCalculation = ['1 HS', '1 FS', '2 HS', '2 FS', '3 FS'];
if (periodsForPromotionCalculation.indexOf(currentLevelAndFractionName) == -1) {
// The current period is not one of the normal periods where a promotion calculation should be done.
// Only for negative students in 3 HS a promotion calculation should be done.
if (currentLevelAndFractionName == '3 HS' && initialPromotionCode != 'def') {
// Continue. A promotion calculation should be done.
}
else {
// In this period no promotion has to be calculated.
return null;
}
}
}
else if (schoolType == 'FMS') {
// The basis is FMS-Verordnung
var periodsForPromotionCalculation = ['1 HS', '1 FS', '2 FS'];
if (periodsForPromotionCalculation.indexOf(currentLevelAndFractionName) == -1) {
// The current period is not one of the normal periods where a promotion calculation should be done.
// Only for negative students in 2 HS a promotion calculation should be done.
if (currentLevelAndFractionName == '2 HS' && initialPromotionCode != 'def') {
// Continue. A promotion calculation should be done.
}
else {
// In this period no promotion has to be calculated.
return null;
}
}
}
// Find the possible promotions for this perdiod
if (!utils.hasRecords(_class_members_available_profile_promotions)) {
// No promotions defined for this period
return null;
}
else {
var possiblePromotions = new Array();
for (var i = 1; i <= _class_members_available_profile_promotions.getSize(); i++) {
possiblePromotions.push(_class_members_available_profile_promotions.getRecord(i).promotion_code);
}
}
// Check if all promotion subjects are marked.
for (var j = 1; j <= _class_members_enroled_for_profile_positions.getSize(); j++) {
var profilePosition = _class_members_enroled_for_profile_positions.getRecord(j);
if (!profilePosition.is_dispensed
&& profilePosition.profile_positions_referenced_by_profile_definitions.allow_assessment
&& profilePosition.profile_positions_referenced_by_profile_definitions.significance
&& !profilePosition.mark) {
// Profile position found without mark.
return null;
}
}
// Start the evaluation of the achievement. For this, compare the different limits
// defined in the profile with the current marks, avarage and balance.
var achievementSufficient = true;
if (currentProfile.min_average_of_promotion_marks != null) {
// Check average of promotion marks
if (_average_of_promotion_marks < currentProfile.min_average_of_promotion_marks) {
achievementSufficient = false;
}
}
if (currentProfile.max_number_of_insufficient_marks != null) {
// Check number of unsufficient marks
if (_number_of_insufficient_promotion_marks > currentProfile.max_number_of_insufficient_marks) {
achievementSufficient = false;
}
}
if (currentProfile.balance_calculation_promotion != null) {
if (_balance_of_promotion_marks < currentProfile.min_balance_of_promotion_marks) {
achievementSufficient = false;
}
}
var promotionCode = null;
// Depending on previous promotion(s) find current promotion to return
if (initialPromotionCode == 'def') {
if (achievementSufficient) {
if (possiblePromotions.indexOf('def') != -1) {
promotionCode = 'def';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['def']));
}
}
else if (!achievementSufficient) {
if ( (schoolType == 'MS' && currentLevelAndFractionName == '3 FS')
|| (schoolType == 'FMS' && currentLevelAndFractionName == '2 FS')) {
// The next level cannot be started with a negative promotion. The student has to repeat the class.
// Or, if the maximum number of remotions is reached, he/she gets promotion code 'aus' and will
// be excluded from the school.
if (_number_of_remotions < currentProfile.max_number_of_remotions) {
if (possiblePromotions.indexOf('rem') != -1) {
promotionCode = 'rem';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['rem']));
}
}
else if (_number_of_remotions >= currentProfile.max_number_of_remotions) {
if (possiblePromotions.indexOf('aus') != -1) {
promotionCode = 'aus';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['aus']));
}
}
}
else {
if (possiblePromotions.indexOf('prov') != -1) {
promotionCode = 'prov';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['prov']));
}
}
}
}
else if (initialPromotionCode == 'prov' || initialPromotionCode == 'vprov') {
if (achievementSufficient) {
if (possiblePromotions.indexOf('def') != -1) {
promotionCode = 'def';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['def']));
}
}
else if (!achievementSufficient) {
if (currentLevelAndFractionName == '1 HS') {
if (possiblePromotions.indexOf('pzNeg') != -1) {
promotionCode = 'pzNeg';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['pzNeg']));
}
}
else if (_number_of_remotions < currentProfile.max_number_of_remotions) {
if (possiblePromotions.indexOf('rem') != -1) {
promotionCode = 'rem';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['rem']));
}
}
else if (_number_of_remotions >= currentProfile.max_number_of_remotions) {
if (possiblePromotions.indexOf('aus') != -1) {
promotionCode = 'aus';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['aus']));
}
}
}
}
else if (initialPromotionCode == 'vpz') {
if (achievementSufficient) {
if (possiblePromotions.indexOf('def') != -1) {
promotionCode = 'def';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, 'Die berechnete Promotion def ist für diese Periode nicht definiert.');
}
}
else if (!achievementSufficient) {
if (possiblePromotions.indexOf('pzNeg') != -1) {
promotionCode = 'pzNeg';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['pzNeg']));
}
}
}
else if (initialPromotionCode == 'rem') {
if (achievementSufficient) {
if (possiblePromotions.indexOf('def') != -1) {
promotionCode = 'def';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['def']));
}
}
else if (!achievementSufficient) {
if (possiblePromotions.indexOf('aus') != -1) {
promotionCode = 'aus';
}
else {
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningCalculatedPromotionNotDefined', ['aus']));
}
}
}
else {
// The initialPromotionCode is not expected
//globals.protocolWarning(i18n.getI18NMessage('hades.ach.protocol.title.promotion.ucl'), _as_string, i18n.getI18NMessage('hades.ach.protocol.msg.warningNoInitialPromotionCode'));
}
return promotionCode;
}
Now I am courious on your answer.
Best regards, Robert