Search in sources :

Example 26 with TimeSpec

use of com.linkedin.thirdeye.api.TimeSpec in project pinot by linkedin.

the class DetectionJobSchedulerUtils method getBoundaryAlignedTimeForDataset.

/**
   * round this time to earlier boundary, depending on granularity of dataset
   * e.g. 12:15pm on HOURLY dataset should be treated as 12pm
   * any dataset with granularity finer than HOUR, will be rounded as per function frequency (assumption is that this is in MINUTES)
   * so 12.53 on 5 MINUTES dataset, with function frequency 15 MINUTES will be rounded to 12.45
   * @param anomalyFunction
   * @param timeSpec
   * @param dataCompletenessStartTime
   * @param dateTimeZone
   * @return
   */
public static long getBoundaryAlignedTimeForDataset(DatasetConfigDTO datasetConfig, DateTime dateTime, AnomalyFunctionDTO anomalyFunction) {
    TimeSpec timeSpec = ThirdEyeUtils.getTimeSpecFromDatasetConfig(datasetConfig);
    TimeUnit dataUnit = timeSpec.getDataGranularity().getUnit();
    TimeGranularity functionFrequency = anomalyFunction.getFrequency();
    // Calculate time periods according to the function frequency
    if (dataUnit.equals(TimeUnit.MINUTES) || dataUnit.equals(TimeUnit.MILLISECONDS) || dataUnit.equals(TimeUnit.SECONDS)) {
        if (functionFrequency.getUnit().equals(TimeUnit.MINUTES) && (functionFrequency.getSize() <= 30)) {
            int minuteBucketSize = functionFrequency.getSize();
            int roundedMinutes = (dateTime.getMinuteOfHour() / minuteBucketSize) * minuteBucketSize;
            dateTime = dateTime.withTime(dateTime.getHourOfDay(), roundedMinutes, 0, 0);
        } else {
            // default to HOURS
            dateTime = getBoundaryAlignedTimeForDataset(dateTime, TimeUnit.HOURS);
        }
    } else {
        dateTime = getBoundaryAlignedTimeForDataset(dateTime, dataUnit);
    }
    return dateTime.getMillis();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) TimeSpec(com.linkedin.thirdeye.api.TimeSpec)

Aggregations

TimeSpec (com.linkedin.thirdeye.api.TimeSpec)26 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)14 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)13 DateTime (org.joda.time.DateTime)11 DateTimeZone (org.joda.time.DateTimeZone)8 TimeUnit (java.util.concurrent.TimeUnit)6 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)6 ExecutionException (java.util.concurrent.ExecutionException)5 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)4 ArrayList (java.util.ArrayList)4 Path (javax.ws.rs.Path)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 JSONException (org.json.JSONException)3 ResultSet (com.linkedin.pinot.client.ResultSet)2 ResultSetGroup (com.linkedin.pinot.client.ResultSetGroup)2 TimeOnTimeComparisonRequest (com.linkedin.thirdeye.client.comparison.TimeOnTimeComparisonRequest)2 TimeSeriesHandler (com.linkedin.thirdeye.client.timeseries.TimeSeriesHandler)2 TimeSeriesRequest (com.linkedin.thirdeye.client.timeseries.TimeSeriesRequest)2 TimeSeriesResponse (com.linkedin.thirdeye.client.timeseries.TimeSeriesResponse)2