use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestMergedAnomalyResultManager method testMergedResultCRUD.
@Test
public void testMergedResultCRUD() {
anomalyFunctionDAO.save(function);
Assert.assertNotNull(function.getId());
// create anomaly result
RawAnomalyResultDTO result = getAnomalyResult();
result.setFunction(function);
rawAnomalyResultDAO.save(result);
RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(result.getId());
Assert.assertEquals(resultRet.getFunction(), function);
anomalyResultId = result.getId();
// Let's create merged result
List<RawAnomalyResultDTO> rawResults = new ArrayList<>();
rawResults.add(result);
AnomalyMergeConfig mergeConfig = new AnomalyMergeConfig();
List<MergedAnomalyResultDTO> mergedResults = AnomalyTimeBasedSummarizer.mergeAnomalies(rawResults, mergeConfig.getMaxMergeDurationLength(), mergeConfig.getSequentialAllowedGap());
Assert.assertEquals(mergedResults.get(0).getStartTime(), result.getStartTime());
Assert.assertEquals(mergedResults.get(0).getEndTime(), result.getEndTime());
Assert.assertEquals(mergedResults.get(0).getAnomalyResults().get(0), result);
// Let's persist the merged result
mergedResults.get(0).setDimensions(result.getDimensions());
mergedAnomalyResultDAO.save(mergedResults.get(0));
mergedResult = mergedResults.get(0);
Assert.assertNotNull(mergedResult.getId());
// verify the merged result
MergedAnomalyResultDTO mergedResultById = mergedAnomalyResultDAO.findById(mergedResult.getId());
Assert.assertEquals(mergedResultById.getAnomalyResults(), rawResults);
Assert.assertEquals(mergedResultById.getAnomalyResults().get(0).getId(), anomalyResultId);
List<MergedAnomalyResultDTO> mergedResultsByMetricDimensionsTime = mergedAnomalyResultDAO.findByCollectionMetricDimensionsTime(mergedResult.getCollection(), mergedResult.getMetric(), mergedResult.getDimensions().toString(), 0, System.currentTimeMillis(), true);
Assert.assertEquals(mergedResultsByMetricDimensionsTime.get(0), mergedResult);
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestAnomalyResultManager method testResultFeedback.
@Test(dependsOnMethods = { "testAnomalyResultCRUD" })
public void testResultFeedback() {
RawAnomalyResultDTO result = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertNotNull(result);
Assert.assertNull(result.getFeedback());
AnomalyFeedbackDTO feedback = new AnomalyFeedbackDTO();
feedback.setComment("this is a good find");
feedback.setFeedbackType(AnomalyFeedbackType.ANOMALY);
feedback.setStatus(FeedbackStatus.NEW);
result.setFeedback(feedback);
rawAnomalyResultDAO.save(result);
RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertEquals(resultRet.getId(), result.getId());
Assert.assertNotNull(resultRet.getFeedback());
AnomalyFunctionDTO functionSpec = result.getFunction();
rawAnomalyResultDAO.deleteById(anomalyResult.getId());
anomalyFunctionDAO.deleteById(functionSpec.getId());
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestAnomalyResultManager method testAnomalyResultCRUD.
@Test
public void testAnomalyResultCRUD() {
anomalyFunctionDAO.save(spec);
Assert.assertNotNull(spec);
// create anomaly result
anomalyResult = getAnomalyResult();
anomalyResult.setFunction(spec);
rawAnomalyResultDAO.save(anomalyResult);
RawAnomalyResultDTO resultRet = rawAnomalyResultDAO.findById(anomalyResult.getId());
Assert.assertEquals(resultRet.getFunction(), spec);
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class RawAnomalyResultManagerImpl method findByPredicate.
private List<RawAnomalyResultDTO> findByPredicate(Predicate predicate) {
List<RawAnomalyResultBean> list = genericPojoDao.get(predicate, RawAnomalyResultBean.class);
List<RawAnomalyResultDTO> result = new ArrayList<>();
for (RawAnomalyResultBean bean : list) {
result.add(createRawAnomalyDTOFromBean(bean));
}
return result;
}
use of com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO in project pinot by linkedin.
the class TestMinMaxThresholdFunction method analyze.
@Test(dataProvider = "timeSeriesDataProvider")
public void analyze(Properties properties, TimeSeriesKey timeSeriesKey, long bucketSizeInMs, TimeSeries observedTimeSeries) throws Exception {
AnomalyDetectionContext anomalyDetectionContext = new AnomalyDetectionContext();
anomalyDetectionContext.setBucketSizeInMS(bucketSizeInMs);
properties.put(MinMaxThresholdDetectionModel.MAX_VAL, "20");
properties.put(MinMaxThresholdDetectionModel.MIN_VAL, "12");
// Create anomaly function spec
AnomalyFunctionDTO functionSpec = new AnomalyFunctionDTO();
functionSpec.setMetric(mainMetric);
functionSpec.setProperties(TestWeekOverWeekRuleFunction.toString(properties));
AnomalyDetectionFunction function = new MinMaxThresholdFunction();
function.init(functionSpec);
anomalyDetectionContext.setAnomalyDetectionFunction(function);
anomalyDetectionContext.setCurrent(mainMetric, observedTimeSeries);
anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
List<RawAnomalyResultDTO> actualAnomalyResults = function.analyze(anomalyDetectionContext);
// Expected RawAnomalies of WoW without smoothing
List<RawAnomalyResultDTO> expectedRawAnomalies = new ArrayList<>();
RawAnomalyResultDTO rawAnomaly1 = new RawAnomalyResultDTO();
rawAnomaly1.setStartTime(observedStartTime);
rawAnomaly1.setEndTime(observedStartTime + bucketMillis);
rawAnomaly1.setWeight(-0.166666d);
rawAnomaly1.setScore(13.6d);
expectedRawAnomalies.add(rawAnomaly1);
RawAnomalyResultDTO rawAnomaly2 = new RawAnomalyResultDTO();
rawAnomaly2.setStartTime(observedStartTime + bucketMillis * 3);
rawAnomaly2.setEndTime(observedStartTime + bucketMillis * 4);
rawAnomaly2.setWeight(0.1d);
rawAnomaly2.setScore(13.6d);
expectedRawAnomalies.add(rawAnomaly2);
RawAnomalyResultDTO rawAnomaly3 = new RawAnomalyResultDTO();
rawAnomaly3.setStartTime(observedStartTime + bucketMillis * 4);
rawAnomaly3.setEndTime(observedStartTime + bucketMillis * 5);
rawAnomaly3.setWeight(-0.33333d);
rawAnomaly3.setScore(13.6d);
expectedRawAnomalies.add(rawAnomaly3);
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);
}
// Test getTimeSeriesIntervals
List<Interval> expectedDataRanges = new ArrayList<>();
expectedDataRanges.add(new Interval(observedStartTime, observedStartTime + bucketMillis * 5));
List<Interval> actualDataRanges = function.getTimeSeriesIntervals(observedStartTime, observedStartTime + bucketMillis * 5);
Assert.assertEquals(actualDataRanges, expectedDataRanges);
}
Aggregations