jihaozh commented on a change in pull request #4466: Adding week over week std rule detector URL: https://github.com/apache/incubator-pinot/pull/4466#discussion_r306941010
########## File path: thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/components/WoWStdRuleDetectorTest.java ########## @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2014-2018 LinkedIn Corp. ([email protected]) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pinot.thirdeye.detection.components; + +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import com.google.common.collect.Multimap; +import com.google.common.collect.TreeMultimap; +import java.util.concurrent.TimeUnit; +import org.apache.pinot.thirdeye.common.time.TimeGranularity; +import org.apache.pinot.thirdeye.dataframe.DataFrame; +import org.apache.pinot.thirdeye.dataframe.util.MetricSlice; +import org.apache.pinot.thirdeye.datalayer.dto.DatasetConfigDTO; +import org.apache.pinot.thirdeye.datalayer.dto.MergedAnomalyResultDTO; +import org.apache.pinot.thirdeye.datalayer.dto.MetricConfigDTO; +import org.apache.pinot.thirdeye.detection.DataProvider; +import org.apache.pinot.thirdeye.detection.DefaultInputDataFetcher; +import org.apache.pinot.thirdeye.detection.MockDataProvider; +import org.apache.pinot.thirdeye.detection.Pattern; +import org.apache.pinot.thirdeye.detection.algorithm.AlgorithmUtils; +import org.apache.pinot.thirdeye.detection.spec.WoWStdRuleDetectorSpec; +import org.apache.pinot.thirdeye.detection.spi.model.DetectionResult; +import org.apache.pinot.thirdeye.detection.spi.model.TimeSeries; +import org.joda.time.Interval; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.apache.pinot.thirdeye.rootcause.impl.MetricEntity; + +import static org.apache.pinot.thirdeye.dataframe.util.DataFrameUtils.*; + + +public class WoWStdRuleDetectorTest { + + private DataProvider provider; + private DataFrame data; + private Multimap<String, String> filters = TreeMultimap.create(); + + @BeforeMethod + public void setUp() throws Exception { + try (Reader dataReader = new InputStreamReader(AlgorithmUtils.class.getResourceAsStream("timeseries-1y.csv"))) { + this.data = DataFrame.fromCsv(dataReader); + this.data.setIndex(COL_TIME); + } + + MetricConfigDTO dailyMetricConfig = new MetricConfigDTO(); + dailyMetricConfig.setId(1L); + dailyMetricConfig.setName("thirdeye-test-daily"); + dailyMetricConfig.setDataset("thirdeye-test-dataset-daily"); + + DatasetConfigDTO dailyDatasetConfig = new DatasetConfigDTO(); + dailyDatasetConfig.setTimeUnit(TimeUnit.DAYS); + dailyDatasetConfig.setDataset("thirdeye-test-dataset-daily"); + dailyDatasetConfig.setTimeDuration(1); + + Map<MetricSlice, DataFrame> timeseries = new HashMap<>(); + timeseries.put(MetricSlice.from(1L, 1499126400000L, 1562630400000L, filters, TimeGranularity.fromString("7_DAYS")), this.data); + + this.provider = new MockDataProvider() + .setTimeseries(timeseries) + .setMetrics(Collections.singletonList(dailyMetricConfig)) + .setDatasets(Collections.singletonList(dailyDatasetConfig)); + } + + @Test + public void testComputePredictedTimeSeriesDaily() { + WoWStdRuleDetector detector = new WoWStdRuleDetector(); + WoWStdRuleDetectorSpec spec = new WoWStdRuleDetectorSpec(); + spec.setMonitoringGranularity("7_DAYS"); + spec.setLookback(52); + spec.setSensitivity(1.0); + detector.init(spec, new DefaultInputDataFetcher(this.provider, -1)); + Interval window = new Interval(1530576000000L, 1562630400000L); + String metricUrn = "thirdeye:metric:1"; + MetricEntity me = MetricEntity.fromURN(metricUrn); + MetricSlice slice = MetricSlice.from(me.getId(), window.getStartMillis(), window.getEndMillis(), me.getFilters(), TimeGranularity + .fromString(spec.getMonitoringGranularity())); + TimeSeries timeSeries = detector.computePredictedTimeSeries(slice); + Assert.assertEquals(timeSeries.getPredictedBaseline().size(), 53); Review comment: Maybe add an assertion for the predicted values? ---------------------------------------------------------------- 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]
