From b6bb7bcc9dd3c3cd78d826b97ddd92c8da4aadb1 Mon Sep 17 00:00:00 2001 From: Thomas Heartman Date: Fri, 24 Jan 2025 15:37:22 +0100 Subject: [PATCH] chore(1-3293): update fake store --- .../fake-traffic-data-usage-store.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/lib/features/traffic-data-usage/fake-traffic-data-usage-store.ts b/src/lib/features/traffic-data-usage/fake-traffic-data-usage-store.ts index fa2262f7f7..3b9023b103 100644 --- a/src/lib/features/traffic-data-usage/fake-traffic-data-usage-store.ts +++ b/src/lib/features/traffic-data-usage/fake-traffic-data-usage-store.ts @@ -89,4 +89,41 @@ export class FakeTrafficDataUsageStore implements ITrafficDataUsageStore { return Object.values(data); } + + async getDailyTrafficDataForPeriod( + from: Date, + to: Date, + ): Promise { + return this.trafficData.filter( + (data) => data.day >= from && data.day <= to, + ); + } + + async getMonthlyTrafficDataForPeriod( + from: Date, + to: Date, + ): Promise { + const data: { [key: string]: IStatMonthlyTrafficUsage } = + this.trafficData + .filter((entry) => entry.day >= from && entry.day <= to) + .reduce((acc, entry) => { + const month = format(entry.day, 'yyyy-MM'); + const key = `${month}-${entry.trafficGroup}-${entry.statusCodeSeries}`; + + if (acc[key]) { + acc[key].count += entry.count; + } else { + acc[key] = { + month, + trafficGroup: entry.trafficGroup, + statusCodeSeries: entry.statusCodeSeries, + count: entry.count, + }; + } + + return acc; + }, {}); + + return Object.values(data); + } }