From fd6a3966af4db2e0dc4e49c7757c148209f80282 Mon Sep 17 00:00:00 2001 From: Amogh-Bharadwaj Date: Thu, 16 Nov 2023 21:54:30 +0530 Subject: [PATCH] fix graph --- .../[mirrorId]/aggregatedCountsByInterval.ts | 16 +++++++++------- ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx | 10 ++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/ui/app/mirrors/edit/[mirrorId]/aggregatedCountsByInterval.ts b/ui/app/mirrors/edit/[mirrorId]/aggregatedCountsByInterval.ts index bdadb85b8d..b2fdf7b1fb 100644 --- a/ui/app/mirrors/edit/[mirrorId]/aggregatedCountsByInterval.ts +++ b/ui/app/mirrors/edit/[mirrorId]/aggregatedCountsByInterval.ts @@ -21,7 +21,6 @@ function aggregateCountsByInterval( timeUnit = 'YYYY-MM'; break; case 'day': - case 'week': timeUnit = 'YYYY-MM-DD'; break; case '1min': @@ -37,7 +36,7 @@ function aggregateCountsByInterval( // Iterate through the timestamps and populate the aggregatedCounts object for (let { timestamp, count } of timestamps) { - const date = roundUpToNearest15Minutes(timestamp); + const date = roundUpToNearestNMinutes(timestamp, 15); const formattedTimestamp = moment(date).format(timeUnit); if (!aggregatedCounts[formattedTimestamp]) { @@ -53,7 +52,10 @@ function aggregateCountsByInterval( let currentTimestamp = new Date(); if (interval === '15min') { - currentTimestamp = roundUpToNearest15Minutes(currentTimestamp); + currentTimestamp = roundUpToNearestNMinutes(currentTimestamp, 15); + } + if (interval === '5min') { + currentTimestamp = roundUpToNearestNMinutes(currentTimestamp, 5); } while (intervals.length < 30) { @@ -78,13 +80,13 @@ function aggregateCountsByInterval( return resultArray; } -function roundUpToNearest15Minutes(date: Date) { +function roundUpToNearestNMinutes(date: Date, N: number) { const minutes = date.getMinutes(); - const remainder = minutes % 15; + const remainder = minutes % N; if (remainder > 0) { - // Round up to the nearest 15 minutes - date.setMinutes(minutes + (15 - remainder)); + // Round up to the nearest N minutes + date.setMinutes(minutes + (N - remainder)); } // Reset seconds and milliseconds to zero to maintain the same time diff --git a/ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx b/ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx index 6c5e9988c1..cdc6d91a37 100644 --- a/ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx +++ b/ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx @@ -35,7 +35,6 @@ function CdcGraph({ syncs }: { syncs: SyncStatusRow[] }) { { label: '15min', value: '15min' }, { label: 'hour', value: 'hour' }, { label: 'day', value: 'day' }, - { label: 'week', value: 'week' }, { label: 'month', value: 'month' }, ]; return ( @@ -67,20 +66,15 @@ function CdcGraph({ syncs }: { syncs: SyncStatusRow[] }) { function formatGraphLabel(date: Date, aggregateType: String): string { switch (aggregateType) { + case '1min': + case '5min': case '15min': - return moment(date).format('MMM Do HH:mm'); case 'hour': return moment(date).format('MMM Do HH:mm'); case 'day': return moment(date).format('MMM Do'); case 'month': return moment(date).format('MMM yy'); - case 'week': - return moment(date).format('MMM Do'); - case '5min': - return moment(date).format('MMM Do HH:mm'); - case '1min': - return moment(date).format('MMM Do HH:mm'); default: return 'Unknown aggregate type: ' + aggregateType; }