public boolean isFitForAggregation(Point point) { boolean result = false; for (String propertyName : GlobalProperties.getPropertiesOfInterestDatabase().keySet()) { Object numberObject = point.getProperty(propertyName); if (numberObject instanceof Number) { result = result || !Utils.isNumberObjectNullOrZero((Number) numberObject); } else { /* * not a number, we cannot aggregate this currently */ result = result || false; } } /* * also check for bbox */ if (bbox != null) { Coordinate pointCoordinate = new Coordinate(point.getX(), point.getY()); if (!bbox.contains(Utils.geometryFactory.createPoint(pointCoordinate))) { return false; } } return result; }
public void runAlgorithm(Iterator<Point> newPoints, String trackId) { if (pointService.trackAlreadyAggregated(trackId)) { LOGGER.info("Track already aggregated. skipping. " + trackId); return; } pointService.insertTrackIntoAggregatedTracksTable(trackId); Point nextPoint; DateTime trackTime = null; List<MeasurementRelation> newRelations = new ArrayList<>(); while (newPoints.hasNext()) { nextPoint = newPoints.next(); /** set the timezone of the track */ if (trackTime == null) { trackTime = nextPoint.getTime(); timeBasedManager.updateTimeZone(trackTime); } if (useCategories) { nextPoint.setTimeCategory(timeBasedManager.fromTime(nextPoint.getTime())); } else { nextPoint.setTimeCategory(TimeBasedCategory.NO_CATEGORY); } /* * check if point is fit for aggregation (one or more value not null or 0) */ if (!isFitForAggregation(nextPoint)) { LOGGER.info("Skipping original point " + nextPoint.getID() + ". All values are null or 0."); continue; } /* * get nearest neighbor from resultSet */ Point nearestNeighbor = pointService.getNearestNeighbor(nextPoint, distance, useBearing ? maxBearingDelta : 0.0); if (nearestNeighbor != null) { /* * if there is one * * aggregate values (avg, function should be * replaceable) */ LOGGER.info("aggregating point: " + nextPoint.getID()); newRelations.add(pointService.aggregate(nextPoint, nearestNeighbor, trackId)); } else { /* * if there is no nearest neighbor * * add point to resultSet */ LOGGER.info( "No nearest neighbor found for " + nextPoint.getID() + ". Adding to resultSet."); /* * add point to result set, give it a new id */ newRelations.add(pointService.addToResultSet(nextPoint)); } } pointService.insertMeasurementRelations(newRelations); }