From 2e576bbc19f841f2d47ba54f03718577852a6c79 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Sat, 21 Mar 2020 20:03:33 +0530 Subject: [PATCH] Adding groupLogsBy to logSheet The following groupBy are available: count: number of logs of each floID total: total value of an attribute for each floID avg: average value of an attribute for each floID min: minimum value of an attribute for each floID max: maximum value of an attribute for each floID --- FLO_LogSheet.html | 98 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/FLO_LogSheet.html b/FLO_LogSheet.html index dbfb89e..3e87456 100644 --- a/FLO_LogSheet.html +++ b/FLO_LogSheet.html @@ -9100,7 +9100,8 @@ Bitcoin.Util = { if(!(title in floGlobals.appObjects.logSheet.sheetList)) throw ("Sheet not found") let sheet = [] - floDapps.getNextGeneralData(title, '0').forEach(l => sheet.push({ + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => sheet.push({ vc: l.vectorClock, floID: l.message.floID, log: l.message.log @@ -9112,6 +9113,101 @@ Bitcoin.Util = { attributes: floGlobals.appObjects.logSheet.sheetList[title].attributes, sheet: sheet } + }, + + groupLogsBy: { + + count(title){ + if(!(title in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let group = {}; + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => { + if(!(l.message.floID in group)) + group[l.message.floID] = 1 + else + group[l.message.floID] += 1 + }) + return group + }, + + total(title, attribute){ + if(!(title in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let group = {}; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[title].attributes.indexOf(attribute) + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => { + let value = parseFloat(l.message.log[attrubuteIndex]) + if(!isNaN(value)){ + if(!(l.message.floID in group)) + group[l.message.floID] = value + else + group[l.message.floID] += value + } + }) + return group + }, + + avg(title, attribute){ + if(!(title in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let group = {}; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[title].attributes.indexOf(attribute) + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => { + let value = parseFloat(l.message.log[attrubuteIndex]) + if(!isNaN(value)){ + if(!(l.message.floID in group)) + group[l.message.floID] = { + total: value, + count: 1 + } + else{ + group[l.message.floID].total += value + group[l.message.floID].count += 1 + } + } + }) + for(floID in group) + group[floID] = group[floID].total / group[floID].count + return group + }, + min(title, attribute){ + if(!(title in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let group = {}; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[title].attributes.indexOf(attribute) + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => { + let value = parseFloat(l.message.log[attrubuteIndex]) + if(!isNaN(value)){ + if(!(l.message.floID in group)) + group[l.message.floID] = value + else if(value < group[l.message.floID]) + group[l.message.floID] = value + } + }) + return group + }, + + max(title, attribute){ + if(!(title in floGlobals.appObjects.logSheet.sheetList)) + throw ("Sheet not found") + let group = {}; + let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[title].attributes.indexOf(attribute) + let filter = floDapps.util.getFilterString(title) + floGlobals.generalData[filter].forEach(l => { + let value = parseFloat(l.message.log[attrubuteIndex]) + if(!isNaN(value)){ + if(!(l.message.floID in group)) + group[l.message.floID] = value + else if(value > group[l.message.floID]) + group[l.message.floID] = value + } + }) + return group + }, }