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

The following examples show how to use org.joda.time.Interval#getStartMillis() . 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: 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 4
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 5
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 6
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 7
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 getStartYMD(Interval interval) {
    long startTime = interval.getStartMillis();
    return startTime == Long.MIN_VALUE ? null : new YearMonthDay(startTime);
}
 
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 Interval intervalWithEnd(Interval originalInterval, YearMonthDay day) {
    long millis = day.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();
    return new Interval(originalInterval.getStartMillis(), millis);
}
 
Example 9
Source File: IntervalTools.java    From fenixedu-academic with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Interval intervalWithEnd(Interval interval, Date date) {
    long millis = date == null ? Long.MAX_VALUE : date.getTime();
    return new Interval(interval.getStartMillis(), millis);
}