2024-03-21 15:39:03 +01:00
|
|
|
import type { InstanceInsightsSchema } from 'openapi';
|
2024-03-20 08:24:56 +01:00
|
|
|
|
|
|
|
export function aggregateDataPerDate(
|
2024-03-21 15:39:03 +01:00
|
|
|
items: InstanceInsightsSchema['metricsSummaryTrends'],
|
2024-03-20 08:24:56 +01:00
|
|
|
) {
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|