@Test public void eventIsRaisedForSuddenSpeedChange() { final ArgumentCaptor<SuddenSpeedChangeEvent> eventCaptor = ArgumentCaptor.forClass(SuddenSpeedChangeEvent.class); context.checking(new Expectations() {{ exactly(2).of(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); oneOf(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.start(); int deltaSecs = 7; PositionChangedEvent event = new PositionChangedEvent(track, null); track.update(track.getTimeOfLastPositionReport() + (deltaSecs + 0) * 1000, Position.create(56, 12), 45.0f, 12.2f, 45.0f); analysis.onSpeedOverGroundUpdated(event); for (int i=0; i<8; i++) { track.update(track.getTimeOfLastPositionReport() + (deltaSecs + 1) * 1000, Position.create(56, 12), 45.0f, 0.1f, 45.0f); analysis.onSpeedOverGroundUpdated(event); } SuddenSpeedChangeEvent capturedEvent = eventCaptor.getCapturedObject(); assertEquals("SuddenSpeedChangeEvent", capturedEvent.getEventType()); assertEquals(219000606, capturedEvent.getBehaviour(track.getMmsi()).getVessel().getMmsi()); assertTrue(capturedEvent.getStartTime().isBefore(capturedEvent.getEndTime())); assertEquals(2, capturedEvent.getBehaviour(track.getMmsi()).getTrackingPoints().size()); assertEquals(12.2, capturedEvent.getBehaviour(track.getMmsi()).getTrackingPoints().first().getSpeedOverGround(), 1e-6); assertEquals(0.1, capturedEvent.getBehaviour(track.getMmsi()).getTrackingPoints().last().getSpeedOverGround(), 1e-6); context.assertIsSatisfied(); }
@AllowConcurrentEvents @Subscribe public void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent) { Track track = trackEvent.getTrack(); Integer vesselLength = track.getVesselLength(); if (vesselLength != null && vesselLength < SHIP_LENGTH_MIN) { statisticsService.incAnalysisStatistics(getAnalysisName(), "LOA < " + SHIP_LENGTH_MIN); return; } if (!isSpeedOverGroundAvailable(track.getSpeedOverGround())) { return; } if (isClassB.test(track) || isUnknownTypeOrSize.test(track) || isFishingVessel.test(track) || isSpecialCraft.test(track) || isEngagedInTowing.test(track) ) { return; } if (isLastAisTrackingReportTooOld(track, track.getTimeOfLastPositionReport())) { LOG.debug("Skipping analysis: MMSI " + track.getMmsi() + " was predicted for too long."); return; } if (isVeryLongVessel.test(track) || (isCargoVessel.test(track) || isTankerVessel.test(track) || isPassengerVessel.test(track))) { performAnalysis(track); updateApplicationStatistics(); } }
SuddenSpeedChangeAnalysis extends Analysis { @AllowConcurrentEvents @Subscribe public void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent) { Track track = trackEvent.getTrack(); Integer vesselLength = track.getVesselLength(); if (vesselLength != null && vesselLength < SHIP_LENGTH_MIN) { statisticsService.incAnalysisStatistics(getAnalysisName(), "LOA < " + SHIP_LENGTH_MIN); return; } if (!isSpeedOverGroundAvailable(track.getSpeedOverGround())) { return; } if (isClassB.test(track) || isUnknownTypeOrSize.test(track) || isFishingVessel.test(track) || isSpecialCraft.test(track) || isEngagedInTowing.test(track) ) { return; } if (isLastAisTrackingReportTooOld(track, track.getTimeOfLastPositionReport())) { LOG.debug("Skipping analysis: MMSI " + track.getMmsi() + " was predicted for too long."); return; } if (isVeryLongVessel.test(track) || (isCargoVessel.test(track) || isTankerVessel.test(track) || isPassengerVessel.test(track))) { performAnalysis(track); updateApplicationStatistics(); } } }
SuddenSpeedChangeAnalysis extends Analysis { @AllowConcurrentEvents @Subscribe public void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent) { Track track = trackEvent.getTrack(); Integer vesselLength = track.getVesselLength(); if (vesselLength != null && vesselLength < SHIP_LENGTH_MIN) { statisticsService.incAnalysisStatistics(getAnalysisName(), "LOA < " + SHIP_LENGTH_MIN); return; } if (!isSpeedOverGroundAvailable(track.getSpeedOverGround())) { return; } if (isClassB.test(track) || isUnknownTypeOrSize.test(track) || isFishingVessel.test(track) || isSpecialCraft.test(track) || isEngagedInTowing.test(track) ) { return; } if (isLastAisTrackingReportTooOld(track, track.getTimeOfLastPositionReport())) { LOG.debug("Skipping analysis: MMSI " + track.getMmsi() + " was predicted for too long."); return; } if (isVeryLongVessel.test(track) || (isCargoVessel.test(track) || isTankerVessel.test(track) || isPassengerVessel.test(track))) { performAnalysis(track); updateApplicationStatistics(); } } @Inject  SuddenSpeedChangeAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); }
SuddenSpeedChangeAnalysis extends Analysis { @AllowConcurrentEvents @Subscribe public void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent) { Track track = trackEvent.getTrack(); Integer vesselLength = track.getVesselLength(); if (vesselLength != null && vesselLength < SHIP_LENGTH_MIN) { statisticsService.incAnalysisStatistics(getAnalysisName(), "LOA < " + SHIP_LENGTH_MIN); return; } if (!isSpeedOverGroundAvailable(track.getSpeedOverGround())) { return; } if (isClassB.test(track) || isUnknownTypeOrSize.test(track) || isFishingVessel.test(track) || isSpecialCraft.test(track) || isEngagedInTowing.test(track) ) { return; } if (isLastAisTrackingReportTooOld(track, track.getTimeOfLastPositionReport())) { LOG.debug("Skipping analysis: MMSI " + track.getMmsi() + " was predicted for too long."); return; } if (isVeryLongVessel.test(track) || (isCargoVessel.test(track) || isTankerVessel.test(track) || isPassengerVessel.test(track))) { performAnalysis(track); updateApplicationStatistics(); } } @Inject  SuddenSpeedChangeAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); @Override String toString(); @AllowConcurrentEvents @Subscribe void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent); }
SuddenSpeedChangeAnalysis extends Analysis { @AllowConcurrentEvents @Subscribe public void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent) { Track track = trackEvent.getTrack(); Integer vesselLength = track.getVesselLength(); if (vesselLength != null && vesselLength < SHIP_LENGTH_MIN) { statisticsService.incAnalysisStatistics(getAnalysisName(), "LOA < " + SHIP_LENGTH_MIN); return; } if (!isSpeedOverGroundAvailable(track.getSpeedOverGround())) { return; } if (isClassB.test(track) || isUnknownTypeOrSize.test(track) || isFishingVessel.test(track) || isSpecialCraft.test(track) || isEngagedInTowing.test(track) ) { return; } if (isLastAisTrackingReportTooOld(track, track.getTimeOfLastPositionReport())) { LOG.debug("Skipping analysis: MMSI " + track.getMmsi() + " was predicted for too long."); return; } if (isVeryLongVessel.test(track) || (isCargoVessel.test(track) || isTankerVessel.test(track) || isPassengerVessel.test(track))) { performAnalysis(track); updateApplicationStatistics(); } } @Inject  SuddenSpeedChangeAnalysis(Configuration configuration, AppStatisticsService statisticsService, EventEmittingTracker trackingService, EventRepository eventRepository); @Override String toString(); @AllowConcurrentEvents @Subscribe void onSpeedOverGroundUpdated(PositionChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent);  }