From a21f60553715e3ebe01a0dc366a7b0685feea86e Mon Sep 17 00:00:00 2001 From: Yaliang Wu Date: Fri, 8 May 2020 10:41:57 -0700 Subject: [PATCH 1/3] fix live chart bar width problem --- public/pages/utils/anomalyResultUtils.ts | 54 ++++++++++++++---------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/public/pages/utils/anomalyResultUtils.ts b/public/pages/utils/anomalyResultUtils.ts index aa3acb63..12304ad2 100644 --- a/public/pages/utils/anomalyResultUtils.ts +++ b/public/pages/utils/anomalyResultUtils.ts @@ -110,8 +110,8 @@ const sampleMaxAnomalyGrade = (anomalies: any[]): any[] => { export const prepareDataForChart = ( data: any[], dateRange: DateRange, - interval?: number, - getFloorPlotTime?: any + interval: number = 1, + getFloorPlotTime?: any, ) => { if (!data || data.length === 0) { return []; @@ -124,32 +124,42 @@ export const prepareDataForChart = ( if (anomalies.length > MAX_DATA_POINTS) { anomalies = sampleMaxAnomalyGrade(anomalies); } - - anomalies.push({ - startTime: dateRange.startDate, - endTime: dateRange.startDate, - plotTime: interval - ? dateRange.startDate - MIN_IN_MILLI_SECS * interval - : dateRange.startDate, - confidence: null, - anomalyGrade: null, - }); - anomalies.unshift({ - startTime: dateRange.endDate, - endTime: dateRange.endDate, - plotTime: interval - ? dateRange.endDate + MIN_IN_MILLI_SECS * interval - : dateRange.endDate, - confidence: null, - anomalyGrade: null, - }); - if (getFloorPlotTime) { + if (getFloorPlotTime) { // we need to get floor plot time for bar chart anomalies = anomalies.map(anomaly => { return { ...anomaly, plotTime: getFloorPlotTime(anomaly.plotTime), }; }); + anomalies.push({ + startTime: dateRange.startDate, + endTime: dateRange.startDate, + plotTime: anomalies[anomalies.length - 1].plotTime - MIN_IN_MILLI_SECS * interval, + confidence: null, + anomalyGrade: null, + }); + anomalies.unshift({ + startTime: dateRange.endDate, + endTime: dateRange.endDate, + plotTime: anomalies[0].plotTime + MIN_IN_MILLI_SECS * interval, + confidence: null, + anomalyGrade: null, + }); + } else { + anomalies.push({ + startTime: dateRange.startDate, + endTime: dateRange.startDate, + plotTime: dateRange.startDate, + confidence: null, + anomalyGrade: null, + }); + anomalies.unshift({ + startTime: dateRange.endDate, + endTime: dateRange.endDate, + plotTime: dateRange.endDate, + confidence: null, + anomalyGrade: null, + }); } return anomalies; }; From 03427f593f8b51821628ff8d0e57ead25bb123de Mon Sep 17 00:00:00 2001 From: Yaliang Wu Date: Fri, 8 May 2020 12:33:28 -0700 Subject: [PATCH 2/3] fix null anomalies and missing now line --- public/pages/utils/anomalyResultUtils.ts | 37 +++++++++++++++++++++--- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/public/pages/utils/anomalyResultUtils.ts b/public/pages/utils/anomalyResultUtils.ts index 12304ad2..039f03a1 100644 --- a/public/pages/utils/anomalyResultUtils.ts +++ b/public/pages/utils/anomalyResultUtils.ts @@ -111,7 +111,7 @@ export const prepareDataForChart = ( data: any[], dateRange: DateRange, interval: number = 1, - getFloorPlotTime?: any, + getFloorPlotTime?: any ) => { if (!data || data.length === 0) { return []; @@ -124,24 +124,53 @@ export const prepareDataForChart = ( if (anomalies.length > MAX_DATA_POINTS) { anomalies = sampleMaxAnomalyGrade(anomalies); } - if (getFloorPlotTime) { // we need to get floor plot time for bar chart + if (getFloorPlotTime) { + // we need to get floor plot time for bar chart anomalies = anomalies.map(anomaly => { return { ...anomaly, plotTime: getFloorPlotTime(anomaly.plotTime), }; }); + let startTime = + anomalies.length > 0 + ? anomalies[anomalies.length - 1].plotTime + : getFloorPlotTime(dateRange.startDate); + let endTime = + anomalies.length > 0 + ? anomalies[0].plotTime + : getFloorPlotTime(dateRange.endDate); + + while (endTime < dateRange.endDate) { + endTime += MIN_IN_MILLI_SECS * interval; + } + if (anomalies.length === 0) { + for ( + let time = endTime; + time > startTime; + time -= MIN_IN_MILLI_SECS * interval + ) { + anomalies.push({ + startTime: time, + endTime: time, + plotTime: time, + confidence: null, + anomalyGrade: null, + }); + } + } + anomalies.push({ startTime: dateRange.startDate, endTime: dateRange.startDate, - plotTime: anomalies[anomalies.length - 1].plotTime - MIN_IN_MILLI_SECS * interval, + plotTime: startTime - MIN_IN_MILLI_SECS * interval, confidence: null, anomalyGrade: null, }); anomalies.unshift({ startTime: dateRange.endDate, endTime: dateRange.endDate, - plotTime: anomalies[0].plotTime + MIN_IN_MILLI_SECS * interval, + plotTime: endTime, confidence: null, anomalyGrade: null, }); From e55bbf7232fada3fdcdc10749dd58d0d4666d378 Mon Sep 17 00:00:00 2001 From: Yaliang Wu Date: Fri, 8 May 2020 12:41:48 -0700 Subject: [PATCH 3/3] add comments; add Yizhe and Tyler to CONTRIBUTORS --- CONTRIBUTORS | 2 ++ public/pages/utils/anomalyResultUtils.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 6a98ed6a..65b24843 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -6,6 +6,8 @@ Jack Mazanec Mihir Soni Chris Swierczewski Yaliang Wu +Yizhe Liu +Tyler Ohlsen Hanguang Zhang Jing Zhang Pavani Baddepudi diff --git a/public/pages/utils/anomalyResultUtils.ts b/public/pages/utils/anomalyResultUtils.ts index 039f03a1..0540440b 100644 --- a/public/pages/utils/anomalyResultUtils.ts +++ b/public/pages/utils/anomalyResultUtils.ts @@ -142,6 +142,7 @@ export const prepareDataForChart = ( : getFloorPlotTime(dateRange.endDate); while (endTime < dateRange.endDate) { + // make sure the end of plot time is big enough to cover NOW annotation, which is at dateRange.endDate endTime += MIN_IN_MILLI_SECS * interval; } if (anomalies.length === 0) {