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();
}
Aggregations