Java Code Examples for org.joda.time.Interval#getEndMillis()

The following examples show how to use org.joda.time.Interval#getEndMillis() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OfflineSegmentIntervalChecker.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Computes the number of missing segments based on the given existing segment intervals and the expected frequency
 * of the intervals.
 * <p>We count the interval as missing if there are at least two intervals between the start of the previous interval
 * and current interval. For long intervals (span over multiple intervals), count its start time as the start time of
 * the last interval it covers.
 *
 * @param segmentIntervals List of existing segment intervals
 * @param frequency Expected interval frequency
 * @return Number of missing segments
 */
@VisibleForTesting
static int computeNumMissingSegments(List<Interval> segmentIntervals, Duration frequency) {
  int numSegments = segmentIntervals.size();

  // If there are less than two segments, none can be missing
  if (numSegments < 2) {
    return 0;
  }

  // Sort the intervals by ascending starting time
  segmentIntervals.sort(Comparator.comparingLong(BaseInterval::getStartMillis));

  int numMissingSegments = 0;
  long frequencyMs = frequency.getMillis();
  long lastStartTimeMs = -1L;
  for (Interval segmentInterval : segmentIntervals) {
    long startTimeMs = segmentInterval.getStartMillis();
    if (lastStartTimeMs != -1L && startTimeMs - lastStartTimeMs > frequencyMs) {
      // If there are at least two intervals between the start of the previous interval and current interval, then
      // count the interval(s) as missing
      numMissingSegments += (startTimeMs - lastStartTimeMs - frequencyMs) / frequencyMs;
    }
    // Handle long intervals
    long endTimeMs = segmentInterval.getEndMillis();
    while (startTimeMs + frequencyMs <= endTimeMs) {
      startTimeMs += frequencyMs;
    }
    lastStartTimeMs = Math.max(lastStartTimeMs, startTimeMs);
  }
  return numMissingSegments;
}
 
Example 2
Source File: BackwardAnomalyFunctionUtils.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static List<Pair<Long, Long>> toBackwardCompatibleDataRanges(
    List<Interval> timeSeriesIntervals) {
  List<Pair<Long, Long>> dataRanges = new ArrayList<>();
  for (Interval interval : timeSeriesIntervals) {
    Pair<Long, Long> dataRange = new Pair<>(interval.getStartMillis(), interval.getEndMillis());
    dataRanges.add(dataRange);
  }
  return dataRanges;
}
 
Example 3
Source File: ThresholdRuleDetector.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
@Override
public DetectionResult runDetection(Interval window, String metricUrn) {
  MetricEntity me = MetricEntity.fromURN(metricUrn);
  Long endTime = window.getEndMillis();
  MetricSlice slice = MetricSlice.from(me.getId(), window.getStartMillis(), endTime, me.getFilters(), timeGranularity);

  InputData data = this.dataFetcher.fetchData(
      new InputDataSpec().withTimeseriesSlices(Collections.singletonList(slice))
          .withMetricIdsForDataset(Collections.singletonList(me.getId())));
  DataFrame df = data.getTimeseries().get(slice).renameSeries(COL_VALUE, COL_CURRENT);

  // defaults
  df.addSeries(COL_TOO_HIGH, BooleanSeries.fillValues(df.size(), false));
  df.addSeries(COL_TOO_LOW, BooleanSeries.fillValues(df.size(), false));

  // max
  if (!Double.isNaN(this.max)) {
    df.addSeries(COL_TOO_HIGH, df.getDoubles(COL_CURRENT).gt(this.max));
  }

  // min
  if (!Double.isNaN(this.min)) {
    df.addSeries(COL_TOO_LOW, df.getDoubles(COL_CURRENT).lt(this.min));
  }
  df.mapInPlace(BooleanSeries.HAS_TRUE, COL_ANOMALY, COL_TOO_HIGH, COL_TOO_LOW);
  DatasetConfigDTO datasetConfig = data.getDatasetForMetricId().get(me.getId());
  List<MergedAnomalyResultDTO> anomalies = DetectionUtils.makeAnomalies(slice, df, COL_ANOMALY, endTime,
      DetectionUtils.getMonitoringGranularityPeriod(monitoringGranularity, datasetConfig), datasetConfig);
  DataFrame baselineWithBoundaries = constructBaselineAndBoundaries(df);

  return DetectionResult.from(anomalies, TimeSeries.fromDataFrame(baselineWithBoundaries));
}
 
Example 4
Source File: IntervalUtils.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * turns a list of intervals into a string.
 * Ex. [1-5, 6-6, 9-15] -> "{1-5, 6, 9-15}"
 * @param intervals
 * @return string form of interval list
 */
public static String getIntervalRangesAsString(List<Interval> intervals) {
  if (intervals.isEmpty()) {
    return "";
  }

  StringBuilder sb = new StringBuilder("{");

  for (Interval interval : intervals) {
    long start = interval.getStartMillis();
    long end = interval.getEndMillis();

    // we check using >= because times may not be 100% perfectly aligned due to boundary shifting misalignment.
    if (start >= end) {
      sb.append(start);
    } else {
      sb.append(start);
      sb.append("-");
      sb.append(end);
    }
    sb.append(", ");
  }

  // delete the last "," and " " characters.
  // StringBuilder start is inclusive, end is exclusive.
  sb.delete(sb.length() - 2, sb.length());
  sb.append("}");

  return sb.toString();
}
 
Example 5
Source File: DataService.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
protected DesignOptions createDesignOptions(UndesignedParameterSet parameterSet,
                                            ArrayList<TimeseriesProperties> props,
                                            boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    DesignOptions designOptions = new DesignOptions(props, begin, end, renderGrid);
    if (parameterSet.getResultTime() != null) {
        Instant resultTime = Instant.parse(parameterSet.getResultTime());
        designOptions.setResultTime(resultTime.getMillis());
    }
    return designOptions;
}
 
Example 6
Source File: DataService.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
protected DesignOptions createDesignOptions(ParameterSet parameterSet,
                                            ArrayList<TimeseriesProperties> props,
                                            boolean renderGrid) {
    Interval timespan = Interval.parse(parameterSet.getTimespan());
    long begin = timespan.getStartMillis();
    long end = timespan.getEndMillis();
    return new DesignOptions(props, begin, end, renderGrid);
}
 
Example 7
Source File: TimeUtils.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
/**
 * Given a time interval, returns true if the interval is between a valid range, false otherwise.
 * <p>The current valid range used is between beginning of 1971 and beginning of 2071.
 */
public static boolean isValidTimeInterval(Interval timeInterval) {
  return timeInterval.getStartMillis() >= VALID_MIN_TIME_MILLIS
      && timeInterval.getEndMillis() <= VALID_MAX_TIME_MILLIS;
}
 
Example 8
Source File: IntervalTools.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Deprecated
public static YearMonthDay getEndYMD(Interval interval) {
    long endTime = interval.getEndMillis();
    return endTime == Long.MAX_VALUE ? null : new YearMonthDay(endTime);
}
 
Example 9
Source File: IntervalTools.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Deprecated
public static Interval intervalWithStart(Interval originalInterval, YearMonthDay day) {
    long millis = day.toDateMidnight().getMillis();
    return new Interval(millis, originalInterval.getEndMillis());
}
 
Example 10
Source File: IntervalTools.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Interval intervalWithStart(Interval interval, Date date) {
    long millis = date == null ? Long.MIN_VALUE : date.getTime();
    return new Interval(millis, interval.getEndMillis());
}