use of com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey in project pinot by linkedin.
the class BackwardAnomalyFunctionUtils method buildAnomalyDetectionContext.
/**
* Returns an anomaly detection context from the given information.
*
* @param anomalyFunction the anomaly function for anomaly detection.
* @param timeSeries the given time series.
* @param metric the metric name of the given time series.
* @param exploredDimensions the dimension map of the given time series.
* @param windowStart the start of the interval of the time series.
* @param windowEnd the end of the interval of the time series.
*
* @return an anomaly detection context from the given information.
*/
public static AnomalyDetectionContext buildAnomalyDetectionContext(AnomalyDetectionFunction anomalyFunction, MetricTimeSeries timeSeries, String metric, DimensionMap exploredDimensions, int bucketSize, TimeUnit bucketUnit, DateTime windowStart, DateTime windowEnd) {
// Create the anomaly detection context for the new modularized anomaly function
AnomalyDetectionContext anomalyDetectionContext = new AnomalyDetectionContext();
anomalyDetectionContext.setBucketSizeInMS(AnomalyDetectionUtils.getBucketInMillis(bucketSize, bucketUnit));
anomalyDetectionContext.setAnomalyDetectionFunction(anomalyFunction);
// Construct TimeSeriesKey
TimeSeriesKey timeSeriesKey = new TimeSeriesKey();
timeSeriesKey.setDimensionMap(exploredDimensions);
timeSeriesKey.setMetricName(metric);
anomalyDetectionContext.setTimeSeriesKey(timeSeriesKey);
// Split time series to observed time series and baselines for each metric
for (String metricName : anomalyFunction.getSpec().getMetrics()) {
List<Interval> intervals = anomalyFunction.getTimeSeriesIntervals(windowStart.getMillis(), windowEnd.getMillis());
List<TimeSeries> timeSeriesList = BackwardAnomalyFunctionUtils.splitSetsOfTimeSeries(timeSeries, metricName, intervals);
anomalyDetectionContext.setCurrent(metricName, timeSeriesList.get(0));
timeSeriesList.remove(0);
anomalyDetectionContext.setBaselines(metricName, timeSeriesList);
}
return anomalyDetectionContext;
}
use of com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey in project pinot by linkedin.
the class TestWeekOverWeekRuleFunction method timeSeriesDataProvider.
@DataProvider(name = "timeSeriesDataProvider")
public Object[][] timeSeriesDataProvider() {
// The properties for the testing time series
Properties properties = new Properties();
long bucketSizeInMS = TimeUnit.SECONDS.toMillis(1);
// Set up time series key for the testing time series
TimeSeriesKey timeSeriesKey = new TimeSeriesKey();
String metric = mainMetric;
timeSeriesKey.setMetricName(metric);
DimensionMap dimensionMap = new DimensionMap();
dimensionMap.put("dimensionName1", "dimensionValue1");
dimensionMap.put("dimensionName2", "dimensionValue2");
timeSeriesKey.setDimensionMap(dimensionMap);
TimeSeries observedTimeSeries = new TimeSeries();
{
observedTimeSeries.set(observedStartTime, 10d);
observedTimeSeries.set(observedStartTime + bucketMillis, 15d);
observedTimeSeries.set(observedStartTime + bucketMillis * 2, 13d);
observedTimeSeries.set(observedStartTime + bucketMillis * 3, 27d);
observedTimeSeries.set(observedStartTime + bucketMillis * 4, 10d);
Interval observedTimeSeriesInterval = new Interval(observedStartTime, observedStartTime + bucketMillis * 5);
observedTimeSeries.setTimeSeriesInterval(observedTimeSeriesInterval);
}
List<TimeSeries> baselines = new ArrayList<>();
TimeSeries baseline1TimeSeries = new TimeSeries();
{
baseline1TimeSeries.set(baseline1StartTime, 10d);
baseline1TimeSeries.set(baseline1StartTime + bucketMillis, 20d);
baseline1TimeSeries.set(baseline1StartTime + bucketMillis * 2, 15d);
baseline1TimeSeries.set(baseline1StartTime + bucketMillis * 3, 24d);
baseline1TimeSeries.set(baseline1StartTime + bucketMillis * 4, 14d);
Interval baseline1Interval = new Interval(baseline1StartTime, baseline1StartTime + bucketMillis * 5);
baseline1TimeSeries.setTimeSeriesInterval(baseline1Interval);
}
baselines.add(baseline1TimeSeries);
TimeSeries baseline2TimeSeries = new TimeSeries();
{
baseline2TimeSeries.set(baseline2StartTime, 10d);
baseline2TimeSeries.set(baseline2StartTime + bucketMillis, 10d);
baseline2TimeSeries.set(baseline2StartTime + bucketMillis * 2, 5d);
baseline2TimeSeries.set(baseline2StartTime + bucketMillis * 3, 20d);
baseline2TimeSeries.set(baseline2StartTime + bucketMillis * 4, 10d);
Interval baseline2Interval = new Interval(baseline2StartTime, baseline2StartTime + bucketMillis * 5);
baseline2TimeSeries.setTimeSeriesInterval(baseline2Interval);
}
baselines.add(baseline2TimeSeries);
return new Object[][] { { properties, timeSeriesKey, bucketSizeInMS, observedTimeSeries, baselines } };
}
use of com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey in project pinot by linkedin.
the class TestMinMaxThresholdFunction method timeSeriesDataProvider.
@DataProvider(name = "timeSeriesDataProvider")
public Object[][] timeSeriesDataProvider() {
// The properties for the testing time series
Properties properties = new Properties();
long bucketSizeInMS = TimeUnit.SECONDS.toMillis(1);
// Set up time series key for the testing time series
TimeSeriesKey timeSeriesKey = new TimeSeriesKey();
String metric = mainMetric;
timeSeriesKey.setMetricName(metric);
DimensionMap dimensionMap = new DimensionMap();
dimensionMap.put("dimensionName1", "dimensionValue1");
dimensionMap.put("dimensionName2", "dimensionValue2");
timeSeriesKey.setDimensionMap(dimensionMap);
TimeSeries observedTimeSeries = new TimeSeries();
{
observedTimeSeries.set(observedStartTime, 10d);
observedTimeSeries.set(observedStartTime + bucketMillis, 15d);
observedTimeSeries.set(observedStartTime + bucketMillis * 2, 13d);
observedTimeSeries.set(observedStartTime + bucketMillis * 3, 22d);
observedTimeSeries.set(observedStartTime + bucketMillis * 4, 8d);
Interval observedTimeSeriesInterval = new Interval(observedStartTime, observedStartTime + bucketMillis * 5);
observedTimeSeries.setTimeSeriesInterval(observedTimeSeriesInterval);
}
return new Object[][] { { properties, timeSeriesKey, bucketSizeInMS, observedTimeSeries } };
}
Aggregations