@Test public void testIsDriftPeriodLongEnough() throws Exception { final long t0 = System.currentTimeMillis(); final long t1 = t0 + driftAnalysis.OBSERVATION_PERIOD_MINUTES*60*1000; final long dt = 7000; System.out.println("Testing normally moving, non-drifting track"); Track track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 45.0f, 12.0f, 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing track moving in observed speed interval, but not drifting"); track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing track moving in normal speed, but cog/hdg deviation indicates drift"); track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), -45.0f, (float) (driftAnalysis.SPEED_HIGH_MARK + 0.5), 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing track moving below observed speed interval and not drifting"); track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 45.0f, (float) (driftAnalysis.SPEED_LOW_MARK - 0.5), 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing track drifting, but not drifting for long enough"); track = new Track(219000001); for (long t = t0; t < t1-60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } for (long t = t1-60000+1000; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), -45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing track drifting, but eventually getting out of drift"); track = new Track(219000001); for (long t = t0; t < t1-60000; t += dt) { track.update(t, Position.create(56.0, 12.0), -45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } for (long t = t1-60000+1000; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } assertFalse(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing drifting track 1"); track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), -45.0f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } assertTrue(driftAnalysis.isDriftPeriodLongEnough(track)); System.out.println("Testing drifting track 2"); track = new Track(219000001); for (long t = t0; t < t1+60000; t += dt) { track.update(t, Position.create(56.0, 12.0), 353.3f, (float) (driftAnalysis.SPEED_LOW_MARK + 0.5), 45.1f); } assertTrue(driftAnalysis.isDriftPeriodLongEnough(track)); }
boolean isDriftPeriodLongEnough(Track track) { final long t1 = track.getNewestTrackingReport().getTimestamp() - OBSERVATION_PERIOD_MINUTES*60*1000; return track.getTrackingReports() .stream() .filter(tr -> tr.getTimestamp() >= t1) .allMatch(tr -> isDrifting(tr)); }
DriftAnalysis extends Analysis { boolean isDriftPeriodLongEnough(Track track) { final long t1 = track.getNewestTrackingReport().getTimestamp() - OBSERVATION_PERIOD_MINUTES*60*1000; return track.getTrackingReports() .stream() .filter(tr -> tr.getTimestamp() >= t1) .allMatch(tr -> isDrifting(tr)); } }
DriftAnalysis extends Analysis { boolean isDriftPeriodLongEnough(Track track) { final long t1 = track.getNewestTrackingReport().getTimestamp() - OBSERVATION_PERIOD_MINUTES*60*1000; return track.getTrackingReports() .stream() .filter(tr -> tr.getTimestamp() >= t1) .allMatch(tr -> isDrifting(tr)); } @Inject  DriftAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); }
DriftAnalysis extends Analysis { boolean isDriftPeriodLongEnough(Track track) { final long t1 = track.getNewestTrackingReport().getTimestamp() - OBSERVATION_PERIOD_MINUTES*60*1000; return track.getTrackingReports() .stream() .filter(tr -> tr.getTimestamp() >= t1) .allMatch(tr -> isDrifting(tr)); } @Inject  DriftAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); @Override String toString(); @AllowConcurrentEvents @Subscribe void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent); }
DriftAnalysis extends Analysis { boolean isDriftPeriodLongEnough(Track track) { final long t1 = track.getNewestTrackingReport().getTimestamp() - OBSERVATION_PERIOD_MINUTES*60*1000; return track.getTrackingReports() .stream() .filter(tr -> tr.getTimestamp() >= t1) .allMatch(tr -> isDrifting(tr)); } @Inject  DriftAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); @Override String toString(); @AllowConcurrentEvents @Subscribe void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent);  }