bug fix: groupBy and aggBy

- Fixed: groupBy and aggBy parsing partial invalid numbers (eg, 1A gets parsed as 1) from string
- Fixed: aggBy.total returning undefined instead of value
This commit is contained in:
sairajzero 2023-05-03 18:09:09 +05:30
parent 3d2d827e66
commit 1341f25dd6

View File

@ -192,6 +192,8 @@
} }
} }
const _isNaN = value => isNaN(value) || value === '';
const groupBy = logSheet.groupBy = {}; const groupBy = logSheet.groupBy = {};
groupBy.count = function (sheet_id, sheet) { groupBy.count = function (sheet_id, sheet) {
if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList)) if (!(sheet_id in floGlobals.appObjects.logSheet.sheetList))
@ -212,8 +214,8 @@
let group = {}; let group = {};
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (!(l.floID in group)) if (!(l.floID in group))
group[l.floID] = value group[l.floID] = value
else else
@ -229,8 +231,8 @@
let group = {}; let group = {};
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (!(l.floID in group)) if (!(l.floID in group))
group[l.floID] = { group[l.floID] = {
total: value, total: value,
@ -253,8 +255,8 @@
let group = {}; let group = {};
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (!(l.floID in group)) if (!(l.floID in group))
group[l.floID] = value group[l.floID] = value
else if (value < group[l.floID]) else if (value < group[l.floID])
@ -270,8 +272,8 @@
let group = {}; let group = {};
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (!(l.floID in group)) if (!(l.floID in group))
group[l.floID] = value group[l.floID] = value
else if (value > group[l.floID]) else if (value > group[l.floID])
@ -294,10 +296,11 @@
throw ("Sheet not found") throw ("Sheet not found")
let result = 0; let result = 0;
let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute) let attrubuteIndex = floGlobals.appObjects.logSheet.sheetList[sheet_id].attributes.indexOf(attribute)
result = sheet.forEach(l => { sheet.forEach(l => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) let value = parseFloat(l.log[attrubuteIndex])
result += value; result += value;
}
}); });
return result; return result;
@ -309,8 +312,8 @@
let result = 0, count = 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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
result += value; result += value;
count++; count++;
} }
@ -325,14 +328,12 @@
let result = null; let result = null;
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (result === null || value < result) if (result === null || value < result)
result = value; result = value;
} }
}) })
console.debug(sheet)
console.debug(result)
return result; return result;
} }
@ -342,8 +343,8 @@
let result = null; let result = null;
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 => {
let value = parseFloat(l.log[attrubuteIndex]) if (!_isNaN(l.log[attrubuteIndex])) {
if (!isNaN(value)) { let value = parseFloat(l.log[attrubuteIndex])
if (result === null || value > result) if (result === null || value > result)
result = value; result = value;
} }