bare-script 2.2.15 → 2.2.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/data.js +13 -2
- package/package.json +1 -1
package/lib/data.js
CHANGED
|
@@ -376,6 +376,9 @@ enum AggregationFunction
|
|
|
376
376
|
# The least of the measure's values
|
|
377
377
|
min
|
|
378
378
|
|
|
379
|
+
# The standard deviation of the measure's values
|
|
380
|
+
stddev
|
|
381
|
+
|
|
379
382
|
# The sum of the measure's values
|
|
380
383
|
sum
|
|
381
384
|
`);
|
|
@@ -434,7 +437,9 @@ export function aggregateData(data, aggregation) {
|
|
|
434
437
|
if (!(field in aggregateRow)) {
|
|
435
438
|
aggregateRow[field] = [];
|
|
436
439
|
}
|
|
437
|
-
|
|
440
|
+
if (value !== null) {
|
|
441
|
+
aggregateRow[field].push(value);
|
|
442
|
+
}
|
|
438
443
|
}
|
|
439
444
|
}
|
|
440
445
|
|
|
@@ -445,7 +450,9 @@ export function aggregateData(data, aggregation) {
|
|
|
445
450
|
const field = measure.name ?? measure.field;
|
|
446
451
|
const func = measure.function;
|
|
447
452
|
const measureValues = aggregateRow[field];
|
|
448
|
-
if (
|
|
453
|
+
if (!measureValues.length) {
|
|
454
|
+
aggregateRow[field] = null;
|
|
455
|
+
} else if (func === 'count') {
|
|
449
456
|
aggregateRow[field] = measureValues.length;
|
|
450
457
|
} else if (func === 'max') {
|
|
451
458
|
aggregateRow[field] = measureValues.reduce((max, val) => (val > max ? val : max));
|
|
@@ -453,7 +460,11 @@ export function aggregateData(data, aggregation) {
|
|
|
453
460
|
aggregateRow[field] = measureValues.reduce((min, val) => (val < min ? val : min));
|
|
454
461
|
} else if (func === 'sum') {
|
|
455
462
|
aggregateRow[field] = measureValues.reduce((sum, val) => sum + val, 0);
|
|
463
|
+
} else if (func === 'stddev') {
|
|
464
|
+
const average = measureValues.reduce((sum, val) => sum + val, 0) / measureValues.length;
|
|
465
|
+
aggregateRow[field] = Math.sqrt(measureValues.reduce((sum, val) => sum + (val - average) ** 2, 0) / measureValues.length);
|
|
456
466
|
} else {
|
|
467
|
+
// func === 'average'
|
|
457
468
|
aggregateRow[field] = measureValues.reduce((sum, val) => sum + val, 0) / measureValues.length;
|
|
458
469
|
}
|
|
459
470
|
}
|