use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestWeekOverWeekRuleFunction method compareActualAndExpectedRawAnomalies.
private void compareActualAndExpectedRawAnomalies(List<RawAnomalyResultDTO> actualAnomalyResults, List<RawAnomalyResultDTO> expectedRawAnomalies) {
Assert.assertEquals(actualAnomalyResults.size(), expectedRawAnomalies.size());
for (int i = 0; i < actualAnomalyResults.size(); ++i) {
RawAnomalyResultDTO actualAnomaly = actualAnomalyResults.get(i);
RawAnomalyResultDTO expectedAnomaly = actualAnomalyResults.get(i);
Assert.assertEquals(actualAnomaly.getWeight(), expectedAnomaly.getWeight(), EPSILON);
Assert.assertEquals(actualAnomaly.getScore(), expectedAnomaly.getScore(), EPSILON);
}
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestWeekOverWeekRuleFunction method analyzeWo2WAvg.
@Test(dataProvider = "timeSeriesDataProvider")
public void analyzeWo2WAvg(Properties properties, TimeSeriesKey timeSeriesKey, long bucketSizeInMs, TimeSeries observedTimeSeries, List<TimeSeries> baselines) throws Exception {
// Expected RawAnomalies without smoothing
List<RawAnomalyResultDTO> expectedRawAnomalies = new ArrayList<>();
RawAnomalyResultDTO rawAnomaly1 = new RawAnomalyResultDTO();
rawAnomaly1.setStartTime(observedStartTime + bucketMillis * 2);
rawAnomaly1.setEndTime(observedStartTime + bucketMillis * 3);
rawAnomaly1.setWeight(0.3d);
rawAnomaly1.setScore(15d);
expectedRawAnomalies.add(rawAnomaly1);
RawAnomalyResultDTO rawAnomaly2 = new RawAnomalyResultDTO();
rawAnomaly2.setStartTime(observedStartTime + bucketMillis * 3);
rawAnomaly2.setEndTime(observedStartTime + bucketMillis * 4);
rawAnomaly2.setWeight(0.22727272727272727);
rawAnomaly2.setScore(15d);
expectedRawAnomalies.add(rawAnomaly2);
AnomalyDetectionContext anomalyDetectionContext = new AnomalyDetectionContext();
anomalyDetectionContext.setBucketSizeInMS(bucketSizeInMs);
// Append properties for anomaly function specific setting
properties.put(WeekOverWeekRuleFunction.BASELINE, "w/2wAvg");
properties.put(SimpleThresholdDetectionModel.CHANGE_THRESHOLD, "0.2");
// Create anomaly function spec
AnomalyFunctionDTO functionSpec = new AnomalyFunctionDTO();
functionSpec.setMetric(mainMetric);
functionSpec.setProperties(toString(properties));
WeekOverWeekRuleFunction function = new WeekOverWeekRuleFunction();
function.init(functionSpec);
anomalyDetectionContext.setAnomalyDetectionFunction(function);
anomalyDetectionContext.setCurrent(mainMetric, observedTimeSeries);
anomalyDetectionContext.setBaselines(mainMetric, baselines);
anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
List<RawAnomalyResultDTO> rawAnomalyResults = function.analyze(anomalyDetectionContext);
compareWo2WAvgRawAnomalies(rawAnomalyResults);
// Test data model
List<Interval> expectedDataRanges = new ArrayList<>();
expectedDataRanges.add(new Interval(observedStartTime, observedStartTime + bucketMillis * 5));
expectedDataRanges.add(new Interval(observedStartTime - oneWeekInMillis, observedStartTime + bucketMillis * 5 - oneWeekInMillis));
expectedDataRanges.add(new Interval(observedStartTime - oneWeekInMillis * 2, observedStartTime + bucketMillis * 5 - oneWeekInMillis * 2));
List<Interval> actualDataRanges = function.getDataModel().getAllDataIntervals(observedStartTime, observedStartTime + bucketMillis * 5);
Assert.assertEquals(actualDataRanges, expectedDataRanges);
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestWeekOverWeekRuleFunction method compareWoWRawAnomalies.
private void compareWoWRawAnomalies(List<RawAnomalyResultDTO> actualAnomalyResults) {
// Expected RawAnomalies of WoW without smoothing
List<RawAnomalyResultDTO> expectedRawAnomalies = new ArrayList<>();
RawAnomalyResultDTO rawAnomaly1 = new RawAnomalyResultDTO();
rawAnomaly1.setStartTime(observedStartTime + bucketMillis);
rawAnomaly1.setEndTime(observedStartTime + bucketMillis * 2);
rawAnomaly1.setWeight(-0.25d);
rawAnomaly1.setScore(15d);
expectedRawAnomalies.add(rawAnomaly1);
RawAnomalyResultDTO rawAnomaly2 = new RawAnomalyResultDTO();
rawAnomaly2.setStartTime(observedStartTime + bucketMillis * 4);
rawAnomaly2.setEndTime(observedStartTime + bucketMillis * 5);
rawAnomaly2.setWeight(-0.2857142857d);
rawAnomaly2.setScore(15d);
expectedRawAnomalies.add(rawAnomaly2);
compareActualAndExpectedRawAnomalies(actualAnomalyResults, expectedRawAnomalies);
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestWeekOverWeekRuleFunction method testTotalCountThresholdFunction.
@Test(dataProvider = "timeSeriesDataProvider")
public void testTotalCountThresholdFunction(Properties properties, TimeSeriesKey timeSeriesKey, long bucketSizeInMs, TimeSeries observedTimeSeries, List<TimeSeries> baselines) throws Exception {
AnomalyDetectionContext anomalyDetectionContext = new AnomalyDetectionContext();
anomalyDetectionContext.setBucketSizeInMS(bucketSizeInMs);
// Append properties for anomaly function specific setting
String totalCountTimeSeriesName = "totalCount";
TimeSeries totalCountTimeSeries = new TimeSeries();
{
totalCountTimeSeries.set(observedStartTime, 10d);
totalCountTimeSeries.set(observedStartTime + bucketMillis, 10d);
totalCountTimeSeries.set(observedStartTime + bucketMillis * 2, 10d);
totalCountTimeSeries.set(observedStartTime + bucketMillis * 3, 10d);
totalCountTimeSeries.set(observedStartTime + bucketMillis * 4, 10d);
Interval totalCountTimeSeriesInterval = new Interval(observedStartTime, observedStartTime + bucketMillis * 5);
totalCountTimeSeries.setTimeSeriesInterval(totalCountTimeSeriesInterval);
}
properties.put(TotalCountThresholdRemovalFunction.TOTAL_COUNT_METRIC_NAME, totalCountTimeSeriesName);
properties.put(TotalCountThresholdRemovalFunction.TOTAL_COUNT_THRESHOLD, "51");
properties.put(WeekOverWeekRuleFunction.BASELINE, "w/2wAvg");
properties.put(SimpleThresholdDetectionModel.CHANGE_THRESHOLD, "0.2");
// Create anomaly function spec
AnomalyFunctionDTO functionSpec = new AnomalyFunctionDTO();
functionSpec.setMetric(mainMetric);
functionSpec.setProperties(toString(properties));
// Create anomalyDetectionContext using anomaly function spec
WeekOverWeekRuleFunction function = new WeekOverWeekRuleFunction();
function.init(functionSpec);
anomalyDetectionContext.setAnomalyDetectionFunction(function);
anomalyDetectionContext.setCurrent(mainMetric, observedTimeSeries);
anomalyDetectionContext.setBaselines(mainMetric, baselines);
anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
anomalyDetectionContext.setCurrent(totalCountTimeSeriesName, totalCountTimeSeries);
List<RawAnomalyResultDTO> rawAnomalyResults = function.analyze(anomalyDetectionContext);
// No anomalies after smoothing the time series
Assert.assertEquals(rawAnomalyResults.size(), 0);
// Test disabled total count by lowering the threshold
anomalyDetectionContext = new AnomalyDetectionContext();
anomalyDetectionContext.setBucketSizeInMS(bucketSizeInMs);
properties.put(TotalCountThresholdRemovalFunction.TOTAL_COUNT_THRESHOLD, "0");
// Create anomaly function spec
functionSpec = new AnomalyFunctionDTO();
functionSpec.setMetric(mainMetric);
functionSpec.setProperties(toString(properties));
function = new WeekOverWeekRuleFunction();
function.init(functionSpec);
anomalyDetectionContext.setAnomalyDetectionFunction(function);
anomalyDetectionContext.setCurrent(mainMetric, observedTimeSeries);
anomalyDetectionContext.setBaselines(mainMetric, baselines);
anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
anomalyDetectionContext.setCurrent(totalCountTimeSeriesName, totalCountTimeSeries);
rawAnomalyResults = function.analyze(anomalyDetectionContext);
compareWo2WAvgRawAnomalies(rawAnomalyResults);
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class FetchMetricDataAndExistingAnomaliesTool method fetchRawAnomaliesInRangeByFunctionId.
public List<ResultNode> fetchRawAnomaliesInRangeByFunctionId(long functionId, DateTime startTime, DateTime endTime) {
AnomalyFunctionDTO anomalyFunction = anomalyFunctionDAO.findById(functionId);
LOG.info(String.format("Loading raw anaomaly results of functionId {} from db...", Long.toString(functionId)));
List<ResultNode> resultNodes = new ArrayList<>();
if (anomalyFunction == null) {
// no such function
return resultNodes;
}
List<RawAnomalyResultDTO> rawResults = rawAnomalyResultDAO.findAllByTimeAndFunctionId(startTime.getMillis(), endTime.getMillis(), functionId);
for (RawAnomalyResultDTO rawResult : rawResults) {
ResultNode res = new ResultNode();
res.functionId = functionId;
res.functionName = anomalyFunction.getFunctionName();
res.startTime = new DateTime(rawResult.getStartTime());
res.endTime = new DateTime(rawResult.getEndTime());
res.dimensions = rawResult.getDimensions();
res.setFilters(anomalyFunction.getFilters());
res.severity = rawResult.getWeight();
AnomalyFeedbackDTO feedback = rawResult.getFeedback();
res.feedbackType = (feedback == null) ? null : feedback.getFeedbackType();
resultNodes.add(res);
}
return resultNodes;
}
Aggregations