From d259e1f25881cfa310eb3fd88adce194fcab928f Mon Sep 17 00:00:00 2001 From: Pete Harverson Date: Tue, 9 Apr 2019 17:04:42 +0100 Subject: [PATCH] [ML] Fixes Single Metric Viewer anomaly markers for long chart aggregation (#34791) --- .../timeseriesexplorer_controller.js | 3 ++- .../timeseriesexplorer_utils.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js index 7fe1a004b251..4d0fb34294ad 100644 --- a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js +++ b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_controller.js @@ -420,7 +420,8 @@ module.controller('MlTimeSeriesExplorerController', function ( refreshFocusData.focusChartData, refreshFocusData.anomalyRecords, $scope.timeFieldName, - $scope.focusAggregationInterval); + $scope.focusAggregationInterval, + $scope.modelPlotEnabled); refreshFocusData.focusChartData = processScheduledEventsForChart( refreshFocusData.focusChartData, diff --git a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_utils.js b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_utils.js index 7d76b4a242ec..33048cb0f9d0 100644 --- a/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_utils.js +++ b/x-pack/plugins/ml/public/timeseriesexplorer/timeseriesexplorer_utils.js @@ -98,7 +98,8 @@ export function processDataForFocusAnomalies( chartData, anomalyRecords, timeFieldName, - aggregationInterval) { + aggregationInterval, + modelPlotEnabled) { const timesToAddPointsFor = []; @@ -122,10 +123,16 @@ export function processDataForFocusAnomalies( timesToAddPointsFor.sort((a, b) => a - b); timesToAddPointsFor.forEach((time) => { - chartData.push({ + const pointToAdd = { date: new Date(time), value: null - }); + }; + + if (modelPlotEnabled === true) { + pointToAdd.upper = null; + pointToAdd.lower = null; + } + chartData.push(pointToAdd); }); // Iterate through the anomaly records adding the @@ -257,10 +264,9 @@ export function findChartPointForAnomalyTime(chartData, anomalyTime, aggregation // which contains the anomalous bucket. let foundItem; const intervalMs = aggregationInterval.asMilliseconds(); - const anomalyTimeForAggInt = (Math.floor(anomalyTime / intervalMs)) * intervalMs; for (let i = 0; i < chartData.length; i++) { const itemTime = chartData[i].date.getTime(); - if (itemTime === anomalyTimeForAggInt) { + if (anomalyTime - itemTime < intervalMs) { foundItem = chartData[i]; break; }