/** * Are notifications enabled for the given notification type, the given check statue and a point * in time * * @param type the notification type * @param status the status of the check * @param time the time * @return true if notifications are enabled */ public boolean isEnabledAt(NotificationType type, Status status, Calendar time) { TimePeriod timePeriod = this.getTimePeriod(); return this.enabled && this.isNotificationTypeEnabled(type) && (!this.isStatusIgnored(status)) && (timePeriod == null ? true : timePeriod.isInTimeRange(time)) && (this.allEnginesEnabled || this.getEngines().stream().anyMatch((e) -> e.isEnabledAt(type, status, time))); }
/** * Returns the x-value for a time period. * * @param period the time period. * @return The x-value. */ private long getX(TimePeriod period) { if (this.xPosition == TimePeriodAnchor.START) { return period.getStart().getTime(); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { return period.getStart().getTime() / 2 + period.getEnd().getTime() / 2; } else if (this.xPosition == TimePeriodAnchor.END) { return period.getEnd().getTime(); } else { throw new IllegalStateException("TimePeriodAnchor unknown."); } }
/** * Returns the x-value for a time period. * * @param period the time period. * @return The x-value. */ private long getXValue(TimePeriod period) { long result = 0L; if (this.xPosition == TimePeriodAnchor.START) { result = period.getStart().getTime(); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { long t0 = period.getStart().getTime(); long t1 = period.getEnd().getTime(); result = t0 + (t1 - t0) / 2L; } else if (this.xPosition == TimePeriodAnchor.END) { result = period.getEnd().getTime(); } return result; }
/** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that controls whether or not the x-intervals are taken into * account. * @return The range. */ public Range getDomainBounds(boolean includeInterval) { List keys = this.values.getRowKeys(); if (keys.isEmpty()) { return null; } TimePeriod first = (TimePeriod) keys.get(0); TimePeriod last = (TimePeriod) keys.get(keys.size() - 1); if (!includeInterval || this.domainIsPointsInTime) { return new Range(getXValue(first), getXValue(last)); } else { return new Range(first.getStart().getTime(), last.getEnd().getTime()); } }
/** * find the best collection to use as a time-base. Which collection has the most values within * the specified time period? * * @param period * @param items * @return most suited collection */ public IBaseTemporalCollection getOptimalTimes( TimePeriod period, Collection<ICollection> items) { IBaseTemporalCollection res = null; long resScore = 0; Iterator<ICollection> iter = items.iterator(); while (iter.hasNext()) { ICollection iCollection = (ICollection) iter.next(); if (iCollection.isTemporal()) { IBaseTemporalCollection timeC = (IBaseTemporalCollection) iCollection; Iterator<Long> times = timeC.getTimes().iterator(); int score = 0; while (times.hasNext()) { long long1 = (long) times.next(); if (period.contains(long1)) { score++; } } if ((res == null) || (score > resScore)) { res = timeC; resScore = score; } } } return res; }
public TimePeriod getBoundingTime(final Collection<ICollection> items) { TimePeriod res = null; Iterator<ICollection> iter = items.iterator(); while (iter.hasNext()) { ICollection iCollection = (ICollection) iter.next(); if (iCollection.isTemporal()) { IBaseTemporalCollection timeC = (IBaseTemporalCollection) iCollection; if (res == null) { res = new TimePeriod(timeC.start(), timeC.finish()); } else { res.startTime = Math.max(res.startTime, timeC.start()); res.endTime = Math.min(res.endTime, timeC.finish()); } } } return res; }
/** * Returns the end x-value (as a double primitive) for an item within a series. * * @param series the series index (zero-based). * @param item the item index (zero-based). * @return The value. */ public double getEndXValue(int series, int item) { TimePeriod period = (TimePeriod) this.values.getRowKey(item); return period.getEnd().getTime(); }
/** * Update the index values for the maximum and minimum bounds. * * @param period the time period. * @param index the index of the time period. */ private void updateBounds(TimePeriod period, int index) { long start = period.getStart().getTime(); long end = period.getEnd().getTime(); long middle = start + ((end - start) / 2); if (this.minStartIndex >= 0) { long minStart = getDataItem(this.minStartIndex).getPeriod().getStart().getTime(); if (start < minStart) { this.minStartIndex = index; } } else { this.minStartIndex = index; } if (this.maxStartIndex >= 0) { long maxStart = getDataItem(this.maxStartIndex).getPeriod().getStart().getTime(); if (start > maxStart) { this.maxStartIndex = index; } } else { this.maxStartIndex = index; } if (this.minMiddleIndex >= 0) { long s = getDataItem(this.minMiddleIndex).getPeriod().getStart().getTime(); long e = getDataItem(this.minMiddleIndex).getPeriod().getEnd().getTime(); long minMiddle = s + (e - s) / 2; if (middle < minMiddle) { this.minMiddleIndex = index; } } else { this.minMiddleIndex = index; } if (this.maxMiddleIndex >= 0) { long s = getDataItem(this.maxMiddleIndex).getPeriod().getStart().getTime(); long e = getDataItem(this.maxMiddleIndex).getPeriod().getEnd().getTime(); long maxMiddle = s + (e - s) / 2; if (middle > maxMiddle) { this.maxMiddleIndex = index; } } else { this.maxMiddleIndex = index; } if (this.minEndIndex >= 0) { long minEnd = getDataItem(this.minEndIndex).getPeriod().getEnd().getTime(); if (end < minEnd) { this.minEndIndex = index; } } else { this.minEndIndex = index; } if (this.maxEndIndex >= 0) { long maxEnd = getDataItem(this.maxEndIndex).getPeriod().getEnd().getTime(); if (end > maxEnd) { this.maxEndIndex = index; } } else { this.maxEndIndex = index; } }
@Test public void testDurationInMillis() { assertThat(TimePeriod.builder().startMillis(50).endMillis(75).create().durationInMillis()) .isEqualTo(25); }
@Test public void testIsValidWhenEndIsBeforeStart() { assertThat(TimePeriod.builder().startMillis(100).endMillis(50).create().isValid()).isFalse(); }
@Test public void testIsValid() { assertThat(TimePeriod.builder().startMillis(50).endMillis(100).create().isValid()).isTrue(); }
@Test public void testContainsWhenTimeIsBeforeStart() { assertThat(TimePeriod.builder().startMillis(50).endMillis(100).create().contains(25)).isFalse(); }
@Test public void testContains() { assertThat(TimePeriod.builder().startMillis(50).endMillis(100).create().contains(75)).isTrue(); }
/** * wrap the actual operation. We're doing this since we need to separate it from the core * "execute" operation in order to support dynamic updates * * @param unit * @param outputs */ private void performCalc(List<IStoreItem> outputs) { // and the bounding period TimePeriod period = getBoundingTime(data.values()); // check it's valid if (period.invalid()) { System.err.println("Insufficient coverage for datasets"); return; } // ok, let's start by finding our time sync IBaseTemporalCollection times = getOptimalTimes(period, data.values()); // check we were able to find some times if (times == null) { System.err.println("Unable to find time source dataset"); return; } // get the output dataset final Temporal.Frequency_Hz output = (Frequency_Hz) outputs.iterator().next(); final GeodeticCalculator calc = GeoSupport.getCalculator(); // and now we can start looping through Iterator<Long> tIter = times.getTimes().iterator(); while (tIter.hasNext()) { long thisTime = (long) tIter.next(); if ((thisTime >= period.startTime) && (thisTime <= period.endTime)) { // ok, now collate our data Geometry txLoc = locationFor(data.get(TX + "LOC"), thisTime); Geometry rxLoc = locationFor(data.get(RX + "LOC"), thisTime); double txCourseRads = valueAt(data.get(TX + "COURSE"), thisTime, SI.RADIAN); double rxCourseRads = valueAt(data.get(RX + "COURSE"), thisTime, SI.RADIAN); double txSpeedMSec = valueAt(data.get(TX + "SPEED"), thisTime, SI.METERS_PER_SECOND); double rxSpeedMSec = valueAt(data.get(RX + "SPEED"), thisTime, SI.METERS_PER_SECOND); double freq = valueAt(data.get(TX + "FREQ"), thisTime, SI.HERTZ); double soundSpeed = valueAt(data.get("SOUND_SPEED"), thisTime, SI.METERS_PER_SECOND); // now find the bearing between them calc.setStartingGeographicPoint( txLoc.getCentroid().getOrdinate(0), txLoc.getCentroid().getOrdinate(1)); calc.setDestinationGeographicPoint( rxLoc.getCentroid().getOrdinate(0), rxLoc.getCentroid().getOrdinate(1)); double angleDegs = calc.getAzimuth(); if (angleDegs < 0) angleDegs += 360; double angleRads = Math.toRadians(angleDegs); // ok, and the calculation double shifted = calcPredictedFreqSI( soundSpeed, txCourseRads, rxCourseRads, txSpeedMSec, rxSpeedMSec, angleRads, freq); output.add(thisTime, shifted); } } }
/** * Returns the range of the values in this dataset's domain. * * @param includeInterval a flag that determines whether or not the x-interval is taken into * account. * @return The range. */ @Override public Range getDomainBounds(boolean includeInterval) { boolean interval = includeInterval || this.domainIsPointsInTime; Range result = null; Range temp = null; Iterator iterator = this.data.iterator(); while (iterator.hasNext()) { TimePeriodValues series = (TimePeriodValues) iterator.next(); int count = series.getItemCount(); if (count > 0) { TimePeriod start = series.getTimePeriod(series.getMinStartIndex()); TimePeriod end = series.getTimePeriod(series.getMaxEndIndex()); if (!interval) { if (this.xPosition == TimePeriodAnchor.START) { TimePeriod maxStart = series.getTimePeriod(series.getMaxStartIndex()); temp = new Range(start.getStart().getTime(), maxStart.getStart().getTime()); } else if (this.xPosition == TimePeriodAnchor.MIDDLE) { TimePeriod minMiddle = series.getTimePeriod(series.getMinMiddleIndex()); long s1 = minMiddle.getStart().getTime(); long e1 = minMiddle.getEnd().getTime(); TimePeriod maxMiddle = series.getTimePeriod(series.getMaxMiddleIndex()); long s2 = maxMiddle.getStart().getTime(); long e2 = maxMiddle.getEnd().getTime(); temp = new Range(s1 + (e1 - s1) / 2, s2 + (e2 - s2) / 2); } else if (this.xPosition == TimePeriodAnchor.END) { TimePeriod minEnd = series.getTimePeriod(series.getMinEndIndex()); temp = new Range(minEnd.getEnd().getTime(), end.getEnd().getTime()); } } else { temp = new Range(start.getStart().getTime(), end.getEnd().getTime()); } result = Range.combine(result, temp); } } return result; }
public static TimePeriod getCustom(long seconds) { TimePeriod custom = TimePeriod.CUSTOM; custom.seconds = seconds; return custom; }