jihaozh commented on a change in pull request #4176: [TE] anomaly detector 
interface change and implementation for rule-based detection
URL: https://github.com/apache/incubator-pinot/pull/4176#discussion_r279875131
 
 

 ##########
 File path: 
thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/components/ThresholdRuleDetector.java
 ##########
 @@ -87,8 +91,38 @@
     df.mapInPlace(BooleanSeries.HAS_TRUE, COL_ANOMALY, COL_TOO_HIGH, 
COL_TOO_LOW);
 
     DatasetConfigDTO datasetConfig = 
data.getDatasetForMetricId().get(me.getId());
-    return DetectionUtils.makeAnomalies(slice, df, COL_ANOMALY, endTime,
+    List<MergedAnomalyResultDTO> anomalies = 
DetectionUtils.makeAnomalies(slice, df, COL_ANOMALY, endTime,
         DetectionUtils.getMonitoringGranularityPeriod(monitoringGranularity, 
datasetConfig), datasetConfig);
+    return DetectionResult.from(anomalies, 
TimeSeries.fromDataFrame(constructThresholdBoundaries(df)));
+  }
+
+  @Override
+  public TimeSeries computePredictedTimeSeries(MetricSlice slice) {
+    InputData data =
+        this.dataFetcher.fetchData(new 
InputDataSpec().withTimeseriesSlices(Collections.singletonList(slice)));
+    DataFrame df = data.getTimeseries().get(slice);
+    return TimeSeries.fromDataFrame(constructThresholdBoundaries(df));
+  }
+
+  private DataFrame constructThresholdBoundaries(DataFrame df) {
+    if (!Double.isNaN(this.min)) {
+      df.addSeries(COL_LOWER_BOUND, DoubleSeries.fillValues(df.size(), 
this.min));
+    }
+    if (!Double.isNaN(this.max)) {
+      df.addSeries(COL_UPPER_BOUND, DoubleSeries.fillValues(df.size(), 
this.max));
+    }
+    df.addSeries(COL_VALUE, DoubleSeries.fillValues(df.size(), 
predictedValue()));
+    return df;
+  }
+
+  private double predictedValue() {
 
 Review comment:
   One thing is that, if we set the predicted value the same as current value, 
the percentage change will be 0 in UI.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to