diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapBroadcastRateEvents/MapBroadcastRateEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapBroadcastRateEvents/MapBroadcastRateEventRepositoryImpl.java index fd344b107..f075339c8 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapBroadcastRateEvents/MapBroadcastRateEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapBroadcastRateEvents/MapBroadcastRateEventRepositoryImpl.java @@ -79,22 +79,17 @@ public List getMapBroadcastRateEventsByDay(int intersectionID, Long sta Date endTimeDate = new Date(); if (startTime != null) { - startTime = 0L; - startTimeDate = new Date(startTime); } if (endTime != null) { - endTime = System.currentTimeMillis(); endTimeDate = new Date(endTime); } Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), - Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") ); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapMinimumDataEvent/MapMinimumDataEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapMinimumDataEvent/MapMinimumDataEventRepositoryImpl.java index b79999063..ec5127077 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapMinimumDataEvent/MapMinimumDataEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/MapMinimumDataEvent/MapMinimumDataEventRepositoryImpl.java @@ -73,21 +73,22 @@ public List find(Query query) { return mongoTemplate.find(query, MapMinimumDataEvent.class, collectionName); } - public List getMapMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime) { - if (startTime == null) { - startTime = 0L; + public List getMapMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime){ + Date startTimeDate = new Date(0); + Date endTimeDate = new Date(); + + if (startTime != null) { + startTimeDate = new Date(startTime); } - if (endTime == null) { - endTime = System.currentTimeMillis(); + if (endTime != null) { + endTimeDate = new Date(endTime); } - + Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), - Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") ); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SignalStateConflictEvent/SignalStateConflictEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SignalStateConflictEvent/SignalStateConflictEventRepositoryImpl.java index bca5deda3..8544c64d3 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SignalStateConflictEvent/SignalStateConflictEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SignalStateConflictEvent/SignalStateConflictEventRepositoryImpl.java @@ -73,24 +73,25 @@ public List find(Query query) { return mongoTemplate.find(query, SignalStateConflictEvent.class, collectionName); } - public List getSignalStateConflictEventsByDay(int intersectionID, Long startTime, Long endTime) { - if (startTime == null) { - startTime = 0L; + public List getSignalStateConflictEventsByDay(int intersectionID, Long startTime, Long endTime){ + Date startTimeDate = new Date(0); + Date endTimeDate = new Date(); + + if (startTime != null) { + startTimeDate = new Date(startTime); } - if (endTime == null) { - endTime = System.currentTimeMillis(); + if (endTime != null) { + endTimeDate = new Date(endTime); } Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), - Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") ); - + AggregationResults result = mongoTemplate.aggregate(aggregation, collectionName, IDCount.class); List results = result.getMappedResults(); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatBroadcastRateEvent/SpatBroadcastRateEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatBroadcastRateEvent/SpatBroadcastRateEventRepositoryImpl.java index 9e9573d42..139035649 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatBroadcastRateEvent/SpatBroadcastRateEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatBroadcastRateEvent/SpatBroadcastRateEventRepositoryImpl.java @@ -74,21 +74,22 @@ public List find(Query query) { return mongoTemplate.find(query, SpatBroadcastRateEvent.class, collectionName); } - public List getSpatBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime) { - if (startTime == null) { - startTime = 0L; + public List getSpatBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime){ + Date startTimeDate = new Date(0); + Date endTimeDate = new Date(); + + if (startTime != null) { + startTimeDate = new Date(startTime); } - if (endTime == null) { - endTime = System.currentTimeMillis(); + if (endTime != null) { + endTimeDate = new Date(endTime); } Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), - Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") ); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatMinimumDataEvent/SpatMinimumDataEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatMinimumDataEvent/SpatMinimumDataEventRepositoryImpl.java index a08a28ef2..86577978c 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatMinimumDataEvent/SpatMinimumDataEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/SpatMinimumDataEvent/SpatMinimumDataEventRepositoryImpl.java @@ -74,21 +74,22 @@ public List find(Query query) { return mongoTemplate.find(query, SpatMinimumDataEvent.class, collectionName); } - public List getSpatMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime) { - if (startTime == null) { - startTime = 0L; + public List getSpatMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime){ + Date startTimeDate = new Date(0); + Date endTimeDate = new Date(); + + if (startTime != null) { + startTimeDate = new Date(startTime); } - if (endTime == null) { - endTime = System.currentTimeMillis(); + if (endTime != null) { + endTimeDate = new Date(endTime); } Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), - Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") ); diff --git a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/TimeChangeDetailsEvent/TimeChangeDetailsEventRepositoryImpl.java b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/TimeChangeDetailsEvent/TimeChangeDetailsEventRepositoryImpl.java index b2c5f54f4..b1e24edfc 100644 --- a/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/TimeChangeDetailsEvent/TimeChangeDetailsEventRepositoryImpl.java +++ b/jpo-conflictvisualizer-api/src/main/java/us/dot/its/jpo/ode/api/accessors/events/TimeChangeDetailsEvent/TimeChangeDetailsEventRepositoryImpl.java @@ -73,21 +73,22 @@ public List find(Query query) { return mongoTemplate.find(query, TimeChangeDetailsEvent.class, collectionName); } - public List getTimeChangeDetailsEventsByDay(int intersectionID, Long startTime, Long endTime) { - if (startTime == null) { - startTime = 0L; + public List getTimeChangeDetailsEventsByDay(int intersectionID, Long startTime, Long endTime){ + Date startTimeDate = new Date(0); + Date endTimeDate = new Date(); + + if (startTime != null) { + startTimeDate = new Date(startTime); } - if (endTime == null) { - endTime = System.currentTimeMillis(); + if (endTime != null) { + endTimeDate = new Date(endTime); } Aggregation aggregation = Aggregation.newAggregation( Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), - Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)), - Aggregation.project() - .andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"), + Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), Aggregation.project() - .andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"), + .and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), Aggregation.group("dateStr").count().as("count") );