@Test public void eventIsRaisedForSuddenSpeedChangeSpanningSeveralMessages() { final ArgumentCaptor<SuddenSpeedChangeEvent> eventCaptor = ArgumentCaptor.forClass(SuddenSpeedChangeEvent.class); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.start(); int deltaSecs = 10; track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 13.9f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 13.3f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 11.7f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 8.3f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 5.0f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 1.9f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); for (int i=0; i<6; i++) { track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 0.0f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); never(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); } track.update(track.getTimeOfLastPositionReport() + deltaSecs * 1000, Position.create(56, 12), 45.0f, 0.2f, 45.0f); context.checking(new Expectations() {{ ignoring(eventRepository).findOngoingEventByVessel(219000606, SuddenSpeedChangeEvent.class); oneOf(eventRepository).save(with(eventCaptor.getMatcher())); }}); analysis.onSpeedOverGroundUpdated(new PositionChangedEvent(track, null)); context.assertIsSatisfied(); 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()); }
@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);  }