List of usage examples for org.joda.time Interval toDuration
public Duration toDuration()
From source file:au.id.hazelwood.xmltvguidebuilder.postprocessor.ListingVerifier.java
License:Apache License
public void verifyListing(ChannelListings listings, DateTime from, DateTime to, DateTime subsetTo) { Duration listingDurationTotal = new Interval(from, to).toDuration(); Duration listingDurationSubset = new Interval(from, subsetTo).toDuration(); LOGGER.info(repeat("-", 100)); for (ChannelDetail channelDetail : listings.getChannels()) { Duration missingDurationTotal = Duration.ZERO; Duration missingDurationSubset = Duration.ZERO; StringBuilder allMissingIntervalDetails = new StringBuilder(); for (Interval missing : findMissingIntervals(listings, from, to, channelDetail.getId())) { missingDurationTotal = missingDurationTotal.plus(missing.toDuration()); if (missing.getStart().isBefore(subsetTo)) { if (missing.getEnd().isBefore(subsetTo)) { missingDurationSubset = missingDurationSubset.plus(missing.toDuration()); } else { missingDurationSubset = missingDurationSubset .plus(new Duration(missing.getStart(), subsetTo)); }//from w w w . ja v a 2s .co m } allMissingIntervalDetails.append(allMissingIntervalDetails.length() == 0 ? "missing " : ", "); allMissingIntervalDetails.append( format("{0}-{1}", toISODateTime(missing.getStart()), toISODateTime(missing.getEnd()))); } Duration availableDurationTotal = listingDurationTotal.minus(missingDurationTotal); Duration availableDurationSubset = listingDurationSubset.minus(missingDurationSubset); Integer availablePercentageTotal = getPercentage(availableDurationTotal, listingDurationTotal); Integer availablePercentageSubset = getPercentage(availableDurationSubset, listingDurationSubset); LOGGER.info("{} {} [{}|{}] {}", rightPad(channelDetail.getId() + " - " + channelDetail.getName(), 42), formatDurationDHM(availableDurationTotal.getMillis()), leftPad(availablePercentageSubset + "%", 4), leftPad(availablePercentageTotal + "%", 4), allMissingIntervalDetails.toString()); } LOGGER.info(repeat("-", 100)); }
From source file:com.almende.dsol.example.datacenters.Datacenter.java
License:Apache License
protected void newAdaption(final Interval interval, final double consumptionFactor) throws RemoteException, SimRuntimeException { if (consumptionFactor > 1.0) this.outsourceSchedule.put(interval.getStart(), interval); else if (consumptionFactor < 1.0) this.insourceSchedule.put(interval.getStart(), interval); final double startTime = simTime(interval.getStart()); final double endTime = simTime(interval.getEnd()); this.adaptionHours.addValue(DsolUtil.toTimeUnit(TimeUnitInterface.HOUR, interval.toDuration().getMillis(), TimeUnitInterface.MILLISECOND)); getSimulator().scheduleEvent(new SimEvent(startTime, this, this, APPLY_CONSUMPTION_FACTOR_METHOD_ID, new Object[] { consumptionFactor, false })); getSimulator().scheduleEvent(new SimEvent(endTime, this, this, APPLY_CONSUMPTION_FACTOR_METHOD_ID, new Object[] { 1.0 / consumptionFactor, true })); }
From source file:com.floreantpos.swing.TimerWatch.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { Interval interval = new Interval(date.getTime(), new Instant().getMillis()); Duration duration = interval.toDuration(); int timeOutValueYellow = 300; int timeOutValueRed = 600; if (AppConfig.getString("YellowTimeOut") != null) { timeOutValueYellow = Integer.parseInt(AppConfig.getString("YellowTimeOut")); //$NON-NLS-1$ }/*from w w w . j a v a 2s. c o m*/ if (AppConfig.getString("RedTimeOut") != null) { timeOutValueRed = Integer.parseInt(AppConfig.getString("RedTimeOut")); //$NON-NLS-1$ } if (timeOutValueYellow < duration.getStandardSeconds() && timeOutValueRed > duration.getStandardSeconds()) { backColor = Color.yellow; textColor = Color.black; } else if (timeOutValueRed < duration.getStandardSeconds()) { backColor = Color.red; textColor = Color.white; } else { backColor = Color.white; textColor = Color.black; } timerLabel.setText(duration.getStandardHours() + ":" + (duration.getStandardMinutes() % 60) + ":" //$NON-NLS-1$//$NON-NLS-2$ + (duration.getStandardSeconds() % 60)); }
From source file:com.hamdikavak.humanmobility.modeling.helpers.LocationTraceHelper.java
License:Open Source License
/** * Cleans traces that shared within a sort period of time from the same place * @param traces list of traces. location id of traces has to be set. * @param duration threshold length to identify repeated consequent traces * @return a list of cleaned traces.// w ww.ja v a 2 s . c o m */ public List<ExtendedLocationTrace> cleanRepeatedTraces(List<ExtendedLocationTrace> traces, Duration duration) { // check whether we have enough number of traces if (traces == null || traces.size() < 2) { return traces; } // at this point, we have at least two traces Iterator<ExtendedLocationTrace> traceIterator = traces.iterator(); ExtendedLocationTrace firstTrace = traceIterator.next(); // auto-assign first trace ExtendedLocationTrace secondTrace = null; // to be assigned while (traceIterator.hasNext()) { // get the next item secondTrace = traceIterator.next(); DateTime firstDate = firstTrace.getUTCTime(); DateTime secondDate = secondTrace.getUTCTime(); // calculate time interval between the two Interval interval = new Interval(firstDate, secondDate); // the following if statement checks whether both traces report the same place // and their inter-event duration is shorter than our threshold duration if (firstTrace.getLocationId() == secondTrace.getLocationId() && interval.toDuration().isShorterThan(duration)) { // this means the user reported his/her location shortly after one another. // we delete this record. traceIterator.remove(); } else { // this means, didn't report from the same location within a certain time after the first report. firstTrace = secondTrace; } } return traces; }
From source file:com.hamdikavak.humanmobility.modeling.helpers.LocationTraceHelper.java
License:Open Source License
/** * // www . ja v a 2s .co m * Cleans traces that are shared within a given sort period of time from a * given nearby location distance. This method is different from * {@code LocationTraceHelper.cleanRepeatedTraces} method in a way that this * doesn't require pre-assigned location ids to traces. * * @param traces list of traces. * @param distance threshold spatial distance to identify repeated consequent traces * @param duration threshold length to identify repeated consequent traces * @return a list of cleaned traces. */ public List<ExtendedLocationTrace> cleanRepeatedTracesByDistance(List<ExtendedLocationTrace> traces, DistanceWithUnit distance, Duration duration) { // check whether we have enough number of traces if (traces == null || traces.size() < 2) { return traces; } // at this point, we have at least two traces Iterator<ExtendedLocationTrace> traceIterator = traces.iterator(); ExtendedLocationTrace firstTrace = traceIterator.next(); // auto-assign first trace ExtendedLocationTrace secondTrace = null; // to be assigned while (traceIterator.hasNext()) { // get the next item secondTrace = traceIterator.next(); DateTime firstDate = firstTrace.getUTCTime(); DateTime secondDate = secondTrace.getUTCTime(); // calculate time interval between the two Interval interval = new Interval(firstDate, secondDate); // the following if statement checks whether both traces report within a short distance // and their inter-event duration is shorter than our threshold duration double calculatedDistance = spatialOperation.calculateDistance(firstTrace.getCoordinate(), secondTrace.getCoordinate(), SpatialDistanceUnit.Meter); DistanceWithUnit calculatedDistanceObject = new DistanceWithUnit(calculatedDistance, SpatialDistanceUnit.Meter); if (calculatedDistanceObject.isShortherThan(distance) && interval.toDuration().isShorterThan(duration)) { // this means the user reported his/her location shortly after one another. // we delete this record. traceIterator.remove(); } else { // this means, didn't report from the same location within a certain time after the first report. firstTrace = secondTrace; } } return traces; }
From source file:com.metamx.druid.BaseQuery.java
License:Open Source License
@Override public Duration getDuration() { if (duration == null) { Duration totalDuration = new Duration(0); for (Interval interval : querySegmentSpec.getIntervals()) { if (interval != null) { totalDuration = totalDuration.plus(interval.toDuration()); }// w ww .j a va 2 s . c o m } duration = totalDuration; } return duration; }
From source file:com.smoketurner.pipeline.application.aws.AmazonSNSNotification.java
License:Apache License
@JsonIgnore public Duration getDelayDuration() { final Interval interval = new Interval(timestamp, DateTime.now(DateTimeZone.UTC)); return interval.toDuration(); }
From source file:com.tmathmeyer.sentinel.models.data.Event.java
License:Open Source License
@Override public void setTime(DateTime newTime) { if (new Interval(new DateTime(this.start), new DateTime(this.end)).contains(newTime)) { // this is what stops the events from being dragged to the next day. // leaving it in case we might want it later // return; }/* w w w . j a v a2 s.c om*/ Interval i; int daysBetween = 0; if (new DateTime(this.start).isAfter(newTime)) { i = new Interval(newTime, new DateTime(this.start)); daysBetween = 0 - (int) i.toDuration().getStandardDays(); } else { i = new Interval(new DateTime(this.start), newTime); daysBetween = (int) i.toDuration().getStandardDays(); } MutableDateTime newEnd = new MutableDateTime(this.end); newEnd.addDays(daysBetween); MutableDateTime newStart = new MutableDateTime(this.start); newStart.addDays(daysBetween); this.end = newEnd.toDate(); this.start = newStart.toDate(); }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Selects an event's corresponding Displayable * // w w w. ja v a 2s . com * @param on Event being selected * @param setTo Displayable of Event being selected */ private void selectEvents(Event on, Displayable setTo) { // TODO: refactor this pattern DayPanel mLouvreTour; MutableDateTime startDay = new MutableDateTime(on.getStart()); MutableDateTime endDay = new MutableDateTime(on.getEnd()); endDay.setMillisOfDay(0); endDay.addDays(1); endDay.addMillis(-1); startDay.setMillisOfDay(0); Interval eventLength = new Interval(startDay, endDay); if (setTo == null || eventLength.toDuration().getStandardHours() > 24) { for (WeekMultidayEventItem multidayItem : multidayItemList) { if (setTo != null && multidayItem.getEvent().getUuid().equals(((Event) on).getUuid())) multidayItem.setSelected(true); else multidayItem.setSelected(false); } return; } // TODO: can be simplified now that multiday events are handled // elsewhere int index = 0; for (int i = 0; i < 7; i++) { if (startDay.getDayOfYear() == daysOfWeekArray[i].getDisplayDate().getDayOfYear()) { index = i; break; } } while (index < 7 && !endDay.isBefore(daysOfWeekArray[index].getDisplayDate())) { mLouvreTour = daysOfWeekArray[index]; try { mLouvreTour.select(setTo); } catch (NullPointerException ex) { // silently ignore as this is apparently not in the view } index++; } }
From source file:com.tmathmeyer.sentinel.ui.views.week.WeekCalendar.java
License:Open Source License
/** * Gets the multiday events in the scope of the week * /*from ww w . ja v a 2 s. c o m*/ * @return list of multiday events */ private List<Event> getMultidayEvents() { List<Event> retrievedEvents = new ArrayList<>(); for (Displayable d : displayableList) { if (!(d instanceof Event)) continue; DateTime intervalStart = d.getStart(); DateTime intervalEnd = d.getEnd(); Interval mInterval = new Interval(intervalStart, intervalEnd); if (mInterval.toDuration().getStandardHours() > 24) retrievedEvents.add(((Event) d)); } return retrievedEvents; }