Fix: aggBy.total and aggBy.avg

- Fixed: aggBy.total and aggBy.avg to return null when no record has a valid number value
This commit is contained in:
sairajzero 2023-05-03 18:43:44 +05:30
parent 1341f25dd6
commit 40560c5824

View File

@ -294,15 +294,19 @@
aggBy.total = function (sheet_id, sheet, attribute) { aggBy.total = function (sheet_id, sheet, attribute) {
if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList))
throw ("Sheet not found") throw ("Sheet not found")
let result = 0; let result = 0, count = 0;
let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute)
sheet.forEach(l => { sheet.forEach(l => {
if (!_isNaN(l.log[attrubuteIndex])) { if (!_isNaN(l.log[attrubuteIndex])) {
let value = parseFloat(l.log[attrubuteIndex]) let value = parseFloat(l.log[attrubuteIndex])
result += value; result += value;
count++;
} }
}); });
if (count == 0)
result = null;
return result; return result;
} }
@ -318,7 +322,10 @@
count++; count++;
} }
}) })
result = result / count; if (count == 0)
result = null;
else
result = result / count;
return result; return result;
} }