package com.linkedin.thirdeye.anomalydetection.performanceEvaluation; import com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO; import com.linkedin.thirdeye.util.IntervalUtils; import java.util.List; import org.joda.time.Interval; /** * The performance evaluator calculates the percentage of time when there are anomalies * We care about the frequency of anomaly generated by our algorithm. This performance evaluator can help us providing * this information to clients or backend algorithms */ public class AnomalyPercentagePerformanceEvaluation extends BasePerformanceEvaluate{ private Interval windowInterval; private List<MergedAnomalyResultDTO> detectedResults; public AnomalyPercentagePerformanceEvaluation(Interval windowInterval, List<MergedAnomalyResultDTO> detectedResults) { this.windowInterval = windowInterval; this.detectedResults = detectedResults; } @Override public double evaluate(){ long anomalyLength = 0; long totalLength = windowInterval.toDurationMillis(); List<Interval> anomalyIntervals = mergedAnomalyResultsToIntervals(detectedResults); anomalyIntervals = IntervalUtils.mergeIntervals(anomalyIntervals); for(Interval interval : anomalyIntervals) { anomalyLength += interval.toDurationMillis(); } double ratio = (double) anomalyLength / totalLength; return ratio; } }