UNPKG

@cloud-carbon-footprint/core

Version:

The core logic to get cloud usage data and estimate energy and carbon emissions.

20 lines 837 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.aggregateCostsByDay = void 0; const ramda_1 = require("ramda"); const aggregateCostsByDay = (estimates) => { const getDayOfEstimate = (estimate) => estimate.timestamp.toISOString().substr(0, 10); const accumulatingFn = (acc, value) => { if (acc.timestamp.getTime() === new Date(0).getTime()) { acc.timestamp = new Date(getDayOfEstimate(value)); } acc.amount += value.amount; if (acc.currency === '') { acc.currency = value.currency; } return acc; }; return (0, ramda_1.reduceBy)(accumulatingFn, { timestamp: new Date(0), amount: 0, currency: '' }, getDayOfEstimate, estimates); }; exports.aggregateCostsByDay = aggregateCostsByDay; //# sourceMappingURL=Cost.js.map