@Test public void normalWhereHighShipCountStatistics() { Integer totalCount = statistics1.getSumFor("shipCount"); Integer count = statistics1.getValue((short) 2, (short) 3, "shipCount"); float pd = (float) count / (float) totalCount; assertTrue(pd > 0.001); final ArgumentCaptor<Analysis> analysisCaptor = ArgumentCaptor.forClass(Analysis.class); context.checking(new Expectations() {{ oneOf(behaviourManager).registerSubscriber(with(any(ShipTypeAndSizeAnalysis.class))); oneOf(trackingService).registerSubscriber(with(analysisCaptor.getMatcher())); oneOf(statisticsRepository).getStatisticData("ShipTypeAndSizeStatistic", testCellId); will(returnValue(statistics1)); ignoring(statisticsService).incAnalysisStatistics(with(ShipTypeAndSizeAnalysis.class.getSimpleName()), with(any(String.class))); }}); final ShipTypeAndSizeAnalysis analysis = new ShipTypeAndSizeAnalysis(configuration, statisticsService, statisticsRepository, trackingService, eventRepository, behaviourManager); analysis.start(); boolean isAbnormalEvent = analysis.isAbnormalCellForShipTypeAndSize(testCellId, (short) 2, (short) 3); context.assertIsSatisfied(); assertEquals(analysis, analysisCaptor.getCapturedObject()); assertFalse(isAbnormalEvent); }
boolean isAbnormalCellForShipTypeAndSize(Long cellId, int shipTypeKey, int shipSizeKey) { float pd = 1.0f; StatisticData shipSizeAndTypeData = getStatisticDataRepository().getStatisticData("ShipTypeAndSizeStatistic", cellId); if (shipSizeAndTypeData instanceof ShipTypeAndSizeStatisticData) { Integer totalCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getSumFor("shipCount"); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { Integer shipCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getValue(shipTypeKey, shipSizeKey, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT); if (shipCount == null) { shipCount = 0; } pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", 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 isAbnormalCellForShipTypeAndSize = pd < PD; if (isAbnormalCellForShipTypeAndSize) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalCellForShipTypeAndSize; }
ShipTypeAndSizeAnalysis extends StatisticBasedAnalysis { boolean isAbnormalCellForShipTypeAndSize(Long cellId, int shipTypeKey, int shipSizeKey) { float pd = 1.0f; StatisticData shipSizeAndTypeData = getStatisticDataRepository().getStatisticData("ShipTypeAndSizeStatistic", cellId); if (shipSizeAndTypeData instanceof ShipTypeAndSizeStatisticData) { Integer totalCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getSumFor("shipCount"); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { Integer shipCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getValue(shipTypeKey, shipSizeKey, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT); if (shipCount == null) { shipCount = 0; } pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", 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 isAbnormalCellForShipTypeAndSize = pd < PD; if (isAbnormalCellForShipTypeAndSize) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalCellForShipTypeAndSize; } }
ShipTypeAndSizeAnalysis extends StatisticBasedAnalysis { boolean isAbnormalCellForShipTypeAndSize(Long cellId, int shipTypeKey, int shipSizeKey) { float pd = 1.0f; StatisticData shipSizeAndTypeData = getStatisticDataRepository().getStatisticData("ShipTypeAndSizeStatistic", cellId); if (shipSizeAndTypeData instanceof ShipTypeAndSizeStatisticData) { Integer totalCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getSumFor("shipCount"); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { Integer shipCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getValue(shipTypeKey, shipSizeKey, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT); if (shipCount == null) { shipCount = 0; } pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", 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 isAbnormalCellForShipTypeAndSize = pd < PD; if (isAbnormalCellForShipTypeAndSize) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalCellForShipTypeAndSize; } @Inject  ShipTypeAndSizeAnalysis(Configuration configuration, AppStatisticsService statisticsService, StatisticDataRepository statisticsRepository, EventEmittingTracker trackingService, EventRepository eventRepository, BehaviourManager behaviourManager); }
ShipTypeAndSizeAnalysis extends StatisticBasedAnalysis { boolean isAbnormalCellForShipTypeAndSize(Long cellId, int shipTypeKey, int shipSizeKey) { float pd = 1.0f; StatisticData shipSizeAndTypeData = getStatisticDataRepository().getStatisticData("ShipTypeAndSizeStatistic", cellId); if (shipSizeAndTypeData instanceof ShipTypeAndSizeStatisticData) { Integer totalCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getSumFor("shipCount"); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { Integer shipCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getValue(shipTypeKey, shipSizeKey, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT); if (shipCount == null) { shipCount = 0; } pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", 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 isAbnormalCellForShipTypeAndSize = pd < PD; if (isAbnormalCellForShipTypeAndSize) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalCellForShipTypeAndSize; } @Inject  ShipTypeAndSizeAnalysis(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); }
ShipTypeAndSizeAnalysis extends StatisticBasedAnalysis { boolean isAbnormalCellForShipTypeAndSize(Long cellId, int shipTypeKey, int shipSizeKey) { float pd = 1.0f; StatisticData shipSizeAndTypeData = getStatisticDataRepository().getStatisticData("ShipTypeAndSizeStatistic", cellId); if (shipSizeAndTypeData instanceof ShipTypeAndSizeStatisticData) { Integer totalCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getSumFor("shipCount"); if (totalCount > TOTAL_SHIP_COUNT_THRESHOLD) { Integer shipCount = ((ShipTypeAndSizeStatisticData) shipSizeAndTypeData).getValue(shipTypeKey, shipSizeKey, ShipTypeAndSizeStatisticData.STAT_SHIP_COUNT); if (shipCount == null) { shipCount = 0; } pd = (float) shipCount / (float) totalCount; LOG.debug("cellId=" + cellId + ", shipType=" + shipTypeKey + ", shipSize=" + shipSizeKey + ", 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 isAbnormalCellForShipTypeAndSize = pd < PD; if (isAbnormalCellForShipTypeAndSize) { LOG.debug("Abnormal event detected."); } else { LOG.debug("Normal or inconclusive event detected."); } statisticsService.incAnalysisStatistics(getAnalysisName(), "Analyses performed"); return isAbnormalCellForShipTypeAndSize; } @Inject  ShipTypeAndSizeAnalysis(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);  }