@contrail/aggregates
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -8,3 +8,4 @@ export declare class AggregateHelper { | ||
static getValueCounts(data: Array<any>, index: any, values: Array<string>): {}; | ||
private static testValue; | ||
static getGroupTotals(data: Array<any>, groupingIndex: string, groupingValues: Array<string>, totalIndex: string): {}; | ||
} |
@@ -61,3 +61,5 @@ "use strict"; | ||
static getUniqueCount(data, index) { | ||
return [...new Set(data.filter(obj => util_1.ObjectUtil.getByPath(obj, index)).map(obj => util_1.ObjectUtil.getByPath(obj, index)))].length; | ||
return [...new Set(data.filter(obj => util_1.ObjectUtil.getByPath(obj, index)) | ||
.map(obj => util_1.ObjectUtil.getByPath(obj, index))) | ||
].length; | ||
} | ||
@@ -67,10 +69,24 @@ static getValueCounts(data, index, values) { | ||
for (const val of values) { | ||
counts[val] = data.filter(obj => util_1.ObjectUtil.getByPath(obj, index) === val).length; | ||
const filtered = data.filter(obj => { | ||
const testValue = util_1.ObjectUtil.getByPath(obj, index); | ||
return AggregateHelper.testValue(val, testValue); | ||
}); | ||
counts[val] = filtered.length; | ||
} | ||
return counts; | ||
} | ||
static testValue(value, testValue) { | ||
if (Array.isArray(testValue)) { | ||
return testValue.includes(value); | ||
} | ||
return value === testValue; | ||
} | ||
static getGroupTotals(data, groupingIndex, groupingValues, totalIndex) { | ||
const totals = {}; | ||
groupingValues.forEach(val => { | ||
totals[val] = this.getTotal(data.filter(obj => util_1.ObjectUtil.getByPath(obj, groupingIndex) === val), totalIndex); | ||
const filtered = data.filter(obj => { | ||
const testValue = util_1.ObjectUtil.getByPath(obj, groupingIndex); | ||
return AggregateHelper.testValue(val, testValue); | ||
}); | ||
totals[val] = this.getTotal(filtered, totalIndex); | ||
}); | ||
@@ -77,0 +93,0 @@ return totals; |
export * from './aggregate-helper'; |
@@ -0,0 +0,0 @@ "use strict"; |
{ | ||
"name": "@contrail/aggregates", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Utilities for computing aggregates", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5364
118