Search in sources :

Example 21 with TimeGranularity

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

the class TimeSeriesTest method generateGroupByTimeRequest.

private static TimeSeriesRequest generateGroupByTimeRequest() {
    TimeSeriesRequest timeSeriesRequest = new TimeSeriesRequest();
    timeSeriesRequest.setCollectionName(THIRDEYE_ABOOK);
    timeSeriesRequest.setStart(START);
    timeSeriesRequest.setEnd(START.plusDays(1));
    List<MetricFunction> metricFunctions = new ArrayList<>();
    metricFunctions.add(DEFAULT_METRIC_FUNCTION);
    List<MetricExpression> metricExpressions = Utils.convertToMetricExpressions(metricFunctions);
    metricExpressions.add(SUBMIT_RATE_EXPRESSION);
    timeSeriesRequest.setMetricExpressions(metricExpressions);
    timeSeriesRequest.setAggregationTimeGranularity(new TimeGranularity(1, TimeUnit.HOURS));
    return timeSeriesRequest;
}
Also used : MetricFunction(com.linkedin.thirdeye.client.MetricFunction) ArrayList(java.util.ArrayList) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) MetricExpression(com.linkedin.thirdeye.client.MetricExpression)

Example 22 with TimeGranularity

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

the class DataCompletenessTaskUtilsTest method testGetBucketSizeForDataset.

@Test
public void testGetBucketSizeForDataset() throws Exception {
    String columnName = "Date";
    // DAYS bucket
    TimeGranularity timeGranularity = new TimeGranularity(1, TimeUnit.DAYS);
    String timeFormat = TimeSpec.SINCE_EPOCH_FORMAT;
    TimeSpec timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    long bucketSize = DataCompletenessTaskUtils.getBucketSizeInMSForDataset(timeSpec);
    Assert.assertEquals(bucketSize, 24 * 60 * 60_000);
    // HOURS bucket
    timeGranularity = new TimeGranularity(1, TimeUnit.HOURS);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    bucketSize = DataCompletenessTaskUtils.getBucketSizeInMSForDataset(timeSpec);
    Assert.assertEquals(bucketSize, 60 * 60_000);
    // MINUTES returns 30 MINUTES bucket
    timeGranularity = new TimeGranularity(1, TimeUnit.MINUTES);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    bucketSize = DataCompletenessTaskUtils.getBucketSizeInMSForDataset(timeSpec);
    Assert.assertEquals(bucketSize, 30 * 60_000);
    // DEFAULT bucket
    timeGranularity = new TimeGranularity(1, TimeUnit.MILLISECONDS);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    bucketSize = DataCompletenessTaskUtils.getBucketSizeInMSForDataset(timeSpec);
    Assert.assertEquals(bucketSize, 60 * 60_000);
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) Test(org.testng.annotations.Test)

Example 23 with TimeGranularity

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

the class DataCompletenessTaskUtilsTest method testGetBucketNameToTimeValuesMap.

