mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
68a1ba3dec
Fills missing datapoints with 0s so that all metrics chart lines have data for all datapoints. Closes # [1-2278](https://linear.app/unleash/issue/1-2278/fill-the-metrics-data-with-0s-when-not-enough-data-to-fill-the-chart) Before: <img width="1547" alt="Screenshot 2024-04-10 at 12 48 22" src="https://github.com/Unleash/unleash/assets/104830839/35885852-d986-4760-84e2-9e8ef61bedf0"> <img width="1550" alt="Screenshot 2024-04-10 at 12 48 44" src="https://github.com/Unleash/unleash/assets/104830839/3385b8eb-08e2-4cc9-86b2-7b31b9fe81ef"> After: <img width="1582" alt="Screenshot 2024-04-10 at 13 43 10" src="https://github.com/Unleash/unleash/assets/104830839/d3713df3-869b-48ba-b2ab-095027b37506"> <img width="1545" alt="Screenshot 2024-04-10 at 13 42 49" src="https://github.com/Unleash/unleash/assets/104830839/44a6e662-2e9f-4fe8-8299-c15ab8f8e261"> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
34 lines
936 B
TypeScript
34 lines
936 B
TypeScript
import type { InstanceInsightsSchema } from 'openapi';
|
|
|
|
export function aggregateDataPerDate(
|
|
items: InstanceInsightsSchema['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;
|
|
};
|
|
},
|
|
);
|
|
}
|