diff --git a/jpo-conflictmonitor b/jpo-conflictmonitor index 14f1cb507..61d14702e 160000 --- a/jpo-conflictmonitor +++ b/jpo-conflictmonitor @@ -1 +1 @@ -Subproject commit 14f1cb507260747aecbbf1f1b6be30ef2fc507a1 +Subproject commit 61d14702e964df7992fb7b20353f9024c32bd469 diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepository.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepository.java index 46c3ce8cd..c09824c3d 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepository.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepository.java @@ -11,7 +11,7 @@ import us.dot.its.jpo.ode.api.models.IntersectionReferenceData; public interface ProcessedMapRepository extends DataLoader>{ - Query getQuery(Integer intersectionID, Long startTime, Long endTime,boolean latest); + Query getQuery(Integer intersectionID, Long startTime, Long endTime,boolean latest, boolean compact); long getQueryResultCount(Query query); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepositoryImpl.java index 485aee53d..02d018025 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/map/ProcessedMapRepositoryImpl.java @@ -54,7 +54,7 @@ public class ProcessedMapRepositoryImpl implements ProcessedMapRepository { private ObjectMapper mapper = DateJsonMapper.getInstance(); private Logger logger = LoggerFactory.getLogger(ProcessedMapRepositoryImpl.class); - public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest) { + public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest, boolean compact) { Query query = new Query(); if (intersectionID != null) { @@ -78,8 +78,13 @@ public Query getQuery(Integer intersectionID, Long startTime, Long endTime, bool query.limit(props.getMaximumResponseSize()); } + if (compact){ + query.fields().exclude("recordGeneratedAt", "properties.validationMessages"); + }else{ + query.fields().exclude("recordGeneratedAt"); + } + query.addCriteria(Criteria.where("properties.timeStamp").gte(startTimeString).lte(endTimeString)); - query.fields().exclude("recordGeneratedAt"); return query; } diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepository.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepository.java index 0b670a12f..d9c95b376 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepository.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepository.java @@ -9,7 +9,7 @@ import org.springframework.data.mongodb.core.query.Query; public interface ProcessedSpatRepository extends DataLoader{ - Query getQuery(Integer intersectionID, Long startTime, Long endTime); + Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest, boolean compact); long getQueryResultCount(Query query); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepositoryImpl.java index 131ea2ddd..6034eb9f1 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/spat/ProcessedSpatRepositoryImpl.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -40,7 +41,7 @@ public class ProcessedSpatRepositoryImpl implements ProcessedSpatRepository { private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH"); private ObjectMapper mapper = DateJsonMapper.getInstance(); - public Query getQuery(Integer intersectionID, Long startTime, Long endTime) { + public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest, boolean compact) { Query query = new Query(); if (intersectionID != null) { @@ -56,9 +57,21 @@ public Query getQuery(Integer intersectionID, Long startTime, Long endTime) { if (endTime != null) { endTimeString = Instant.ofEpochMilli(endTime).toString(); } - query.limit(props.getMaximumResponseSize()); - query.addCriteria(Criteria.where("odeReceivedAt").gte(startTimeString).lte(endTimeString)); - query.fields().exclude("recordGeneratedAt"); + + if (latest) { + query.with(Sort.by(Sort.Direction.DESC, "utcTimeStamp")); + query.limit(1); + }else{ + query.limit(props.getMaximumResponseSize()); + } + + if (compact){ + query.fields().exclude("recordGeneratedAt", "validationMessages"); + }else{ + query.fields().exclude("recordGeneratedAt"); + } + + query.addCriteria(Criteria.where("utcTimeStamp").gte(startTimeString).lte(endTimeString)); return query; } @@ -72,26 +85,20 @@ public List findProcessedSpats(Query query) { } public List getSpatBroadcastRates(int intersectionID, Long startTime, Long endTime){ - Query query = getQuery(intersectionID, startTime, endTime); + Query query = getQuery(intersectionID, startTime, endTime, false, true); query.fields().include("utcTimeStamp"); List times = mongoTemplate.find(query, Map.class, collectionName); - //List spats = findProcessedSpats(query); - System.out.println("Retreived Spat List" + times.size()); Map results = new HashMap<>(); for(Map doc: times){ - //ZonedDateTime time = spat.getUtcTimeStamp(); - System.out.println(doc); ZonedDateTime time = mapper.convertValue(doc.get("utcTimeStamp"), ZonedDateTime.class); String key = time.format(formatter); - //String key = map.getProperties().getTimeStamp().substring(0,10) + map.getProperties().getTimeStamp().substring(11,13); if(results.containsKey(key)){ IDCount count = results.get(key); count.setCount(count.getCount() +1); - //results.put(key, count); } else{ IDCount count = new IDCount(); @@ -101,46 +108,12 @@ public List getSpatBroadcastRates(int intersectionID, Long startTime, L } } - System.out.println("Finished Message Parsing"); - - //AggregationResults result = mongoTemplate.aggregate(aggregation, collectionName, IDCount.class); - //List results = result.getMappedResults(); - //results = new ArrayList(results); - List outputCounts = new ArrayList<>(results.values()); for (IDCount r : outputCounts) { r.setCount((double) r.getCount() / 3600.0); } return outputCounts; - // String startTimeString = Instant.ofEpochMilli(0).toString(); - // String endTimeString = Instant.now().toString(); - - // if (startTime != null) { - // startTimeString = Instant.ofEpochMilli(startTime).toString(); - // } - // if (endTime != null) { - // endTimeString = Instant.ofEpochMilli(endTime).toString(); - // } - - // AggregationOptions options = AggregationOptions.builder().allowDiskUse(true).build(); - - // Aggregation aggregation = Aggregation.newAggregation( - // Aggregation.match(Criteria.where("intersectionId").is(intersectionID)), - // Aggregation.match(Criteria.where("utcTimeStamp").gte(startTimeString).lte(endTimeString)), - // Aggregation.project("utcTimeStamp"), - // Aggregation.project() - // .and(DateOperators.DateFromString.fromStringOf("utcTimeStamp")).as("date"), - // Aggregation.project() - // .and(DateOperators.DateToString.dateOf("date").toString("%Y-%m-%d-%H")).as("dateStr"), - // Aggregation.group("dateStr").count().as("count"), - // Aggregation.sort(Sort.Direction.ASC, "_id") - // ).withOptions(options); - - // AggregationResults result = mongoTemplate.aggregate(aggregation, collectionName, IDCount.class); - // List results = result.getMappedResults(); - // for (IDCount r: results){ - // r.setCount((float)r.getCount() / 3600.0); - // } + } @@ -187,5 +160,4 @@ public List getSpatBroadcastRateDistribution(int intersectionID, Long s public void add(ProcessedSpat item) { mongoTemplate.save(item, collectionName); } - } diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java index 47b94bebe..3a173c82f 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/MapController.java @@ -44,13 +44,14 @@ public ResponseEntity> findMaps( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @RequestParam(name = "end_time_utc_millis", required = false) Long endTime, - @RequestParam(name= "latest", required = false, defaultValue = "false") boolean latest, - @RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) { + @RequestParam(name = "latest", required = false, defaultValue = "false") boolean latest, + @RequestParam(name = "test", required = false, defaultValue = "false") boolean testData, + @RequestParam(name = "compact", required = false, defaultValue = "false") boolean compact) { if (testData) { return ResponseEntity.ok(MockMapGenerator.getProcessedMaps()); } else { - Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, latest); + Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, latest, compact); long count = processedMapRepo.getQueryResultCount(query); logger.info("Returning ProcessedMap Response with Size: " + count); @@ -71,7 +72,7 @@ public ResponseEntity countMaps( if (testData) { return ResponseEntity.ok(5L); } else { - Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, false); + Query query = processedMapRepo.getQuery(intersectionID, startTime, endTime, false, true); long count = processedMapRepo.getQueryResultCount(query); logger.info("Found: " + count + "Processed Map Messages"); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java index cb6c32976..fb88691cc 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/controllers/SpatController.java @@ -46,12 +46,14 @@ public ResponseEntity> findSpats( @RequestParam(name = "intersection_id", required = false) Integer intersectionID, @RequestParam(name = "start_time_utc_millis", required = false) Long startTime, @RequestParam(name = "end_time_utc_millis", required = false) Long endTime, + @RequestParam(name = "latest", required = false, defaultValue = "false") boolean latest, + @RequestParam(name = "compact", required = false, defaultValue = "false") boolean compact, @RequestParam(name = "test", required = false, defaultValue = "false") boolean testData) { if (testData) { return ResponseEntity.ok(MockSpatGenerator.getProcessedSpats()); } else { - Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime); + Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime, latest, compact); long count = processedSpatRepo.getQueryResultCount(query); logger.info("Returning Processed Spat Response with Size: " + count); return ResponseEntity.ok(processedSpatRepo.findProcessedSpats(query)); @@ -70,7 +72,7 @@ public ResponseEntity countSpats( if (testData) { return ResponseEntity.ok(80L); } else { - Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime); + Query query = processedSpatRepo.getQuery(intersectionID, startTime, endTime,false, true); long count = processedSpatRepo.getQueryResultCount(query); logger.info("Found: " + count + "Processed Spat Messages"); return ResponseEntity.ok(count); diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/AssessmentTests.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/AssessmentTests.java index a11b73939..467d0d33b 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/AssessmentTests.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/AssessmentTests.java @@ -19,7 +19,6 @@ import us.dot.its.jpo.conflictmonitor.monitor.models.assessments.ConnectionOfTravelAssessment; import us.dot.its.jpo.conflictmonitor.monitor.models.assessments.LaneDirectionOfTravelAssessment; -import us.dot.its.jpo.conflictmonitor.monitor.models.assessments.SignalStateAssessment; import us.dot.its.jpo.conflictmonitor.monitor.models.assessments.StopLinePassageAssessment; import us.dot.its.jpo.conflictmonitor.monitor.models.assessments.StopLineStopAssessment; import us.dot.its.jpo.ode.api.accessors.assessments.ConnectionOfTravelAssessment.ConnectionOfTravelAssessmentRepository; diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MapTest.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MapTest.java index bf789b1b5..aa581e6d2 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MapTest.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MapTest.java @@ -42,10 +42,10 @@ public void testProcessedMap() { List list = MockMapGenerator.getProcessedMaps(); - Query query = processedMapRepo.getQuery(null, null, null, false); + Query query = processedMapRepo.getQuery(null, null, null, false, false); when(processedMapRepo.findProcessedMaps(query)).thenReturn(list); - ResponseEntity> result = controller.findMaps(null, null, null, false, false); + ResponseEntity> result = controller.findMaps(null, null, null, false, false, false); assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); assertThat(result.getBody()).isEqualTo(list); } diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MockKeyCloakAuth.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MockKeyCloakAuth.java index ad88cfdf4..fd5891bca 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MockKeyCloakAuth.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/MockKeyCloakAuth.java @@ -5,7 +5,6 @@ import java.util.Collection; import java.util.Set; - import org.mockito.Mockito; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/SpatTest.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/SpatTest.java index 335c280d3..2b663e9e6 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/SpatTest.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/SpatTest.java @@ -41,10 +41,10 @@ public void testProcessedSpat() { List list = MockSpatGenerator.getProcessedSpats(); - Query query = processedSpatRepo.getQuery(null, null, null); + Query query = processedSpatRepo.getQuery(null, null, null, false, false); when(processedSpatRepo.findProcessedSpats(query)).thenReturn(list); - ResponseEntity> result = controller.findSpats(null, null, null, false); + ResponseEntity> result = controller.findSpats(null, null, null, false,false,false); assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); // assertThat(result.getHeaders().getContentType()).isEqualTo(MediaType.APPLICATION_JSON); assertThat(result.getBody()).isEqualTo(list); diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/map/ProcessedMapRepositoryImplTest.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/map/ProcessedMapRepositoryImplTest.java index 5c5016071..be40c1ffc 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/map/ProcessedMapRepositoryImplTest.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/map/ProcessedMapRepositoryImplTest.java @@ -51,7 +51,7 @@ public void testGetQuery() { boolean latest = true; - Query query = repository.getQuery(intersectionID, startTime, endTime, latest); + Query query = repository.getQuery(intersectionID, startTime, endTime, latest, false); // Assert IntersectionID diff --git a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/spat/ProcessedSpatRepositoryImplTest.java b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/spat/ProcessedSpatRepositoryImplTest.java index 69b310fea..a663418ee 100644 --- a/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/spat/ProcessedSpatRepositoryImplTest.java +++ b/jpo-conflictvisualizer-api/src/test/java/us/dot/its/jpo/ode/api/accessorTests/spat/ProcessedSpatRepositoryImplTest.java @@ -51,7 +51,7 @@ void setUp() { @Test public void testGetQuery() { - Query query = repository.getQuery(intersectionID, startTime, endTime); + Query query = repository.getQuery(intersectionID, startTime, endTime, false, false); @@ -60,7 +60,7 @@ public void testGetQuery() { // Assert Start and End Time - Document queryTimeDocument = (Document)query.getQueryObject().get("odeReceivedAt"); + Document queryTimeDocument = (Document)query.getQueryObject().get("utcTimeStamp"); assertThat(queryTimeDocument.getString("$gte")).isEqualTo(Instant.ofEpochMilli(startTime).toString()); assertThat(queryTimeDocument.getString("$lte")).isEqualTo(Instant.ofEpochMilli(endTime).toString());