Skip to content

Commit

Permalink
Merge pull request #118 from usdot-jpo-ode/message-progression-events
Browse files Browse the repository at this point in the history
Message progression events
  • Loading branch information
John-Wiens authored Nov 27, 2024
2 parents 47298ea + ff0b8ca commit 4bd9712
Show file tree
Hide file tree
Showing 9 changed files with 608 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jpo-conflictvisualizer-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<dependency>
<groupId>usdot.jpo.ode</groupId>
<artifactId>jpo-conflictmonitor</artifactId>
<version>1.4.1</version>
<version>1.5.0</version>
<!-- <classifier>jpo-conflictmonitor</classifier> -->
</dependency>
<dependency>
Expand Down
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);
}
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'");
}


}
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);
}
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'");
}


}
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);
}
Loading

0 comments on commit 4bd9712

Please sign in to comment.