forked from usdot-jpo-ode/jpo-cvmanager
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from usdot-jpo-ode/message-progression-events
Message progression events
- Loading branch information
Showing
9 changed files
with
608 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../BsmMessageCountProgressionEventRepository/BsmMessageCountProgressionEventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package us.dot.its.jpo.ode.api.accessors.events.BsmMessageCountProgressionEventRepository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.mongodb.core.query.Query; | ||
import us.dot.its.jpo.ode.api.models.IDCount; | ||
import us.dot.its.jpo.ode.api.models.DataLoader; | ||
import us.dot.its.jpo.conflictmonitor.monitor.models.events.BsmMessageCountProgressionEvent; | ||
|
||
public interface BsmMessageCountProgressionEventRepository extends DataLoader<BsmMessageCountProgressionEvent>{ | ||
Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest); | ||
|
||
long getQueryResultCount(Query query); | ||
|
||
long getQueryFullCount(Query query); | ||
|
||
List<BsmMessageCountProgressionEvent> find(Query query); | ||
|
||
List<IDCount> getBsmBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime); | ||
} |
113 changes: 113 additions & 0 deletions
113
...s/BsmMessageCountProgressionEventRepository/BsmMessageCountProgressionRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package us.dot.its.jpo.ode.api.accessors.events.BsmMessageCountProgressionEventRepository; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
import org.springframework.data.domain.Sort; | ||
|
||
import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
import org.springframework.data.mongodb.core.aggregation.DateOperators; | ||
|
||
import us.dot.its.jpo.conflictmonitor.monitor.models.events.BsmMessageCountProgressionEvent; | ||
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties; | ||
import us.dot.its.jpo.ode.api.models.IDCount; | ||
|
||
@Component | ||
public class BsmMessageCountProgressionRepositoryImpl implements BsmMessageCountProgressionEventRepository { | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@Autowired | ||
ConflictMonitorApiProperties props; | ||
|
||
private String collectionName = "CmBsmMessageCountProgressionEvents"; | ||
|
||
public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest) { | ||
Query query = new Query(); | ||
|
||
if (intersectionID != null) { | ||
query.addCriteria(Criteria.where("intersectionID").is(intersectionID)); | ||
} | ||
Date startTimeDate = new Date(0); | ||
Date endTimeDate = new Date(); | ||
|
||
if (startTime != null) { | ||
startTimeDate = new Date(startTime); | ||
} | ||
if (endTime != null) { | ||
endTimeDate = new Date(endTime); | ||
} | ||
|
||
query.addCriteria(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)); | ||
if (latest) { | ||
query.with(Sort.by(Sort.Direction.DESC, "eventGeneratedAt")); | ||
query.limit(1); | ||
}else{ | ||
query.limit(props.getMaximumResponseSize()); | ||
} | ||
return query; | ||
} | ||
|
||
public long getQueryResultCount(Query query) { | ||
return mongoTemplate.count(query, BsmMessageCountProgressionEvent.class, collectionName); | ||
} | ||
|
||
public long getQueryFullCount(Query query){ | ||
int limit = query.getLimit(); | ||
query.limit(-1); | ||
long count = mongoTemplate.count(query, BsmMessageCountProgressionEvent.class, collectionName); | ||
query.limit(limit); | ||
return count; | ||
} | ||
|
||
public List<BsmMessageCountProgressionEvent> find(Query query) { | ||
return mongoTemplate.find(query, BsmMessageCountProgressionEvent.class, collectionName); | ||
} | ||
|
||
public List<IDCount> getBsmMessageCountProgressionEventsByDay(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) { | ||
endTimeDate = new Date(endTime); | ||
} | ||
|
||
Aggregation aggregation = Aggregation.newAggregation( | ||
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), | ||
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), | ||
Aggregation.project() | ||
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), | ||
Aggregation.group("dateStr").count().as("count") | ||
); | ||
|
||
AggregationResults<IDCount> result = mongoTemplate.aggregate(aggregation, collectionName, IDCount.class); | ||
List<IDCount> results = result.getMappedResults(); | ||
|
||
return results; | ||
} | ||
|
||
@Override | ||
public void add(BsmMessageCountProgressionEvent item) { | ||
mongoTemplate.save(item, collectionName); | ||
} | ||
|
||
@Override | ||
public List<IDCount> getBsmBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getBsmBroadcastRateEventsByDay'"); | ||
} | ||
|
||
|
||
} |
20 changes: 20 additions & 0 deletions
20
.../MapMessageCountProgressionEventRepository/MapMessageCountProgressionEventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package us.dot.its.jpo.ode.api.accessors.events.MapMessageCountProgressionEventRepository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.mongodb.core.query.Query; | ||
import us.dot.its.jpo.ode.api.models.IDCount; | ||
import us.dot.its.jpo.ode.api.models.DataLoader; | ||
import us.dot.its.jpo.conflictmonitor.monitor.models.events.MapMessageCountProgressionEvent; | ||
|
||
public interface MapMessageCountProgressionEventRepository extends DataLoader<MapMessageCountProgressionEvent>{ | ||
Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest); | ||
|
||
long getQueryResultCount(Query query); | ||
|
||
long getQueryFullCount(Query query); | ||
|
||
List<MapMessageCountProgressionEvent> find(Query query); | ||
|
||
List<IDCount> getMapBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime); | ||
} |
114 changes: 114 additions & 0 deletions
114
...s/MapMessageCountProgressionEventRepository/MapMessageCountProgressionRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package us.dot.its.jpo.ode.api.accessors.events.MapMessageCountProgressionEventRepository; | ||
|
||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.mongodb.core.MongoTemplate; | ||
import org.springframework.data.mongodb.core.query.Criteria; | ||
import org.springframework.data.mongodb.core.query.Query; | ||
import org.springframework.stereotype.Component; | ||
|
||
|
||
import org.springframework.data.domain.Sort; | ||
|
||
import org.springframework.data.mongodb.core.aggregation.Aggregation; | ||
import org.springframework.data.mongodb.core.aggregation.AggregationResults; | ||
import org.springframework.data.mongodb.core.aggregation.DateOperators; | ||
|
||
import us.dot.its.jpo.conflictmonitor.monitor.models.events.MapMessageCountProgressionEvent; | ||
import us.dot.its.jpo.ode.api.ConflictMonitorApiProperties; | ||
import us.dot.its.jpo.ode.api.models.IDCount; | ||
|
||
@Component | ||
public class MapMessageCountProgressionRepositoryImpl implements MapMessageCountProgressionEventRepository { | ||
|
||
@Autowired | ||
private MongoTemplate mongoTemplate; | ||
|
||
@Autowired | ||
ConflictMonitorApiProperties props; | ||
|
||
private String collectionName = "CmMapMessageCountProgressionEvents"; | ||
|
||
public Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest) { | ||
Query query = new Query(); | ||
|
||
if (intersectionID != null) { | ||
query.addCriteria(Criteria.where("intersectionID").is(intersectionID)); | ||
} | ||
Date startTimeDate = new Date(0); | ||
Date endTimeDate = new Date(); | ||
|
||
if (startTime != null) { | ||
startTimeDate = new Date(startTime); | ||
} | ||
if (endTime != null) { | ||
endTimeDate = new Date(endTime); | ||
} | ||
|
||
query.addCriteria(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)); | ||
if (latest) { | ||
query.with(Sort.by(Sort.Direction.DESC, "eventGeneratedAt")); | ||
query.limit(1); | ||
}else{ | ||
query.limit(props.getMaximumResponseSize()); | ||
} | ||
return query; | ||
} | ||
|
||
public long getQueryResultCount(Query query) { | ||
return mongoTemplate.count(query, MapMessageCountProgressionEvent.class, collectionName); | ||
} | ||
|
||
public long getQueryFullCount(Query query){ | ||
int limit = query.getLimit(); | ||
query.limit(-1); | ||
long count = mongoTemplate.count(query, MapMessageCountProgressionEvent.class, collectionName); | ||
query.limit(limit); | ||
return count; | ||
} | ||
|
||
public List<MapMessageCountProgressionEvent> find(Query query) { | ||
return mongoTemplate.find(query, MapMessageCountProgressionEvent.class, collectionName); | ||
} | ||
|
||
public List<IDCount> getMapMessageCountProgressionEventsByDay(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) { | ||
endTimeDate = new Date(endTime); | ||
} | ||
|
||
Aggregation aggregation = Aggregation.newAggregation( | ||
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)), | ||
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)), | ||
Aggregation.project() | ||
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"), | ||
Aggregation.group("dateStr").count().as("count") | ||
); | ||
|
||
AggregationResults<IDCount> result = mongoTemplate.aggregate(aggregation, collectionName, IDCount.class); | ||
List<IDCount> results = result.getMappedResults(); | ||
|
||
return results; | ||
} | ||
|
||
@Override | ||
public void add(MapMessageCountProgressionEvent item) { | ||
mongoTemplate.save(item, collectionName); | ||
} | ||
|
||
@Override | ||
public List<IDCount> getMapBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime) { | ||
// TODO Auto-generated method stub | ||
throw new UnsupportedOperationException("Unimplemented method 'getMapBroadcastRateEventsByDay'"); | ||
} | ||
|
||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...s/events/SpatMessageCountProgressionEvent/SpatMessageCountProgressionEventRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package us.dot.its.jpo.ode.api.accessors.events.SpatMessageCountProgressionEvent; | ||
|
||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.mongodb.core.query.Query; | ||
import us.dot.its.jpo.ode.api.models.IDCount; | ||
import us.dot.its.jpo.ode.api.models.DataLoader; | ||
import us.dot.its.jpo.conflictmonitor.monitor.models.events.SpatMessageCountProgressionEvent; | ||
|
||
public interface SpatMessageCountProgressionEventRepository extends DataLoader<SpatMessageCountProgressionEvent>{ | ||
Query getQuery(Integer intersectionID, Long startTime, Long endTime, boolean latest); | ||
|
||
long getQueryResultCount(Query query); | ||
|
||
long getQueryFullCount(Query query); | ||
|
||
List<SpatMessageCountProgressionEvent> find(Query query); | ||
|
||
List<IDCount> getSpatBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime); | ||
} |
Oops, something went wrong.