1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/component/executiveDashboard/componentsChart/MetricsSummaryChart/MetricsChartTooltip/aggregate-metrics-by-day.ts

34 lines
936 B
TypeScript
Raw Normal View History

import type { ExecutiveSummarySchema } from 'openapi';
export function aggregateDataPerDate(
items: ExecutiveSummarySchema['metricsSummaryTrends'],
) {
return items.reduce(
(acc, item) => {
if (!acc[item.date]) {
acc[item.date] = {
totalFlags: 0,
totalNo: 0,
totalRequests: 0,
totalYes: 0,
};
}
acc[item.date].totalFlags += item.totalFlags;
acc[item.date].totalNo += item.totalNo;
acc[item.date].totalRequests += item.totalRequests;
acc[item.date].totalYes += item.totalYes;
return acc;
},
{} as {
[date: string]: {
totalFlags: number;
totalNo: number;
totalRequests: number;
totalYes: number;
};
},
);
}