Skip to content

Commit

Permalink
fix graph
Browse files Browse the repository at this point in the history
  • Loading branch information
Amogh-Bharadwaj committed Nov 16, 2023
1 parent 94d9466 commit fd6a396
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
16 changes: 9 additions & 7 deletions ui/app/mirrors/edit/[mirrorId]/aggregatedCountsByInterval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ function aggregateCountsByInterval(
timeUnit = 'YYYY-MM';
break;
case 'day':
case 'week':
timeUnit = 'YYYY-MM-DD';
break;
case '1min':
Expand All @@ -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]) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down
10 changes: 2 additions & 8 deletions ui/app/mirrors/edit/[mirrorId]/cdcGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit fd6a396

Please sign in to comment.