@contrail/aggregates
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -10,2 +10,3 @@ import { TypeProperty } from "@contrail/types"; | ||
static computeAggregatesForNumericProperties(aggregates: any, data: any, properties: Array<AggregatePropertyInfo>): void; | ||
static applyAggregateFunctions(aggregates: any, properties: any): void; | ||
} |
@@ -24,2 +24,3 @@ "use strict"; | ||
this.computeAggregatesForNumericProperties(propertyAggregate[optionValue], filteredData, properties); | ||
this.applyAggregateFunctions(aggregates, properties); | ||
} | ||
@@ -47,3 +48,33 @@ } | ||
} | ||
static applyAggregateFunctions(aggregates, properties) { | ||
var _a, _b, _c, _d; | ||
const totalMarginProp = properties.find(p => p.typeProperty.slug === 'totalMargin'); | ||
if (totalMarginProp) { | ||
const totalRevenue = (_a = aggregates.totalRevenue) === null || _a === void 0 ? void 0 : _a.total; | ||
const totalCost = (_b = aggregates.totalCost) === null || _b === void 0 ? void 0 : _b.total; | ||
console.log('COMPUTING WEIGHTED MARGIN: ', totalRevenue, totalCost); | ||
let weightedMargin; | ||
if (totalRevenue && totalCost) { | ||
weightedMargin = (totalRevenue - totalCost) / totalRevenue; | ||
} | ||
aggregates.totalMargin = { | ||
total: weightedMargin, | ||
}; | ||
} | ||
const itemOptionEfficiencyProp = properties.find(p => p.typeProperty.slug === 'itemOptionEfficiency'); | ||
const targetItemOptionCountProp = properties.find(p => p.typeProperty.slug === 'targetItemOptionCount'); | ||
if (itemOptionEfficiencyProp && targetItemOptionCountProp) { | ||
const totalVolume = (_c = aggregates.targetVolume) === null || _c === void 0 ? void 0 : _c.total; | ||
console.log('COMPUTING EFFICIENCY: ', totalVolume); | ||
const targetItemOptionCount = (_d = aggregates.targetItemOptionCount) === null || _d === void 0 ? void 0 : _d.total; | ||
let efficiency; | ||
if (totalVolume && targetItemOptionCount) { | ||
efficiency = (totalVolume / targetItemOptionCount); | ||
} | ||
aggregates.itemOptionEfficiency = { | ||
total: efficiency, | ||
}; | ||
} | ||
} | ||
} | ||
exports.AggregateTypePropertyHelper = AggregateTypePropertyHelper; |
{ | ||
"name": "@contrail/aggregates", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Utilities for computing aggregates", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
12019
239