From 3d2d827e667900798d0faf86141a28775cf50bc6 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 3 May 2023 17:51:44 +0530 Subject: [PATCH] Adding aggBy (overall aggregator) --- scripts/logsheet.js | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/scripts/logsheet.js b/scripts/logsheet.js index 47811a9..0cf05ac 100644 --- a/scripts/logsheet.js +++ b/scripts/logsheet.js @@ -280,4 +280,74 @@ }) return group; } + + const aggBy = logSheet.aggBy = {}; + aggBy.count = function (sheet_id, sheet) { + if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let result = sheet.length; + return result; + } + + aggBy.total = function (sheet_id, sheet, attribute) { + if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let result = 0; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) + result = sheet.forEach(l => { + let value = parseFloat(l.log[attrubuteIndex]) + if (!isNaN(value)) + result += value; + }); + + return result; + } + + aggBy.avg = function (sheet_id, sheet, attribute) { + if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let result = 0, count = 0; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) + sheet.forEach(l => { + let value = parseFloat(l.log[attrubuteIndex]) + if (!isNaN(value)) { + result += value; + count++; + } + }) + result = result / count; + return result; + } + + aggBy.min = function (sheet_id, sheet, attribute) { + if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let result = null; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) + sheet.forEach(l => { + let value = parseFloat(l.log[attrubuteIndex]) + if (!isNaN(value)) { + if (result === null || value < result) + result = value; + } + }) + console.debug(sheet) + console.debug(result) + return result; + } + + aggBy.max = function (sheet_id, sheet, attribute) { + if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let result = null; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) + sheet.forEach(l => { + let value = parseFloat(l.log[attrubuteIndex]) + if (!isNaN(value)) { + if (result === null || value > result) + result = value; + } + }) + return result; + } })(); \ No newline at end of file