Skip to content

Commit 2c93c98

Browse files
Merge pull request #2 from camsys/feature/speed_map
Feature/speed map
2 parents db8d463 + cae15fc commit 2c93c98

4 files changed

Lines changed: 76 additions & 34 deletions

File tree

transitclock/src/main/java/org/transitclock/db/structs/ArrivalDeparture.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,9 @@ public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(
974974
*/
975975
public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(LocalDate beginDate, LocalDate endDate,
976976
LocalTime beginTime, LocalTime endTime,
977-
String routeId, ServiceType serviceType,
978-
boolean timePointsOnly, String headsign,
977+
String routeId, String headsign,
978+
ServiceType serviceType, boolean timePointsOnly,
979+
boolean scheduledTimesOnly, boolean dwellTimeOnly,
979980
boolean includeTrip, boolean includeStop,
980981
boolean includeStopPath, boolean readOnly) throws Exception {
981982
IntervalTimer timer = new IntervalTimer();
@@ -998,11 +999,13 @@ public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(LocalDate begin
998999
"WHERE " +
9991000
getArrivalDepartureTimeWhere(beginDate, endDate, beginTime, endTime) +
10001001
getRouteIdWhere(routeId) +
1002+
getScheduledTimesWhere(scheduledTimesOnly) +
10011003
getTimePointsWhere(timePointsOnly) +
10021004
getServiceTypeWhere(serviceType) +
10031005
getTripsWhere(headsign) +
10041006
getStopsWhere(includeStop) +
1005-
getStopPathsWhere(includeStopPath);
1007+
getStopPathsWhere(includeStopPath) +
1008+
getDwellTimesWhere(dwellTimeOnly);
10061009

10071010
try {
10081011
Query query = session.createQuery(hql);
@@ -1055,13 +1058,12 @@ private static String getStopsJoin(boolean includeStop){
10551058
}
10561059

10571060
private static String getTripsJoin(String headsign, boolean includeTrip){
1058-
if(StringUtils.isNotBlank(headsign)){
1059-
if(includeTrip){
1060-
return " JOIN FETCH ad.trip t ";
1061-
}else {
1062-
return ", Trip t ";
1063-
}
1061+
if(includeTrip){
1062+
return " JOIN FETCH ad.trip t ";
1063+
}else if(StringUtils.isNotBlank(headsign)){
1064+
return ", Trip t ";
10641065
}
1066+
10651067
return "";
10661068
}
10671069

@@ -1109,6 +1111,13 @@ private static String getRouteIdWhere(String routeId){
11091111
return "";
11101112
}
11111113

1114+
private static String getScheduledTimesWhere(boolean scheduledTimesOnly){
1115+
if(scheduledTimesOnly){
1116+
return "AND ad.scheduledTime IS NOT NULL ";
1117+
}
1118+
return "";
1119+
}
1120+
11121121
private static String getTimePointsWhere(boolean timePointsOnly){
11131122
if(timePointsOnly){
11141123
return "AND ad.configRev = sp.configRev AND ad.stopId = sp.stopId AND ad.tripPatternId = sp.tripPatternId AND sp.scheduleAdherenceStop = true ";
@@ -1151,6 +1160,13 @@ private static String getStopPathsWhere(boolean includeStopPaths){
11511160
}
11521161
return "";
11531162
}
1163+
1164+
private static String getDwellTimesWhere(boolean dwellTimesOnly){
1165+
if(dwellTimesOnly){
1166+
return "AND ad.dwellTime != null ";
1167+
}
1168+
return "";
1169+
}
11541170

11551171
public String getVehicleId() {
11561172
return vehicleId;

transitclock/src/main/java/org/transitclock/ipc/interfaces/ReportingInterface.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
*
1616
*/
1717
public interface ReportingInterface extends Remote {
18-
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(LocalDate beginDate, LocalDate endDate,
18+
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(LocalDate beginDate, LocalDate endDate,
1919
LocalTime beginTime, LocalTime endTime,
2020
String routeIdOrShortName, ServiceType serviceType,
2121
boolean timePointsOnly, String headsign) throws Exception;
2222

23-
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(LocalDate beginDate, LocalDate endDate,
23+
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(LocalDate beginDate, LocalDate endDate,
2424
LocalTime beginTime, LocalTime endTime,
2525
String routeId, ServiceType serviceType,
2626
boolean timePointsOnly, String headsign,
@@ -33,7 +33,8 @@ List<IpcStopWithDwellTime> getStopsWithAvgDwellTimes(LocalDate beginDate, LocalD
3333

3434
List<IpcStopPathWithSpeed> getStopPathsWithSpeed(LocalDate beginDate, LocalDate endDate,
3535
LocalTime beginTime, LocalTime endTime,
36-
String routeIdOrShortName, String headsign, boolean readOnly) throws Exception;
36+
String routeIdOrShortName, ServiceType serviceType,
37+
String headsign, boolean readOnly) throws Exception;
3738

3839
IpcDoubleSummaryStatistics getAverageRunTime(LocalDate beginDate, LocalDate endDate,
3940
LocalTime beginTime, LocalTime endTime, String routeIdOrShortName,

transitclock/src/main/java/org/transitclock/ipc/servers/ReportingServer.java

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
*/
3636
public class ReportingServer extends AbstractServer implements ReportingInterface {
3737

38+
private final boolean DEFAULT_TIME_POINTS_ONLY = false;
39+
private final boolean DEFAULT_SCHEDULED_TIMES_ONLY = false;
40+
private final boolean DEFAULT_DWELL_TIME_ONLY = false;
41+
private final boolean DEFAULT_INCLUDE_TRIP = false;
42+
private final boolean DEFAULT_INCLUDE_STOP = false;
43+
private final boolean DEFAULT_INCLUDE_STOP_PATH = false;
44+
private final ServiceType DEFAULT_SERVICE_TYPE = null;
45+
3846
private static int getMaxSchedAdh() {
3947
return maxSchedAdhSec.getValue();
4048
}
@@ -88,21 +96,22 @@ public static ReportingServer start(String agencyId) {
8896
}
8997

9098
@Override
91-
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
99+
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(
92100
LocalDate beginDate, LocalDate endDate, LocalTime beginTime, LocalTime endTime,
93101
String routeIdOrShortName, ServiceType serviceType,
94102
boolean timePointsOnly, String headsign) throws Exception{
95-
return getArrivalsDeparturesForRoute(beginDate, endDate, beginTime, endTime, routeIdOrShortName, serviceType,
103+
return getArrivalsDeparturesForOtp(beginDate, endDate, beginTime, endTime, routeIdOrShortName, serviceType,
96104
timePointsOnly, headsign, false);
97105
}
98106

99107
@Override
100-
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
108+
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(
101109
LocalDate beginDate, LocalDate endDate, LocalTime beginTime, LocalTime endTime,
102110
String routeIdOrShortName, ServiceType serviceType, boolean timePointsOnly,
103111
String headsign, boolean readOnly) throws Exception {
104112

105113
String routeId = null;
114+
boolean scheduledStopsOnly = true;
106115

107116
if(StringUtils.isNotBlank(routeIdOrShortName)){
108117
Route dbRoute = getRoute(routeIdOrShortName);
@@ -112,8 +121,9 @@ public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
112121
}
113122

114123
List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate, endDate,
115-
beginTime, endTime, routeId, serviceType, timePointsOnly,
116-
headsign, false, false, false, readOnly);
124+
beginTime, endTime, routeId, headsign, serviceType, timePointsOnly,
125+
scheduledStopsOnly,DEFAULT_DWELL_TIME_ONLY, DEFAULT_INCLUDE_TRIP,
126+
DEFAULT_INCLUDE_STOP, DEFAULT_INCLUDE_STOP_PATH, readOnly);
117127

118128
List<IpcArrivalDepartureScheduleAdherence> ipcArrivalDepartures = new ArrayList<>();
119129

@@ -126,22 +136,25 @@ public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
126136

127137
@Override
128138
public List<IpcStopWithDwellTime> getStopsWithAvgDwellTimes(LocalDate beginDate, LocalDate endDate,
129-
LocalTime beginTime, LocalTime endTime, String routeIdOrShortName,
130-
ServiceType serviceType, boolean timePointsOnly,
131-
String headsign, boolean readOnly) throws Exception {
139+
LocalTime beginTime, LocalTime endTime,
140+
String routeIdOrShortName, ServiceType serviceType,
141+
boolean timePointsOnly, String headsign,
142+
boolean readOnly) throws Exception {
132143

133144
String routeId = null;
134-
135145
if(StringUtils.isNotBlank(routeIdOrShortName)){
136146
Route dbRoute = getRoute(routeIdOrShortName);
137147
if (dbRoute == null)
138148
return null;
139149
routeId = dbRoute.getId();
140150
}
141151

152+
boolean dwellTimeOnly = true;
153+
boolean includeStop = true;
154+
142155
List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
143-
endDate, beginTime, endTime, routeId, serviceType, timePointsOnly, headsign,
144-
false, true, false, readOnly);
156+
endDate, beginTime, endTime, routeId, headsign, serviceType, timePointsOnly, DEFAULT_SCHEDULED_TIMES_ONLY,
157+
dwellTimeOnly, DEFAULT_INCLUDE_TRIP, includeStop, DEFAULT_INCLUDE_STOP_PATH, readOnly);
145158

146159
List<IpcStopWithDwellTime> stopsWithAvgDwellTime = new ArrayList<>();
147160

@@ -158,21 +171,23 @@ public List<IpcStopWithDwellTime> getStopsWithAvgDwellTimes(LocalDate beginDate,
158171
@Override
159172
public List<IpcStopPathWithSpeed> getStopPathsWithSpeed(LocalDate beginDate, LocalDate endDate,
160173
LocalTime beginTime, LocalTime endTime,
161-
String routeIdOrShortName, String headsign,
162-
boolean readOnly) throws Exception{
174+
String routeIdOrShortName, ServiceType serviceType,
175+
String headsign, boolean readOnly) throws Exception{
163176

164177
String routeId = null;
165-
166178
if(StringUtils.isNotBlank(routeIdOrShortName)){
167179
Route dbRoute = getRoute(routeIdOrShortName);
168180
if (dbRoute == null)
169181
return null;
170182
routeId = dbRoute.getId();
171183
}
172184

185+
boolean includeStopPath = true;
186+
173187
List<ArrivalDeparture> arrivalDeparturesList = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
174-
endDate, beginTime, endTime, routeId, null, false, headsign,
175-
false, false, true, readOnly);
188+
endDate, beginTime, endTime, routeId, headsign, serviceType, DEFAULT_TIME_POINTS_ONLY,
189+
DEFAULT_SCHEDULED_TIMES_ONLY, DEFAULT_DWELL_TIME_ONLY, DEFAULT_INCLUDE_TRIP, DEFAULT_INCLUDE_STOP,
190+
includeStopPath, readOnly);
176191

177192
Map<ArrivalDepartureTripKey, List<ArrivalDeparture>> resultsMap = new HashMap<>();
178193
Map<String, StopPath> stopPathsMap = new HashMap<>();
@@ -351,17 +366,19 @@ public IpcDoubleSummaryStatistics getAverageRunTime(LocalDate beginDate, LocalDa
351366
String headsign, boolean readOnly) throws Exception {
352367

353368
String routeId = null;
354-
355369
if(StringUtils.isNotBlank(routeIdOrShortName)){
356370
Route dbRoute = getRoute(routeIdOrShortName);
357371
if (dbRoute == null)
358372
return null;
359373
routeId = dbRoute.getId();
360374
}
361375

376+
boolean includeTrip = true;
377+
boolean scheduledTimesOnly = true;
378+
362379
List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
363-
endDate, beginTime, endTime, routeId, serviceType, timePointsOnly, headsign,
364-
true, false, false, readOnly);
380+
endDate, beginTime, endTime, routeId, headsign, serviceType, timePointsOnly, scheduledTimesOnly,
381+
DEFAULT_DWELL_TIME_ONLY, includeTrip, DEFAULT_INCLUDE_STOP, DEFAULT_INCLUDE_STOP_PATH, readOnly);
365382

366383
Map<TripDateKey, Long> runTimeByTripId = getRunTimeByTripId(arrivalDepartures);
367384

transitclockApi/src/main/java/org/transitclock/api/rootResources/ReportingApi.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public Response getArrivalDeparturesByRoute(
7777
serviceTypeEnum = ServiceType.valueOf(serviceType.toUpperCase());
7878
}
7979

80-
List<IpcArrivalDepartureScheduleAdherence> arrivalDepartures = reportingInterface.getArrivalsDeparturesForRoute(
80+
List<IpcArrivalDepartureScheduleAdherence> arrivalDepartures = reportingInterface.getArrivalsDeparturesForOtp(
8181
beginDate.getDate(), endDate.getDate(), beginTime.getTime(), endTime.getTime(), route,
8282
serviceTypeEnum, timePointsOnly, headsign,false);
8383

@@ -233,7 +233,9 @@ public Response getStopPathsSpeed(
233233
@Parameter(description="Retrives only arrivalDepartures belonging to the route name specified.",required=true)
234234
@QueryParam(value = "r") String route,
235235
@Parameter(description="Retrives only arrivalDepartures belonging to the headsign specified.",required=true)
236-
@QueryParam(value = "headsign") String headsign)
236+
@QueryParam(value = "headsign") String headsign,
237+
@Parameter(description="if set, retrives only arrivalDepartures belonging to the serviceType (Weekday, Saturday,Sunday",required=false)
238+
@QueryParam(value = "serviceType") String serviceType)
237239
throws WebApplicationException {
238240

239241
// Make sure request is valid
@@ -244,9 +246,15 @@ public Response getStopPathsSpeed(
244246
ReportingInterface reportingInterface =
245247
stdParameters.getReportingInterface();
246248

249+
ServiceType serviceTypeEnum = null;
250+
251+
if(StringUtils.isNotBlank(serviceType)){
252+
serviceTypeEnum = ServiceType.valueOf(serviceType.toUpperCase());
253+
}
254+
247255
List<IpcStopPathWithSpeed> stopPaths = reportingInterface.getStopPathsWithSpeed(
248256
beginDate.getDate(), endDate.getDate(), beginTime.getTime(), endTime.getTime(),
249-
route, headsign, false);
257+
route, serviceTypeEnum, headsign, false);
250258

251259
Object response = null;
252260

0 commit comments

Comments
 (0)