in desktop/src/app/services/azure-cost-management/azure-cost-management.service.ts [131:179]
private _buildResponseFromRows(rows: Array<{
date: number, preTaxCost: number, currency: string, resourceId: string,
}>): BatchAccountCost {
let currency: string | null = null;
let total = 0;
const poolMap: StringMap<{ [key: number]: AzureCostEntry }> = {};
const days = new Set<number>();
for (const row of rows) {
const poolId = ArmResourceUtils.getAccountNameFromResourceId(row.resourceId);
if (!(poolId in poolMap)) {
poolMap[poolId] = {};
}
if (!days.has(row.date)) {
days.add(row.date);
}
poolMap[poolId][row.date] = {
preTaxCost: row.preTaxCost,
date: this._parseDate(row.date),
};
total += row.preTaxCost;
if (currency == null && row.currency) {
currency = row.currency;
}
}
for (const map of Object.values(poolMap)) {
for (const day of days) {
if (!(day in map)) {
map[day] = {
preTaxCost: 0,
date: this._parseDate(day),
};
}
}
}
const result: StringMap<BatchPoolCost> = {};
for (const [poolId, map] of Object.entries(poolMap)) {
const costs = Object.values(map);
result[poolId] = {
totalForPeriod: costs.reduce((t, c) => t + c.preTaxCost, 0),
costs: costs.sortBy(x => x.date),
};
}
return {
totalForPeriod: total,
currency: currency || "",
pools: result,
};
}