private static Map<String, Double> getPerMinDeltas(final StatTotals totals, final Duration duration) { final double minutes = (double)duration.getMillis() / (double)Minutes.ONE.toStandardDuration().getMillis(); final Map<String, Double> perMinDeltas = new HashMap<>(); perMinDeltas.put("0-10", totals.getAt10() / Math.min(10.0, Math.max(minutes, 0.0))); if(minutes > 10.0) { perMinDeltas.put("10-20", (totals.getAt20() - totals.getAt10()) / Math.min(10.0, minutes - 10.0)); } if(minutes > 20.0) { perMinDeltas.put("20-30", (totals.getAt30() - totals.getAt20()) / Math.min(10.0, minutes - 20.0)); } if(minutes > 30.0) { perMinDeltas.put("30-end", (totals.getAtGameEnd() - totals.getAt30()) / Math.min(10.0, minutes - 30.0)); } return perMinDeltas; }
private RepeatingTrigger(Long triggerTime, Long interval, Long delay, Integer repeatCount) { if (triggerTime != null) { this.triggerTime = getTimeSlice(triggerTime, standardMinutes(1)); } else if (interval == null && delay == null) { this.triggerTime = currentMinute().plusMinutes(1).getMillis(); } this.interval = interval; this.delay = delay == null ? Minutes.ONE.toStandardDuration().getMillis() : delay; this.repeatCount = repeatCount; this.executionCount = 1; if (this.triggerTime == null) { this.triggerTime = getTimeSlice(now.get().getMillis() + this.delay, standardMinutes(1)); } }
private void doOnTick(Action0 action) { Action0 wrapper = () -> { Date timeSlice = getTimeSlice(new DateTime(tickScheduler.now()), minutes(1).toStandardDuration()).toDate(); action.call(); }; AtomicReference<DateTime> previousTimeSliceRef = new AtomicReference<>(); // TODO Emit ticks at the start of every minute Observable.interval(0, 1, TimeUnit.MINUTES, tickScheduler) .filter(tick -> { DateTime time = currentMinute(); if (previousTimeSliceRef.get() == null) { previousTimeSliceRef.set(time); return true; } if (previousTimeSliceRef.get().equals(time)) { return false; } previousTimeSliceRef.set(time); return true; }) .takeUntil(d -> !running) .subscribe(tick -> wrapper.call(), t -> logger.warn(t)); }
public Duration getTotalDuration() { return Minutes.minutesBetween(getBeginHourMinuteSecond(), getEndHourMinuteSecond()).toStandardDuration(); }