Search in sources :

Example 1 with TimeSeriesKey

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;
}
Also used : AnomalyDetectionContext(com.linkedin.thirdeye.anomalydetection.context.AnomalyDetectionContext) TimeSeries(com.linkedin.thirdeye.anomalydetection.context.TimeSeries) MetricTimeSeries(com.linkedin.thirdeye.api.MetricTimeSeries) TimeSeriesKey(com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey) Interval(org.joda.time.Interval)

Example 2 with TimeSeriesKey

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 } };
}
Also used : TimeSeries(com.linkedin.thirdeye.anomalydetection.context.TimeSeries) TimeSeriesKey(com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey) ArrayList(java.util.ArrayList) DimensionMap(com.linkedin.thirdeye.api.DimensionMap) Properties(java.util.Properties) Interval(org.joda.time.Interval) DataProvider(org.testng.annotations.DataProvider)

Example 3 with TimeSeriesKey

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 } };
}
Also used : TimeSeries(com.linkedin.thirdeye.anomalydetection.context.TimeSeries) TimeSeriesKey(com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey) DimensionMap(com.linkedin.thirdeye.api.DimensionMap) Properties(java.util.Properties) Interval(org.joda.time.Interval) DataProvider(org.testng.annotations.DataProvider)

Aggregations

TimeSeries (com.linkedin.thirdeye.anomalydetection.context.TimeSeries)3 TimeSeriesKey (com.linkedin.thirdeye.anomalydetection.context.TimeSeriesKey)3 Interval (org.joda.time.Interval)3 DimensionMap (com.linkedin.thirdeye.api.DimensionMap)2 Properties (java.util.Properties)2 DataProvider (org.testng.annotations.DataProvider)2 AnomalyDetectionContext (com.linkedin.thirdeye.anomalydetection.context.AnomalyDetectionContext)1 MetricTimeSeries (com.linkedin.thirdeye.api.MetricTimeSeries)1 ArrayList (java.util.ArrayList)1