@contrail/aggregates
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -10,2 +10,3 @@ export declare class AggregateHelper { | ||
static getGroupTotals(data: Array<any>, groupingIndex: string, groupingValues: Array<string>, totalIndex: string): {}; | ||
static computeAggregatesForNumeric(data: any, prefix: any, slug: any): any; | ||
} |
@@ -38,6 +38,7 @@ "use strict"; | ||
} | ||
const val = Math.min(...data.map(obj => { | ||
const values = data.map(obj => { | ||
const v = util_1.ObjectUtil.getByPath(obj, index); | ||
return v ? v : 0; | ||
})); | ||
return v; | ||
}).filter(v => (v !== null && v !== undefined)); | ||
const val = Math.min(...values); | ||
if (val === Infinity) { | ||
@@ -94,3 +95,30 @@ return null; | ||
} | ||
static computeAggregatesForNumeric(data, prefix, slug) { | ||
if (!(data === null || data === void 0 ? void 0 : data.length)) { | ||
return; | ||
} | ||
const index = `${prefix || ''}${slug}`; | ||
const total = AggregateHelper.getTotal(data, index); | ||
const average = AggregateHelper.getAverage(data, index); | ||
const min = AggregateHelper.getMin(data, index); | ||
const max = AggregateHelper.getMax(data, index); | ||
const aggregate = {}; | ||
if (total || total === 0) { | ||
aggregate.total = total; | ||
} | ||
if (average || average === 0) { | ||
aggregate.average = average; | ||
} | ||
if (min || min === 0) { | ||
aggregate.min = min; | ||
} | ||
if (max || max === 0) { | ||
aggregate.max = max; | ||
} | ||
const hasValue = (aggregate.total || aggregate.average || aggregate.min || aggregate.max); | ||
if (hasValue) { | ||
return aggregate; | ||
} | ||
} | ||
} | ||
exports.AggregateHelper = AggregateHelper; |
export * from './aggregate-helper'; | ||
export * from './aggregate-type-property-helper'; |
@@ -14,1 +14,2 @@ "use strict"; | ||
__exportStar(require("./aggregate-helper"), exports); | ||
__exportStar(require("./aggregate-type-property-helper"), exports); |
{ | ||
"name": "@contrail/aggregates", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Utilities for computing aggregates", | ||
@@ -41,4 +41,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@contrail/types": "^2.0.43", | ||
"@contrail/util": "^1.0.15" | ||
} | ||
} |
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
10178
7
207
2
+ Added@contrail/types@^2.0.43
+ Added@contrail/types@2.0.75(transitive)