@Test public void abnormalSOGWhenShipCountAboveThreshold() { statistics = SpeedOverGroundStatisticData.create(); statistics.setValue((short) 0, (short) 0, (short) 0, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 1, (short) 0, (short) 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 1, (short) 1, (short) 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 1, (short) 2, (short) 0, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 0, (short) 0, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 0, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 2, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 3, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 4, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 3, (short) 5, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1000); statistics.setValue((short) 2, (short) 4, (short) 0, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 4, (short) 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); statistics.setValue((short) 2, (short) 4, (short) 2, SpeedOverGroundStatisticData.STAT_SHIP_COUNT, 1); final int sum = statistics.getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); final int n1 = statistics.getValue(2, 4, 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT); final int n2 = statistics.getValue(2, 3, 5, SpeedOverGroundStatisticData.STAT_SHIP_COUNT); final float pd1 = (float) n1 / (float) sum; final float pd2 = (float) n2 / (float) sum; assertTrue(sum > configuration.getInt(CONFKEY_ANALYSIS_SOG_CELL_SHIPCOUNT_MIN)); assertEquals(configuration.getFloat(CONFKEY_ANALYSIS_SOG_PD), 0.001, 1e-6); assertTrue(pd1 < 0.001); assertTrue(pd2 > 0.001); context.checking(new Expectations() {{ oneOf(behaviourManager).registerSubscriber(with(any(SpeedOverGroundAnalysis.class))); }}); final SpeedOverGroundAnalysis analysis = new SpeedOverGroundAnalysis(configuration, statisticsService, statisticsRepository, trackingService, eventRepository, behaviourManager); context.checking(new Expectations() {{ ignoring(statisticsService).incAnalysisStatistics(with("SpeedOverGroundAnalysis"), with(any(String.class))); oneOf(statisticsRepository).getStatisticData("SpeedOverGroundStatistic", 123456L); will(returnValue(statistics)); }}); assertNotNull(statistics.getValue(2, 4, 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT)); assertTrue(analysis.isAbnormalSpeedOverGround(123456L, 2, 4, 1)); context.checking(new Expectations() {{ ignoring(statisticsService).incAnalysisStatistics(with("SpeedOverGroundAnalysis"), with(any(String.class))); oneOf(statisticsRepository).getStatisticData("SpeedOverGroundStatistic", 123456L); will(returnValue(statistics)); }}); assertNull(statistics.getValue(1, 3, 1, SpeedOverGroundStatisticData.STAT_SHIP_COUNT)); assertTrue(analysis.isAbnormalSpeedOverGround(123456L, 1, 3, 1)); context.checking(new Expectations() {{ ignoring(statisticsService).incAnalysisStatistics(with("SpeedOverGroundAnalysis"), with(any(String.class))); oneOf(statisticsRepository).getStatisticData("SpeedOverGroundStatistic", 123456L); will(returnValue(statistics)); }}); assertFalse(analysis.isAbnormalSpeedOverGround(123456L, 2, 3, 5)); }
boolean isAbnormalSpeedOverGround(Long cellId, int shipTypeKey, int shipSizeKey, int speedOverGroundKey) { float pd = 1.0f; StatisticData speedOverGroundStatisticData = getStatisticDataRepository().getStatisticData("SpeedOverGroundStatistic", cellId); if (speedOverGroundStatisticData instanceof SpeedOverGroundStatisticData) { Integer totalCount = ((SpeedOverGroundStatisticData) speedOverGroundStatisticData).getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { int shipCount = calculateShipCount((SpeedOverGroundStatisticData) speedOverGroundStatisticData, shipTypeKey, shipSizeKey, speedOverGroundKey); pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", sog=" + speedOverGroundKey + ", shipCount=" + shipCount + ", totalCount=" + totalCount + ", pd=" + pd); } else { LOG.debug("totalCount of " + totalCount + " is not enough statistical data for cell " + cellId); } } LOG.debug("pd = " + pd); boolean isAbnormalSpeedOverGround = pd < PD; if (isAbnormalSpeedOverGround) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalSpeedOverGround; }
SpeedOverGroundAnalysis extends StatisticBasedAnalysis { boolean isAbnormalSpeedOverGround(Long cellId, int shipTypeKey, int shipSizeKey, int speedOverGroundKey) { float pd = 1.0f; StatisticData speedOverGroundStatisticData = getStatisticDataRepository().getStatisticData("SpeedOverGroundStatistic", cellId); if (speedOverGroundStatisticData instanceof SpeedOverGroundStatisticData) { Integer totalCount = ((SpeedOverGroundStatisticData) speedOverGroundStatisticData).getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { int shipCount = calculateShipCount((SpeedOverGroundStatisticData) speedOverGroundStatisticData, shipTypeKey, shipSizeKey, speedOverGroundKey); pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", sog=" + speedOverGroundKey + ", shipCount=" + shipCount + ", totalCount=" + totalCount + ", pd=" + pd); } else { LOG.debug("totalCount of " + totalCount + " is not enough statistical data for cell " + cellId); } } LOG.debug("pd = " + pd); boolean isAbnormalSpeedOverGround = pd < PD; if (isAbnormalSpeedOverGround) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalSpeedOverGround; } }
SpeedOverGroundAnalysis extends StatisticBasedAnalysis { boolean isAbnormalSpeedOverGround(Long cellId, int shipTypeKey, int shipSizeKey, int speedOverGroundKey) { float pd = 1.0f; StatisticData speedOverGroundStatisticData = getStatisticDataRepository().getStatisticData("SpeedOverGroundStatistic", cellId); if (speedOverGroundStatisticData instanceof SpeedOverGroundStatisticData) { Integer totalCount = ((SpeedOverGroundStatisticData) speedOverGroundStatisticData).getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { int shipCount = calculateShipCount((SpeedOverGroundStatisticData) speedOverGroundStatisticData, shipTypeKey, shipSizeKey, speedOverGroundKey); pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", sog=" + speedOverGroundKey + ", shipCount=" + shipCount + ", totalCount=" + totalCount + ", pd=" + pd); } else { LOG.debug("totalCount of " + totalCount + " is not enough statistical data for cell " + cellId); } } LOG.debug("pd = " + pd); boolean isAbnormalSpeedOverGround = pd < PD; if (isAbnormalSpeedOverGround) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalSpeedOverGround; } @Inject  SpeedOverGroundAnalysis(Configuration configuration, AppStatisticsService statisticsService, StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService, EventRepository eventRepository, BehaviourManager behaviourManager); }
SpeedOverGroundAnalysis extends StatisticBasedAnalysis { boolean isAbnormalSpeedOverGround(Long cellId, int shipTypeKey, int shipSizeKey, int speedOverGroundKey) { float pd = 1.0f; StatisticData speedOverGroundStatisticData = getStatisticDataRepository().getStatisticData("SpeedOverGroundStatistic", cellId); if (speedOverGroundStatisticData instanceof SpeedOverGroundStatisticData) { Integer totalCount = ((SpeedOverGroundStatisticData) speedOverGroundStatisticData).getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { int shipCount = calculateShipCount((SpeedOverGroundStatisticData) speedOverGroundStatisticData, shipTypeKey, shipSizeKey, speedOverGroundKey); pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", sog=" + speedOverGroundKey + ", shipCount=" + shipCount + ", totalCount=" + totalCount + ", pd=" + pd); } else { LOG.debug("totalCount of " + totalCount + " is not enough statistical data for cell " + cellId); } } LOG.debug("pd = " + pd); boolean isAbnormalSpeedOverGround = pd < PD; if (isAbnormalSpeedOverGround) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalSpeedOverGround; } @Inject  SpeedOverGroundAnalysis(Configuration configuration, AppStatisticsService statisticsService, StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService, EventRepository eventRepository, BehaviourManager behaviourManager); @Override String toString(); @AllowConcurrentEvents @Subscribe void onCellIdChanged(CellChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent); @Subscribe void onAbnormalEventRaise(AbnormalEventRaise behaviourEvent); @Subscribe void onAbnormalEventMaintain(AbnormalEventMaintain behaviourEvent); @Subscribe void onAbnormalEventLower(AbnormalEventLower behaviourEvent); }
SpeedOverGroundAnalysis extends StatisticBasedAnalysis { boolean isAbnormalSpeedOverGround(Long cellId, int shipTypeKey, int shipSizeKey, int speedOverGroundKey) { float pd = 1.0f; StatisticData speedOverGroundStatisticData = getStatisticDataRepository().getStatisticData("SpeedOverGroundStatistic", cellId); if (speedOverGroundStatisticData instanceof SpeedOverGroundStatisticData) { Integer totalCount = ((SpeedOverGroundStatisticData) speedOverGroundStatisticData).getSumFor(SpeedOverGroundStatisticData.STAT_SHIP_COUNT); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { int shipCount = calculateShipCount((SpeedOverGroundStatisticData) speedOverGroundStatisticData, shipTypeKey, shipSizeKey, speedOverGroundKey); pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", sog=" + speedOverGroundKey + ", shipCount=" + shipCount + ", totalCount=" + totalCount + ", pd=" + pd); } else { LOG.debug("totalCount of " + totalCount + " is not enough statistical data for cell " + cellId); } } LOG.debug("pd = " + pd); boolean isAbnormalSpeedOverGround = pd < PD; if (isAbnormalSpeedOverGround) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalSpeedOverGround; } @Inject  SpeedOverGroundAnalysis(Configuration configuration, AppStatisticsService statisticsService, StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService, EventRepository eventRepository, BehaviourManager behaviourManager); @Override String toString(); @AllowConcurrentEvents @Subscribe void onCellIdChanged(CellChangedEvent trackEvent); @AllowConcurrentEvents @Subscribe void onTrackStale(TrackStaleEvent trackEvent); @Subscribe void onAbnormalEventRaise(AbnormalEventRaise behaviourEvent); @Subscribe void onAbnormalEventMaintain(AbnormalEventMaintain behaviourEvent); @Subscribe void onAbnormalEventLower(AbnormalEventLower behaviourEvent);  }