@Test
public void testGetBucketNameToTimeValuesMap() {
    DateTimeZone zone = DateTimeZone.forID("America/Los_Angeles");
    // SDF
    String columnName = "Date";
    TimeGranularity timeGranularity = new TimeGranularity(1, TimeUnit.DAYS);
    String timeFormat = "SIMPLE_DATE_FORMAT:yyyyMMdd";
    TimeSpec timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    // DAYS
    Map<String, Long> bucketNameToBucketValue = new HashMap<>();
    bucketNameToBucketValue.put("20170112", new DateTime(2017, 01, 12, 0, 0, zone).getMillis());
    bucketNameToBucketValue.put("20170113", new DateTime(2017, 01, 13, 0, 0, zone).getMillis());
    bucketNameToBucketValue.put("20170114", new DateTime(2017, 01, 14, 0, 0, zone).getMillis());
    Map<String, Long> expectedValues = new HashMap<>();
    expectedValues.put("20170112", 20170112L);
    expectedValues.put("20170113", 20170113L);
    expectedValues.put("20170114", 20170114L);
    ListMultimap<String, Long> bucketNameToTimeValuesMap = DataCompletenessTaskUtils.getBucketNameToTimeValuesMap(timeSpec, bucketNameToBucketValue);
    for (Entry<String, Long> entry : bucketNameToTimeValuesMap.entries()) {
        String bucketName = entry.getKey();
        Assert.assertEquals(entry.getValue(), expectedValues.get(bucketName));
    }
    // EPOCH
    zone = DateTimeZone.UTC;
    timeFormat = TimeSpec.SINCE_EPOCH_FORMAT;
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    // HOURS
    timeGranularity = new TimeGranularity(1, TimeUnit.HOURS);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    bucketNameToBucketValue = new HashMap<>();
    bucketNameToBucketValue.put("2017011200", new DateTime(2017, 01, 12, 0, 0, zone).getMillis());
    bucketNameToBucketValue.put("2017011201", new DateTime(2017, 01, 12, 1, 0, zone).getMillis());
    bucketNameToBucketValue.put("2017011202", new DateTime(2017, 01, 12, 2, 0, zone).getMillis());
    expectedValues = new HashMap<>();
    // hours since epoch values
    expectedValues.put("2017011200", 412272L);
    expectedValues.put("2017011201", 412273L);
    expectedValues.put("2017011202", 412274L);
    bucketNameToTimeValuesMap = DataCompletenessTaskUtils.getBucketNameToTimeValuesMap(timeSpec, bucketNameToBucketValue);
    for (Entry<String, Long> entry : bucketNameToTimeValuesMap.entries()) {
        String bucketName = entry.getKey();
        Assert.assertEquals(entry.getValue(), expectedValues.get(bucketName));
    }
    // MINUTES
    timeGranularity = new TimeGranularity(10, TimeUnit.MINUTES);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    bucketNameToBucketValue = new HashMap<>();
    bucketNameToBucketValue.put("201701120000", new DateTime(2017, 01, 12, 0, 0, zone).getMillis());
    bucketNameToBucketValue.put("201701120030", new DateTime(2017, 01, 12, 0, 30, zone).getMillis());
    bucketNameToBucketValue.put("201701120100", new DateTime(2017, 01, 12, 1, 00, zone).getMillis());
    bucketNameToBucketValue.put("201701120130", new DateTime(2017, 01, 12, 1, 30, zone).getMillis());
    Map<String, List<Long>> expectedValuesList = new HashMap<>();
    // 10 minutes since epoch values
    expectedValuesList.put("201701120000", Lists.newArrayList(2473632L, 2473633L, 2473634L));
    expectedValuesList.put("201701120030", Lists.newArrayList(2473635L, 2473636L, 2473637L));
    expectedValuesList.put("201701120100", Lists.newArrayList(2473638L, 2473639L, 2473640L));
    expectedValuesList.put("201701120130", Lists.newArrayList(2473641L, 2473642L, 2473643L));
    bucketNameToTimeValuesMap = DataCompletenessTaskUtils.getBucketNameToTimeValuesMap(timeSpec, bucketNameToBucketValue);
    for (String bucketName : bucketNameToTimeValuesMap.keySet()) {
        List<Long> timeValues = bucketNameToTimeValuesMap.get(bucketName);
        Collections.sort(timeValues);
        Assert.assertEquals(timeValues, expectedValuesList.get(bucketName));
    }
}
Also used : HashMap(java.util.HashMap) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) List(java.util.List) Test(org.testng.annotations.Test)

Example 24 with TimeGranularity

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

the class DataCompletenessTaskUtilsTest method testGetAdjustedStartForDataset.

