Skip to content

Commit

Permalink
Merge pull request #2 from camsys/feature/speed_map
Browse files Browse the repository at this point in the history
Feature/speed map
  • Loading branch information
AlexAndradeCS authored Aug 4, 2020
2 parents db8d463 + cae15fc commit 2c93c98
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -974,8 +974,9 @@ public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(
*/
public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime,
String routeId, ServiceType serviceType,
boolean timePointsOnly, String headsign,
String routeId, String headsign,
ServiceType serviceType, boolean timePointsOnly,
boolean scheduledTimesOnly, boolean dwellTimeOnly,
boolean includeTrip, boolean includeStop,
boolean includeStopPath, boolean readOnly) throws Exception {
IntervalTimer timer = new IntervalTimer();
Expand All @@ -998,11 +999,13 @@ public static List<ArrivalDeparture> getArrivalsDeparturesFromDb(LocalDate begin
"WHERE " +
getArrivalDepartureTimeWhere(beginDate, endDate, beginTime, endTime) +
getRouteIdWhere(routeId) +
getScheduledTimesWhere(scheduledTimesOnly) +
getTimePointsWhere(timePointsOnly) +
getServiceTypeWhere(serviceType) +
getTripsWhere(headsign) +
getStopsWhere(includeStop) +
getStopPathsWhere(includeStopPath);
getStopPathsWhere(includeStopPath) +
getDwellTimesWhere(dwellTimeOnly);

try {
Query query = session.createQuery(hql);
Expand Down Expand Up @@ -1055,13 +1058,12 @@ private static String getStopsJoin(boolean includeStop){
}

private static String getTripsJoin(String headsign, boolean includeTrip){
if(StringUtils.isNotBlank(headsign)){
if(includeTrip){
return " JOIN FETCH ad.trip t ";
}else {
return ", Trip t ";
}
if(includeTrip){
return " JOIN FETCH ad.trip t ";
}else if(StringUtils.isNotBlank(headsign)){
return ", Trip t ";
}

return "";
}

Expand Down Expand Up @@ -1109,6 +1111,13 @@ private static String getRouteIdWhere(String routeId){
return "";
}

private static String getScheduledTimesWhere(boolean scheduledTimesOnly){
if(scheduledTimesOnly){
return "AND ad.scheduledTime IS NOT NULL ";
}
return "";
}

private static String getTimePointsWhere(boolean timePointsOnly){
if(timePointsOnly){
return "AND ad.configRev = sp.configRev AND ad.stopId = sp.stopId AND ad.tripPatternId = sp.tripPatternId AND sp.scheduleAdherenceStop = true ";
Expand Down Expand Up @@ -1151,6 +1160,13 @@ private static String getStopPathsWhere(boolean includeStopPaths){
}
return "";
}

private static String getDwellTimesWhere(boolean dwellTimesOnly){
if(dwellTimesOnly){
return "AND ad.dwellTime != null ";
}
return "";
}

public String getVehicleId() {
return vehicleId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*
*/
public interface ReportingInterface extends Remote {
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(LocalDate beginDate, LocalDate endDate,
List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, ServiceType serviceType,
boolean timePointsOnly, String headsign) throws Exception;

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

List<IpcStopPathWithSpeed> getStopPathsWithSpeed(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, String headsign, boolean readOnly) throws Exception;
String routeIdOrShortName, ServiceType serviceType,
String headsign, boolean readOnly) throws Exception;

IpcDoubleSummaryStatistics getAverageRunTime(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime, String routeIdOrShortName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
*/
public class ReportingServer extends AbstractServer implements ReportingInterface {

private final boolean DEFAULT_TIME_POINTS_ONLY = false;
private final boolean DEFAULT_SCHEDULED_TIMES_ONLY = false;
private final boolean DEFAULT_DWELL_TIME_ONLY = false;
private final boolean DEFAULT_INCLUDE_TRIP = false;
private final boolean DEFAULT_INCLUDE_STOP = false;
private final boolean DEFAULT_INCLUDE_STOP_PATH = false;
private final ServiceType DEFAULT_SERVICE_TYPE = null;

private static int getMaxSchedAdh() {
return maxSchedAdhSec.getValue();
}
Expand Down Expand Up @@ -88,21 +96,22 @@ public static ReportingServer start(String agencyId) {
}

@Override
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(
LocalDate beginDate, LocalDate endDate, LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, ServiceType serviceType,
boolean timePointsOnly, String headsign) throws Exception{
return getArrivalsDeparturesForRoute(beginDate, endDate, beginTime, endTime, routeIdOrShortName, serviceType,
return getArrivalsDeparturesForOtp(beginDate, endDate, beginTime, endTime, routeIdOrShortName, serviceType,
timePointsOnly, headsign, false);
}

@Override
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForRoute(
public List<IpcArrivalDepartureScheduleAdherence> getArrivalsDeparturesForOtp(
LocalDate beginDate, LocalDate endDate, LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, ServiceType serviceType, boolean timePointsOnly,
String headsign, boolean readOnly) throws Exception {

String routeId = null;
boolean scheduledStopsOnly = true;

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

List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate, endDate,
beginTime, endTime, routeId, serviceType, timePointsOnly,
headsign, false, false, false, readOnly);
beginTime, endTime, routeId, headsign, serviceType, timePointsOnly,
scheduledStopsOnly,DEFAULT_DWELL_TIME_ONLY, DEFAULT_INCLUDE_TRIP,
DEFAULT_INCLUDE_STOP, DEFAULT_INCLUDE_STOP_PATH, readOnly);

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

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

@Override
public List<IpcStopWithDwellTime> getStopsWithAvgDwellTimes(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime, String routeIdOrShortName,
ServiceType serviceType, boolean timePointsOnly,
String headsign, boolean readOnly) throws Exception {
LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, ServiceType serviceType,
boolean timePointsOnly, String headsign,
boolean readOnly) throws Exception {

String routeId = null;

if(StringUtils.isNotBlank(routeIdOrShortName)){
Route dbRoute = getRoute(routeIdOrShortName);
if (dbRoute == null)
return null;
routeId = dbRoute.getId();
}

boolean dwellTimeOnly = true;
boolean includeStop = true;

List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
endDate, beginTime, endTime, routeId, serviceType, timePointsOnly, headsign,
false, true, false, readOnly);
endDate, beginTime, endTime, routeId, headsign, serviceType, timePointsOnly, DEFAULT_SCHEDULED_TIMES_ONLY,
dwellTimeOnly, DEFAULT_INCLUDE_TRIP, includeStop, DEFAULT_INCLUDE_STOP_PATH, readOnly);

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

Expand All @@ -158,21 +171,23 @@ public List<IpcStopWithDwellTime> getStopsWithAvgDwellTimes(LocalDate beginDate,
@Override
public List<IpcStopPathWithSpeed> getStopPathsWithSpeed(LocalDate beginDate, LocalDate endDate,
LocalTime beginTime, LocalTime endTime,
String routeIdOrShortName, String headsign,
boolean readOnly) throws Exception{
String routeIdOrShortName, ServiceType serviceType,
String headsign, boolean readOnly) throws Exception{

String routeId = null;

if(StringUtils.isNotBlank(routeIdOrShortName)){
Route dbRoute = getRoute(routeIdOrShortName);
if (dbRoute == null)
return null;
routeId = dbRoute.getId();
}

boolean includeStopPath = true;

List<ArrivalDeparture> arrivalDeparturesList = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
endDate, beginTime, endTime, routeId, null, false, headsign,
false, false, true, readOnly);
endDate, beginTime, endTime, routeId, headsign, serviceType, DEFAULT_TIME_POINTS_ONLY,
DEFAULT_SCHEDULED_TIMES_ONLY, DEFAULT_DWELL_TIME_ONLY, DEFAULT_INCLUDE_TRIP, DEFAULT_INCLUDE_STOP,
includeStopPath, readOnly);

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

String routeId = null;

if(StringUtils.isNotBlank(routeIdOrShortName)){
Route dbRoute = getRoute(routeIdOrShortName);
if (dbRoute == null)
return null;
routeId = dbRoute.getId();
}

boolean includeTrip = true;
boolean scheduledTimesOnly = true;

List<ArrivalDeparture> arrivalDepartures = ArrivalDeparture.getArrivalsDeparturesFromDb(beginDate,
endDate, beginTime, endTime, routeId, serviceType, timePointsOnly, headsign,
true, false, false, readOnly);
endDate, beginTime, endTime, routeId, headsign, serviceType, timePointsOnly, scheduledTimesOnly,
DEFAULT_DWELL_TIME_ONLY, includeTrip, DEFAULT_INCLUDE_STOP, DEFAULT_INCLUDE_STOP_PATH, readOnly);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Response getArrivalDeparturesByRoute(
serviceTypeEnum = ServiceType.valueOf(serviceType.toUpperCase());
}

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

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

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

ServiceType serviceTypeEnum = null;

if(StringUtils.isNotBlank(serviceType)){
serviceTypeEnum = ServiceType.valueOf(serviceType.toUpperCase());
}

List<IpcStopPathWithSpeed> stopPaths = reportingInterface.getStopPathsWithSpeed(
beginDate.getDate(), endDate.getDate(), beginTime.getTime(), endTime.getTime(),
route, headsign, false);
route, serviceTypeEnum, headsign, false);

Object response = null;

Expand Down

0 comments on commit 2c93c98

Please sign in to comment.