List of usage examples for org.joda.time Interval getStart
public DateTime getStart()
From source file:org.opendatakit.tables.data.DataUtil.java
License:Apache License
private String validifyDateTimeValue(String input) { DateTime instant = tryParseInstant(input); if (instant != null) { return formatDateTimeForDb(instant); }/*from w w w . j a v a 2 s . com*/ Interval interval = tryParseInterval(input); if (interval != null) { return formatDateTimeForDb(interval.getStart()); } return null; }
From source file:org.opendatakit.tables.data.DataUtil.java
License:Apache License
private String validifyTimeValue(String input) { // TODO: does this need to be different? // Need to respect TimeZone. What should Date be? DateTime instant = tryParseInstant(input); if (instant != null) { return formatDateTimeForDb(instant); }/*from w w w . j av a 2 s . com*/ Interval interval = tryParseInterval(input); if (interval != null) { return formatDateTimeForDb(interval.getStart()); } return null; }
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; }//from w ww .j a va 2 s . c o 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.db.EventDB.java
License:Open Source License
/** * merge the events in the given list if they are within the same period * General algorithm is as follows:/* ww w . j a v a 2s. co m*/ * * 1) sort them into a map from (type, description)-> List<aggevent> * 2) for each key in map, merge the events and accumulate them in a list to * return * * @param timeUnitLength * @param preMergedEvents * * @return */ static private List<EventStripe> mergeClustersToStripes(Period timeUnitLength, List<EventCluster> preMergedEvents) { //effectively map from type to (map from description to events) Map<EventType, SetMultimap<String, EventCluster>> typeMap = new HashMap<>(); for (EventCluster aggregateEvent : preMergedEvents) { typeMap.computeIfAbsent(aggregateEvent.getEventType(), eventType -> HashMultimap.create()) .put(aggregateEvent.getDescription(), aggregateEvent); } //result list to return ArrayList<EventCluster> aggEvents = new ArrayList<>(); //For each (type, description) key, merge agg events for (SetMultimap<String, EventCluster> descrMap : typeMap.values()) { //for each description ... for (String descr : descrMap.keySet()) { //run through the sorted events, merging together adjacent events Iterator<EventCluster> iterator = descrMap.get(descr).stream() .sorted(Comparator.comparing(event -> event.getSpan().getStartMillis())).iterator(); EventCluster current = iterator.next(); while (iterator.hasNext()) { EventCluster next = iterator.next(); Interval gap = current.getSpan().gap(next.getSpan()); //if they overlap or gap is less one quarter timeUnitLength //TODO: 1/4 factor is arbitrary. review! -jm if (gap == null || gap.toDuration() .getMillis() <= timeUnitLength.toDurationFrom(gap.getStart()).getMillis() / 4) { //merge them current = EventCluster.merge(current, next); } else { //done merging into current, set next as new current aggEvents.add(current); current = next; } } aggEvents.add(current); } } //merge clusters to stripes Map<ImmutablePair<EventType, String>, EventStripe> stripeDescMap = new HashMap<>(); for (EventCluster eventCluster : aggEvents) { stripeDescMap.merge(ImmutablePair.of(eventCluster.getEventType(), eventCluster.getDescription()), new EventStripe(eventCluster), EventStripe::merge); } return stripeDescMap.values().stream().sorted(Comparator.comparing(EventStripe::getStartMillis)) .collect(Collectors.toList()); }
From source file:org.sleuthkit.autopsy.timeline.events.db.EventDB.java
License:Open Source License
/** * //TODO: update javadoc //TODO: split this into helper methods * * get a list of {@link AggregateEvent}s. * * General algorithm is as follows:// w ww. j a v a 2 s. co m * * - get all aggregate events, via one db query. * - sort them into a map from (type, description)-> aggevent * - for each key in map, merge the events and accumulate them in a list * to return * * * @param timeRange the Interval within in which all returned aggregate * events will be. * @param filter only events that pass the filter will be included in * aggregates events returned * @param zoomLevel only events of this level will be included * @param lod description level of detail to use when grouping events * * * @return a list of aggregate events within the given timerange, that pass * the supplied filter, aggregated according to the given event type and * description zoom levels */ private List<AggregateEvent> getAggregatedEvents(Interval timeRange, Filter filter, EventTypeZoomLevel zoomLevel, DescriptionLOD lod) { String descriptionColumn = getDescriptionColumn(lod); final boolean useSubTypes = (zoomLevel.equals(EventTypeZoomLevel.SUB_TYPE)); //get some info about the time range requested RangeDivisionInfo rangeInfo = RangeDivisionInfo.getRangeDivisionInfo(timeRange); //use 'rounded out' range long start = timeRange.getStartMillis() / 1000;//.getLowerBound(); long end = timeRange.getEndMillis() / 1000;//Millis();//rangeInfo.getUpperBound(); if (Objects.equals(start, end)) { end++; } //get a sqlite srtftime format string String strfTimeFormat = getStrfTimeFormat(rangeInfo.getPeriodSize()); //effectively map from type to (map from description to events) Map<EventType, SetMultimap<String, AggregateEvent>> typeMap = new HashMap<>(); //get all agregate events in this time unit dbReadLock(); String query = "select strftime('" + strfTimeFormat + "',time , 'unixepoch'" + (TimeLineController.getTimeZone().get().equals(TimeZone.getDefault()) ? ", 'localtime'" : "") + ") as interval, group_concat(event_id) as event_ids, Min(time), Max(time), " + descriptionColumn + ", " + (useSubTypes ? SUB_TYPE_COLUMN : BASE_TYPE_COLUMN) // NON-NLS + " from events where time >= " + start + " and time < " + end + " and " + getSQLWhere(filter) // NON-NLS + " group by interval, " + (useSubTypes ? SUB_TYPE_COLUMN : BASE_TYPE_COLUMN) + " , " + descriptionColumn // NON-NLS + " order by Min(time)"; // NON-NLS //System.out.println(query); ResultSet rs = null; try (Statement stmt = con.createStatement(); // scoop up requested events in groups organized by interval, type, and desription ) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); rs = stmt.executeQuery(query); stopwatch.stop(); //System.out.println(stopwatch.elapsedMillis() / 1000.0 + " seconds"); while (rs.next()) { EventType type = useSubTypes ? RootEventType.allTypes.get(rs.getInt(SUB_TYPE_COLUMN)) : BaseTypes.values()[rs.getInt(BASE_TYPE_COLUMN)]; AggregateEvent aggregateEvent = new AggregateEvent( new Interval(rs.getLong("Min(time)") * 1000, rs.getLong("Max(time)") * 1000, TimeLineController.getJodaTimeZone()), // NON-NLS type, Arrays.asList(rs.getString("event_ids").split(",")), // NON-NLS rs.getString(descriptionColumn), lod); //put events in map from type/descrition -> event SetMultimap<String, AggregateEvent> descrMap = typeMap.get(type); if (descrMap == null) { descrMap = HashMultimap.<String, AggregateEvent>create(); typeMap.put(type, descrMap); } descrMap.put(aggregateEvent.getDescription(), aggregateEvent); } } catch (SQLException ex) { Exceptions.printStackTrace(ex); } finally { try { rs.close(); } catch (SQLException ex) { Exceptions.printStackTrace(ex); } dbReadUnlock(); } //result list to return ArrayList<AggregateEvent> aggEvents = new ArrayList<>(); //save this for use when comparing gap size Period timeUnitLength = rangeInfo.getPeriodSize().getPeriod(); //For each (type, description) key, merge agg events for (SetMultimap<String, AggregateEvent> descrMap : typeMap.values()) { for (String descr : descrMap.keySet()) { //run through the sorted events, merging together adjacent events Iterator<AggregateEvent> iterator = descrMap.get(descr).stream() .sorted((AggregateEvent o1, AggregateEvent o2) -> Long .compare(o1.getSpan().getStartMillis(), o2.getSpan().getStartMillis())) .iterator(); AggregateEvent current = iterator.next(); while (iterator.hasNext()) { AggregateEvent next = iterator.next(); Interval gap = current.getSpan().gap(next.getSpan()); //if they overlap or gap is less one quarter timeUnitLength //TODO: 1/4 factor is arbitrary. review! -jm if (gap == null || gap.toDuration() .getMillis() <= timeUnitLength.toDurationFrom(gap.getStart()).getMillis() / 4) { //merge them current = AggregateEvent.merge(current, next); } else { //done merging into current, set next as new current aggEvents.add(current); current = next; } } aggEvents.add(current); } } //at this point we should have a list of aggregate events. //one per type/description spanning consecutive time units as determined in rangeInfo return aggEvents; }
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. *//*from w w w . j a v a2 s . c o m*/ @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) {// www . j av a 2 s .com @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.ui.ViewFrame.java
License:Open Source License
/** * Refresh the Histogram to represent the current state of the DB. *//*from w w w. j a v a2 s . co m*/ @NbBundle.Messages({ "ViewFrame.histogramTask.title=Rebuilding Histogram", "ViewFrame.histogramTask.preparing=Preparing", "ViewFrame.histogramTask.resetUI=Resetting UI", "ViewFrame.histogramTask.queryDb=Querying FB", "ViewFrame.histogramTask.updateUI2=Updating UI" }) synchronized private void refreshHistorgram() { if (histogramTask != null) { histogramTask.cancel(true); } histogramTask = new LoggedTask<Void>(Bundle.ViewFrame_histogramTask_title(), true) { private final Lighting lighting = new Lighting(); @Override protected Void call() throws Exception { updateMessage(ViewFrame_histogramTask_preparing()); long max = 0; final RangeDivisionInfo rangeInfo = RangeDivisionInfo .getRangeDivisionInfo(filteredEvents.getSpanningInterval()); final long lowerBound = rangeInfo.getLowerBound(); final long upperBound = rangeInfo.getUpperBound(); Interval timeRange = new Interval(new DateTime(lowerBound, TimeLineController.getJodaTimeZone()), new DateTime(upperBound, TimeLineController.getJodaTimeZone())); //extend range to block bounderies (ie day, month, year) int p = 0; // progress counter //clear old data, and reset ranges and series Platform.runLater(() -> { updateMessage(ViewFrame_histogramTask_resetUI()); }); ArrayList<Long> bins = new ArrayList<>(); DateTime start = timeRange.getStart(); while (timeRange.contains(start)) { if (isCancelled()) { return null; } DateTime end = start.plus(rangeInfo.getPeriodSize().getPeriod()); final Interval interval = new Interval(start, end); //increment for next iteration start = end; updateMessage(ViewFrame_histogramTask_queryDb()); //query for current range long count = filteredEvents.getEventCounts(interval).values().stream().mapToLong(Long::valueOf) .sum(); bins.add(count); max = Math.max(count, max); final double fMax = Math.log(max); final ArrayList<Long> fbins = new ArrayList<>(bins); Platform.runLater(() -> { updateMessage(ViewFrame_histogramTask_updateUI2()); histogramBox.getChildren().clear(); for (Long bin : fbins) { if (isCancelled()) { break; } Region bar = new Region(); //scale them to fit in histogram height bar.prefHeightProperty() .bind(histogramBox.heightProperty().multiply(Math.log(bin)).divide(fMax)); bar.setMaxHeight(USE_PREF_SIZE); bar.setMinHeight(USE_PREF_SIZE); bar.setBackground(GRAY_BACKGROUND); bar.setOnMouseEntered((MouseEvent event) -> { Tooltip.install(bar, new Tooltip(bin.toString())); }); bar.setEffect(lighting); //they each get equal width to fill the histogram horizontally HBox.setHgrow(bar, Priority.ALWAYS); histogramBox.getChildren().add(bar); } }); } return null; } }; new Thread(histogramTask).start(); controller.monitorTask(histogramTask); }