@Test
public void testGetAdjustedStartForDataset() throws Exception {
    DateTimeZone zone = DateTimeZone.forID("America/Los_Angeles");
    DateTime dateTime1 = new DateTime(2017, 01, 12, 15, 46, zone);
    // SDF, DAYS
    long startTime = dateTime1.getMillis();
    String columnName = "Date";
    TimeGranularity timeGranularity = new TimeGranularity(1, TimeUnit.DAYS);
    String timeFormat = "SIMPLE_DATE_FORMAT:yyyyMMdd";
    TimeSpec timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    long adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 0, 0, zone).getMillis());
    // EPOCH
    timeFormat = TimeSpec.SINCE_EPOCH_FORMAT;
    // HOURS
    zone = DateTimeZone.UTC;
    dateTime1 = new DateTime(2017, 01, 12, 15, 46, zone);
    startTime = dateTime1.getMillis();
    timeGranularity = new TimeGranularity(1, TimeUnit.HOURS);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 15, 0, zone).getMillis());
    // DEFAULT
    timeGranularity = new TimeGranularity(1, TimeUnit.MILLISECONDS);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 15, 0, zone).getMillis());
    // MINUTES
    timeGranularity = new TimeGranularity(5, TimeUnit.MINUTES);
    timeSpec = new TimeSpec(columnName, timeGranularity, timeFormat);
    adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 15, 30, zone).getMillis());
    DateTime dateTime2 = new DateTime(2017, 01, 12, 15, 00, zone);
    DateTime dateTime3 = new DateTime(2017, 01, 12, 15, 03, zone);
    startTime = dateTime2.getMillis();
    adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 15, 0, zone).getMillis());
    startTime = dateTime3.getMillis();
    adjustedStartTime = DataCompletenessTaskUtils.getAdjustedTimeForDataset(timeSpec, startTime, zone);
    Assert.assertEquals(adjustedStartTime, new DateTime(2017, 01, 12, 15, 0, zone).getMillis());
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) TimeSpec(com.linkedin.thirdeye.api.TimeSpec) Test(org.testng.annotations.Test)

Example 25 with TimeGranularity

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

the class TimeRangeUtils method main.

public static void main(String[] args) {
    TimeGranularity granularity = new TimeGranularity(1, TimeUnit.DAYS);
    // FAILS FOR UTC time zone
    DateTimeZone utc = DateTimeZone.forID("UTC");
    DateTime baselineStart = new DateTime(1478415600000L, utc);
    DateTime baselineEnd = new DateTime(1478678400000L, utc);
    DateTime currentStart = new DateTime(1479024000000L, utc);
    DateTime currentEnd = new DateTime(1479283200000L, utc);
    List<Range<DateTime>> currentTimeRanges = TimeRangeUtils.computeTimeRanges(granularity, currentStart, currentEnd);
    List<Range<DateTime>> baselineTimeRanges = TimeRangeUtils.computeTimeRanges(granularity, baselineStart, baselineEnd);
    System.out.println(currentTimeRanges);
    System.out.println(baselineTimeRanges);
    // WORKS FOR PST
    DateTimeZone pacificTZ = DateTimeZone.forID("America/Los_Angeles");
    baselineStart = new DateTime(1478415600000L, pacificTZ);
    baselineEnd = new DateTime(1478678400000L, pacificTZ);
    currentStart = new DateTime(1479024000000L, pacificTZ);
    currentEnd = new DateTime(1479283200000L, pacificTZ);
    currentTimeRanges = TimeRangeUtils.computeTimeRanges(granularity, currentStart, currentEnd);
    baselineTimeRanges = TimeRangeUtils.computeTimeRanges(granularity, baselineStart, baselineEnd);
    System.out.println(currentTimeRanges);
    System.out.println(baselineTimeRanges);
}
Also used : TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) Range(com.google.common.collect.Range) TimeRange(com.linkedin.thirdeye.api.TimeRange) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime)

Aggregations

TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)38 DateTime (org.joda.time.DateTime)19 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)13 ArrayList (java.util.ArrayList)13 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)9 DateTimeZone (org.joda.time.DateTimeZone)9 MetricExpression (com.linkedin.thirdeye.client.MetricExpression)8 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)7 Path (javax.ws.rs.Path)7 MetricTimeSeries (com.linkedin.thirdeye.api.MetricTimeSeries)6 ExecutionException (java.util.concurrent.ExecutionException)6 GET (javax.ws.rs.GET)5 MetricFunction (com.linkedin.thirdeye.client.MetricFunction)4 QueryCache (com.linkedin.thirdeye.client.cache.QueryCache)4 MergedAnomalyResultDTO (com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO)4 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)4 HashMap (java.util.HashMap)4 TimeUnit (java.util.concurrent.TimeUnit)4 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)4 Test (org.testng.annotations.Test)4