List of usage examples for org.joda.time Interval getEnd
public DateTime getEnd()
From source file:org.opendatakit.common.android.utilities.DataUtil.java
License:Apache License
public String formatShortIntervalForUser(Interval interval) { return formatShortDateTimeForUser(interval.getStart()) + "-" + formatShortDateTimeForUser(interval.getEnd()); }
From source file:org.opendatakit.common.android.utilities.DataUtil.java
License:Apache License
public String formatLongIntervalForUser(Interval interval) { return formatLongDateTimeForUser(interval.getStart()) + " - " + formatLongDateTimeForUser(interval.getEnd()); }
From source file:org.opendatakit.tables.sms.MsgHandler.java
License:Apache License
private boolean addConstraint(Query query, ColumnProperties cp, char comparator, String value) { // TODO: do Time and DateTime get processed the same as Date??? if ((cp.getColumnType() == ColumnType.DATE_RANGE) || (cp.getColumnType() == ColumnType.DATE) || (cp.getColumnType() == ColumnType.DATETIME) || (cp.getColumnType() == ColumnType.TIME)) { Interval interval = du.tryParseInterval(value); if (interval == null) { DateTime dt = du.tryParseInstant(value); if (dt == null) { return false; }// w w w. j ava 2 s .co m String dbValue = du.formatDateTimeForDb(dt); if (comparator == '=') { if (cp.getColumnType() == ColumnType.DATE_RANGE) { return false; } query.addConstraint(cp, Query.Comparator.EQUALS, dbValue); } else if (comparator == '<') { query.addConstraint(cp, Query.Comparator.LESS_THAN, dbValue); } else if (comparator == '>') { query.addConstraint(cp, Query.Comparator.GREATER_THAN, dbValue); } else { if (cp.getColumnType() == ColumnType.DATE_RANGE) { return false; } query.addConstraint(cp, Query.Comparator.NOT_EQUALS, dbValue); } } else { if (comparator == '=') { if ((cp.getColumnType() == ColumnType.DATE) || (cp.getColumnType() == ColumnType.DATETIME) || (cp.getColumnType() == ColumnType.TIME)) { query.addConstraint(cp, Query.Comparator.GREATER_THAN_EQUALS, du.formatDateTimeForDb(interval.getStart())); query.addConstraint(cp, Query.Comparator.LESS_THAN, du.formatDateTimeForDb(interval.getEnd())); } else { query.addConstraint(cp, Query.Comparator.EQUALS, du.formatIntervalForDb(interval)); } } else if (comparator == '<') { query.addConstraint(cp, Query.Comparator.LESS_THAN, du.formatDateTimeForDb(interval.getStart())); } else if (comparator == '>') { query.addConstraint(cp, Query.Comparator.GREATER_THAN_EQUALS, du.formatDateTimeForDb(interval.getEnd())); } else { if ((cp.getColumnType() == ColumnType.DATE) || (cp.getColumnType() == ColumnType.DATETIME) || (cp.getColumnType() == ColumnType.TIME)) { query.addOrConstraint(cp, Query.Comparator.LESS_THAN, du.formatDateTimeForDb(interval.getStart()), Query.Comparator.GREATER_THAN_EQUALS, du.formatDateTimeForDb(interval.getEnd())); } else { query.addConstraint(cp, Query.Comparator.NOT_EQUALS, du.formatIntervalForDb(interval)); } } } } else { value = du.validifyValue(cp, value); if (value == null) { return false; } if (comparator == '=') { query.addConstraint(cp, Query.Comparator.EQUALS, value); } else if (comparator == '<') { query.addConstraint(cp, Query.Comparator.LESS_THAN, value); } else if (comparator == '>') { query.addConstraint(cp, Query.Comparator.GREATER_THAN, value); } else { query.addConstraint(cp, Query.Comparator.NOT_EQUALS, value); } } return true; }
From source file:org.sleuthkit.autopsy.timeline.TimeLineController.java
License:Open Source License
synchronized public void pushZoomOutTime() { final Interval timeRange = filteredEvents.timeRange().get(); long toDurationMillis = timeRange.toDurationMillis() / 4; DateTime start = timeRange.getStart().minus(toDurationMillis); DateTime end = timeRange.getEnd().plus(toDurationMillis); pushTimeRange(new Interval(start, end)); }
From source file:org.sleuthkit.autopsy.timeline.TimeLineController.java
License:Open Source License
synchronized public void pushZoomInTime() { final Interval timeRange = filteredEvents.timeRange().get(); long toDurationMillis = timeRange.toDurationMillis() / 4; DateTime start = timeRange.getStart().plus(toDurationMillis); DateTime end = timeRange.getEnd().minus(toDurationMillis); pushTimeRange(new Interval(start, end)); }
From source file:org.sleuthkit.autopsy.timeline.TimeLineTopComponent.java
License:Open Source License
/** * Get the string that should be used as the label above the result table. * It displays the time range spanned by the selected events. * * @return A String representation of all the events displayed. */// w w w .jav a 2 s . c om @NbBundle.Messages({ "# {0} - start of date range", "# {1} - end of date range", "TimeLineResultView.startDateToEndDate.text={0} to {1}" }) private String getResultViewerSummaryString() { Interval selectedTimeRange = controller.getSelectedTimeRange(); if (selectedTimeRange == null) { return ""; } else { final DateTimeFormatter zonedFormatter = TimeLineController.getZonedFormatter(); String start = selectedTimeRange.getStart().withZone(TimeLineController.getJodaTimeZone()) .toString(zonedFormatter); String end = selectedTimeRange.getEnd().withZone(TimeLineController.getJodaTimeZone()) .toString(zonedFormatter); return Bundle.TimeLineResultView_startDateToEndDate_text(start, end); } }
From source file:org.sleuthkit.autopsy.timeline.ui.countsview.CountsViewPane.java
License:Open Source License
@Override protected Task<Boolean> getUpdateTask() { return new LoggedTask<Boolean>(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.name"), true) {/* w ww . ja v a2 s. c om*/ @Override protected Boolean call() throws Exception { if (isCancelled()) { return null; } updateProgress(-1, 1); updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.prepUpdate")); Platform.runLater(() -> { setCursor(Cursor.WAIT); }); final RangeDivisionInfo rangeInfo = RangeDivisionInfo .getRangeDivisionInfo(filteredEvents.timeRange().get()); chart.setRangeInfo(rangeInfo); //extend range to block bounderies (ie day, month, year) final long lowerBound = rangeInfo.getLowerBound(); final long upperBound = rangeInfo.getUpperBound(); final Interval timeRange = new Interval( new DateTime(lowerBound, TimeLineController.getJodaTimeZone()), new DateTime(upperBound, TimeLineController.getJodaTimeZone())); int max = 0; int p = 0; // progress counter //clear old data, and reset ranges and series Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.resetUI")); eventTypeMap.clear(); dataSets.clear(); dateAxis.getCategories().clear(); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { //add bar/'category' label for the current interval final String dateString = start.toString(rangeInfo.getTickFormatter()); dateAxis.getCategories().add(dateString); //increment for next iteration start = start.plus(rangeInfo.getPeriodSize().getPeriod()); } //make all series to ensure they get created in consistent order EventType.allTypes.forEach(CountsViewPane.this::getSeries); }); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { final String dateString = start.toString(rangeInfo.getTickFormatter()); DateTime end = start.plus(rangeInfo.getPeriodSize().getPeriod()); final Interval interval = new Interval(start, end); //query for current range Map<EventType, Long> eventCounts = filteredEvents.getEventCounts(interval); //increment for next iteration start = end; int dateMax = 0; //used in max tracking //for each type add data to graph for (final EventType et : eventCounts.keySet()) { if (isCancelled()) { return null; } final Long count = eventCounts.get(et); final int fp = p++; if (count > 0) { final double adjustedCount = count == 0 ? 0 : scale.get().adjust(count); dateMax += adjustedCount; final XYChart.Data<String, Number> xyData = new BarChart.Data<>(dateString, adjustedCount); xyData.nodeProperty().addListener((Observable o) -> { final Node node = xyData.getNode(); if (node != null) { node.setStyle("-fx-border-width: 2; -fx-border-color: " + ColorUtilities.getRGBCode(et.getSuperType().getColor()) + "; -fx-bar-fill: " + ColorUtilities.getRGBCode(et.getColor())); // NON-NLS node.setCursor(Cursor.HAND); node.setOnMouseEntered((MouseEvent event) -> { //defer tooltip creation till needed, this had a surprisingly large impact on speed of loading the chart final Tooltip tooltip = new Tooltip( NbBundle.getMessage(this.getClass(), "CountsViewPane.tooltip.text", count, et.getDisplayName(), dateString, interval.getEnd().toString(rangeInfo.getTickFormatter()))); tooltip.setGraphic(new ImageView(et.getFXImage())); Tooltip.install(node, tooltip); node.setEffect(new DropShadow(10, et.getColor())); }); node.setOnMouseExited((MouseEvent event) -> { if (selectedNodes.contains(node)) { node.setEffect(SELECTED_NODE_EFFECT); } else { node.setEffect(null); } }); node.addEventHandler(MouseEvent.MOUSE_CLICKED, new BarClickHandler(node, dateString, interval, et)); } }); max = Math.max(max, dateMax); final double fmax = max; Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.updatingCounts")); getSeries(et).getData().add(xyData); if (scale.get().equals(ScaleType.LINEAR)) { countAxis.setTickUnit( Math.pow(10, Math.max(0, Math.floor(Math.log10(fmax)) - 1))); } else { countAxis.setTickUnit(Double.MAX_VALUE); } countAxis.setUpperBound(1 + fmax * 1.2); layoutDateLabels(); updateProgress(fp, rangeInfo.getPeriodsInRange()); }); } else { final double fmax = max; Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.updatingCounts")); updateProgress(fp, rangeInfo.getPeriodsInRange()); }); } } } Platform.runLater(() -> { updateMessage(NbBundle.getMessage(this.getClass(), "CountsViewPane.loggedTask.wrappingUp")); updateProgress(1, 1); layoutDateLabels(); setCursor(Cursor.NONE); }); return max > 0; } }; }
From source file:org.sleuthkit.autopsy.timeline.utils.RangeDivisionInfo.java
License:Open Source License
/** * Static factory method.//from w ww . ja v a2s. c o m * * Determine the period size, number of periods, whole period bounds, and * formatters to use to visualize the given timerange. * * @param timeRange * * @return */ public static RangeDivisionInfo getRangeDivisionInfo(Interval timeRange) { //Check from largest to smallest unit //TODO: make this more generic... reduce code duplication -jm DateTimeFieldType timeUnit; final DateTime startWithZone = timeRange.getStart().withZone(TimeLineController.getJodaTimeZone()); final DateTime endWithZone = timeRange.getEnd().withZone(TimeLineController.getJodaTimeZone()); if (Years.yearsIn(timeRange).isGreaterThan(Years.THREE)) { timeUnit = DateTimeFieldType.year(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Years.yearsIn(timeRange).get(timeUnit.getDurationType()) + 1, TimeUnits.YEARS, ISODateTimeFormat.year(), lower, upper); } else if (Months.monthsIn(timeRange).isGreaterThan(Months.THREE)) { timeUnit = DateTimeFieldType.monthOfYear(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Months.monthsIn(timeRange).getMonths() + 1, TimeUnits.MONTHS, DateTimeFormat.forPattern("YYYY'-'MMMM"), lower, upper); // NON-NLS } else if (Days.daysIn(timeRange).isGreaterThan(Days.THREE)) { timeUnit = DateTimeFieldType.dayOfMonth(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Days.daysIn(timeRange).getDays() + 1, TimeUnits.DAYS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd"), lower, upper); // NON-NLS } else if (Hours.hoursIn(timeRange).isGreaterThan(Hours.THREE)) { timeUnit = DateTimeFieldType.hourOfDay(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Hours.hoursIn(timeRange).getHours() + 1, TimeUnits.HOURS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH"), lower, upper); // NON-NLS } else if (Minutes.minutesIn(timeRange).isGreaterThan(Minutes.THREE)) { timeUnit = DateTimeFieldType.minuteOfHour(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Minutes.minutesIn(timeRange).getMinutes() + 1, TimeUnits.MINUTES, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm"), lower, upper); // NON-NLS } else { timeUnit = DateTimeFieldType.secondOfMinute(); long lower = startWithZone.property(timeUnit).roundFloorCopy().getMillis(); long upper = endWithZone.property(timeUnit).roundCeilingCopy().getMillis(); return new RangeDivisionInfo(timeRange, Seconds.secondsIn(timeRange).getSeconds() + 1, TimeUnits.SECONDS, DateTimeFormat.forPattern("YYYY'-'MMMM'-'dd HH':'mm':'ss"), lower, upper); // NON-NLS } }
From source file:org.springframework.analytics.metrics.memory.InMemoryAggregateCounter.java
License:Apache License
public AggregateCounter getCounts(Interval interval, AggregateCounterResolution resolution) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCounterResolution.minute) { List<long[]> days = accumulateDayCounts(minuteCountsByDay, start, end, 60 * 24); counts = MetricUtils.concatArrays(days, interval.getStart().getMinuteOfDay(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCounterResolution.hour) { List<long[]> days = accumulateDayCounts(hourCountsByDay, start, end, 24); counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCounterResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(start.getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> yearDays = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis())); while (cursor.isBefore(endYear)) { long[] dayCounts = dayCountsByYear.get(cursor.getYear()); if (dayCounts == null) { // Querying where we have no data dayCounts = new long[daysInYear(cursor.getYear())]; }/* w w w . j ava 2 s . com*/ yearDays.add(dayCounts); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(yearDays, startDay.getDayOfYear() - 1, nDays); } else if (resolution == AggregateCounterResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> yearMonths = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis())); while (cursor.isBefore(endYear)) { long[] monthCounts = monthCountsByYear.get(cursor.getYear()); if (monthCounts == null) { monthCounts = new long[12]; } yearMonths.add(monthCounts); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(yearMonths, startMonth.getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCounterResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { long[] monthCounts = monthCountsByYear.get(startYear.plusYears(i).getYear()); counts[i] = MetricUtils.sum(monthCounts); } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCounter(this.name, interval, counts, resolution); }
From source file:org.springframework.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
/** * For each query, we need to convert the interval into two variations. One is the start and end points rounded to * the resolution (used to calculate the number of entries to be returned from the query). The second is the start * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the * start day as the start index into the first array, and writing the total number of entries in sequence from that * point into the combined result counts array. *///from w w w .j a v a 2s. c o m @Override public AggregateCounter getCounts(String name, Interval interval, AggregateCounterResolution resolution) { DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCounterResolution.minute) { // Iterate through each hour in the interval and load the minutes for it MutableDateTime dt = new MutableDateTime(interval.getStart()); dt.setRounding(c.hourOfDay()); Duration step = Duration.standardHours(1); List<long[]> hours = new ArrayList<long[]>(); while (dt.isBefore(end) || dt.isEqual(end)) { hours.add(getMinCountsForHour(name, dt)); dt.add(step); } counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCounterResolution.hour) { DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis())); List<long[]> days = new ArrayList<long[]>(); Duration step = Duration.standardHours(24); while (cursor.isBefore(end)) { days.add(getHourCountsForDay(name, cursor)); cursor = cursor.plus(step); } counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCounterResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis())); List<long[]> months = new ArrayList<long[]>(); DateTime endMonth = new DateTime( c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis())); while (cursor.isBefore(endMonth)) { months.add(getDayCountsForMonth(name, cursor)); cursor = cursor.plusMonths(1); } counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays); } else if (resolution == AggregateCounterResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> years = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis())); while (cursor.isBefore(endYear)) { years.add(getMonthCountsForYear(name, cursor)); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCounterResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); Map<String, Long> yearCounts = getYearCounts(name); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { int year = startYear.plusYears(i).getYear(); Long count = yearCounts.get(Integer.toString(year)); if (count == null) { count = 0L; } counts[i] = count; } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCounter(name, interval, counts, resolution); }