Skip to content

Commit

Permalink
Implemented first prototype of new reports with subset of normal charts
Browse files Browse the repository at this point in the history
  • Loading branch information
linda-baker committed Dec 4, 2024
1 parent bafdb2e commit 2a9f845
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package us.dot.its.jpo.ode.api.accessors.events.MapBroadcastRateEvents;

import java.sql.SQLClientInfoException;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -78,17 +79,22 @@ public List<IDCount> 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(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,21 @@ public List<MapMinimumDataEvent> find(Query query) {
return mongoTemplate.find(query, MapMinimumDataEvent.class, collectionName);
}

public List<IDCount> getMapMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime){
Date startTimeDate = new Date(0);
Date endTimeDate = new Date();

if (startTime != null) {
startTimeDate = new Date(startTime);
public List<IDCount> getMapMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime) {
if (startTime == null) {
startTime = 0L;
}
if (endTime != null) {
endTimeDate = new Date(endTime);
if (endTime == null) {
endTime = System.currentTimeMillis();
}

Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,21 @@ public List<SignalStateConflictEvent> find(Query query) {
return mongoTemplate.find(query, SignalStateConflictEvent.class, collectionName);
}

public List<IDCount> getSignalStateConflictEventsByDay(int intersectionID, Long startTime, Long endTime){
Date startTimeDate = new Date(0);
Date endTimeDate = new Date();

if (startTime != null) {
startTimeDate = new Date(startTime);
public List<IDCount> getSignalStateConflictEventsByDay(int intersectionID, Long startTime, Long endTime) {
if (startTime == null) {
startTime = 0L;
}
if (endTime != null) {
endTimeDate = new Date(endTime);
if (endTime == null) {
endTime = System.currentTimeMillis();
}

Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,21 @@ public List<SpatBroadcastRateEvent> find(Query query) {
return mongoTemplate.find(query, SpatBroadcastRateEvent.class, collectionName);
}

public List<IDCount> getSpatBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime){
Date startTimeDate = new Date(0);
Date endTimeDate = new Date();

if (startTime != null) {
startTimeDate = new Date(startTime);
public List<IDCount> getSpatBroadcastRateEventsByDay(int intersectionID, Long startTime, Long endTime) {
if (startTime == null) {
startTime = 0L;
}
if (endTime != null) {
endTimeDate = new Date(endTime);
if (endTime == null) {
endTime = System.currentTimeMillis();
}

Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,21 @@ public List<SpatMinimumDataEvent> find(Query query) {
return mongoTemplate.find(query, SpatMinimumDataEvent.class, collectionName);
}

public List<IDCount> getSpatMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime){
Date startTimeDate = new Date(0);
Date endTimeDate = new Date();

if (startTime != null) {
startTimeDate = new Date(startTime);
public List<IDCount> getSpatMinimumDataEventsByDay(int intersectionID, Long startTime, Long endTime) {
if (startTime == null) {
startTime = 0L;
}
if (endTime != null) {
endTimeDate = new Date(endTime);
if (endTime == null) {
endTime = System.currentTimeMillis();
}

Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,21 @@ public List<TimeChangeDetailsEvent> find(Query query) {
return mongoTemplate.find(query, TimeChangeDetailsEvent.class, collectionName);
}

public List<IDCount> getTimeChangeDetailsEventsByDay(int intersectionID, Long startTime, Long endTime){
Date startTimeDate = new Date(0);
Date endTimeDate = new Date();

if (startTime != null) {
startTimeDate = new Date(startTime);
public List<IDCount> getTimeChangeDetailsEventsByDay(int intersectionID, Long startTime, Long endTime) {
if (startTime == null) {
startTime = 0L;
}
if (endTime != null) {
endTimeDate = new Date(endTime);
if (endTime == null) {
endTime = System.currentTimeMillis();
}

Aggregation aggregation = Aggregation.newAggregation(
Aggregation.match(Criteria.where("intersectionID").is(intersectionID)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTimeDate).lte(endTimeDate)),
Aggregation.match(Criteria.where("eventGeneratedAt").gte(startTime).lte(endTime)),
Aggregation.project()
.andExpression("{$toDate: '$eventGeneratedAt'}").as("eventGeneratedAtDate"),
Aggregation.project()
.and(DateOperators.DateToString.dateOf("eventGeneratedAt").toString("%Y-%m-%d")).as("dateStr"),
.andExpression("{$dateToString: { format: '%Y-%m-%d', date: '$eventGeneratedAtDate' }}").as("dateStr"),
Aggregation.group("dateStr").count().as("count")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.data.annotation.Id;

import lombok.EqualsAndHashCode;
import java.util.List;

@ToString
@Setter
Expand All @@ -22,6 +23,10 @@ public class ReportDocument {
private long reportStartTime;
private long reportStopTime;
private byte[] reportContents;

}

private List<IDCount> mapBroadcastRateEventCount;
private List<IDCount> mapMinimumDataEventCount;
private List<IDCount> timeChangeDetailsEventCount;
private List<IDCount> spatMinimumDataEventCount;
private List<IDCount> spatBroadcastRateEventCount;
private List<IDCount> signalStateConflictEventCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.io.ByteArrayOutputStream;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Arrays;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -98,10 +101,9 @@ public class ReportService {
ReportRepository reportRepo;


public ReportDocument buildReport(int intersectionID, String roadRegulatorID, long startTime, long endTime) {

public ReportDocument buildReport(int intersectionID, String roadRegulatorID, long startTime, long endTime){

String reportName = "CmReport_"+ intersectionID + "_" + roadRegulatorID + "_" + startTime + "_" + endTime;
String reportName = "CmReport_" + intersectionID + "_" + roadRegulatorID + "_" + startTime + "_" + endTime;

// Lane Direction of Travel Info
List<IDCount> laneDirectionOfTravelEventCounts = laneDirectionOfTravelEventRepo.getLaneDirectionOfTravelEventsByDay(intersectionID, startTime, endTime);
Expand Down Expand Up @@ -231,6 +233,13 @@ public ReportDocument buildReport(int intersectionID, String roadRegulatorID, lo
doc.setReportStopTime(endTime);
doc.setReportContents(stream.toByteArray());
doc.setReportName(reportName);
doc.setMapBroadcastRateEventCount(mapBroadcastRateEventCount);
doc.setMapMinimumDataEventCount(mapMinimumDataEventCount);
doc.setTimeChangeDetailsEventCount(timeChangeDetailsEventCounts);
doc.setSpatMinimumDataEventCount(spatMinimumDataEventCount);
doc.setSpatBroadcastRateEventCount(spatBroadcastRateEventCount);
doc.setSignalStateConflictEventCount(signalStateConflictEventCounts);


reportRepo.add(doc);

Expand Down

0 comments on commit 2a9f845

Please sign in to comment.