Skip to content

Commit

Permalink
Merge pull request #142 from vsperez/tc_issue_122_2
Browse files Browse the repository at this point in the history
Tc issue 122 2
  • Loading branch information
scrudden authored Jun 7, 2019
2 parents 3eac868 + aa9f739 commit 1271d36
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.transitclock.core.SpatialMatch;
import org.transitclock.core.TemporalDifference;
import org.transitclock.core.VehicleState;
import org.transitclock.db.structs.HoldingTime;
import org.transitclock.db.structs.Trip;
import org.transitclock.utils.Geo;
import org.transitclock.utils.Time;
Expand All @@ -48,9 +47,9 @@ public class IpcVehicleComplete extends IpcVehicleGtfsRealtime {

private final String originStopId;
private final String destinationId;
private final double distanceToNextStop;
private final double distanceOfNextStopFromTripStart;
private final double distanceAlongTrip;
private final Double distanceToNextStop;
private final Double distanceOfNextStopFromTripStart;
private final Double distanceAlongTrip;
private double headway;

private static final long serialVersionUID = 8154105842499551461L;
Expand Down Expand Up @@ -99,9 +98,9 @@ public IpcVehicleComplete(VehicleState vs) {
// Vehicle not assigned to trip so null out parameters
this.originStopId = null;
this.destinationId = null;
this.distanceToNextStop = Double.NaN;
this.distanceOfNextStopFromTripStart = Double.NaN;
this.distanceAlongTrip = Double.NaN;
this.distanceToNextStop =null; //Double.NaN;
this.distanceOfNextStopFromTripStart =null;// Double.NaN;
this.distanceAlongTrip =null; // Double.NaN;
}
}

Expand Down Expand Up @@ -148,9 +147,9 @@ private IpcVehicleComplete(String blockId,
String nextStopId, String nextStopName, String vehicleType,
long tripStartEpochTime, boolean atStop, String atOrNextStopId,
Integer atOrNextGtfsStopSeq, String originStopId,
String destinationId, double distanceToNextStop,
String destinationId, Double distanceToNextStop,

double distanceOfNextStopFromTripStart, double distanceAlongTrip, long freqStartTime, IpcHoldingTime holdingTime, double predictedLatitude, double predictedLongitude,boolean isCanceled,
Double distanceOfNextStopFromTripStart, Double distanceAlongTrip, long freqStartTime, IpcHoldingTime holdingTime, double predictedLatitude, double predictedLongitude,boolean isCanceled,
double headway) {

super(blockId, blockAssignmentMethod, avl, pathHeading, routeId,
Expand Down Expand Up @@ -178,9 +177,9 @@ protected static class CompleteVehicleSerializationProxy
// Exact copy of fields of IpcCompleteVehicle enclosing class object
private String originStopId;
private String destinationId;
private double distanceToNextStop;
private double distanceOfNextStopFromTripStart;
private double distanceAlongTrip;
private Double distanceToNextStop;
private Double distanceOfNextStopFromTripStart;
private Double distanceAlongTrip;
private double headway;
private static final short currentSerializationVersion = 0;

Expand Down Expand Up @@ -212,9 +211,9 @@ protected void writeObject(java.io.ObjectOutputStream stream)

stream.writeObject(originStopId);
stream.writeObject(destinationId);
stream.writeDouble(distanceToNextStop);
stream.writeDouble(distanceOfNextStopFromTripStart);
stream.writeDouble(distanceAlongTrip);
stream.writeObject(distanceToNextStop);
stream.writeObject(distanceOfNextStopFromTripStart);
stream.writeObject(distanceAlongTrip);
stream.writeDouble(headway);
}

Expand All @@ -240,9 +239,9 @@ protected void readObject(java.io.ObjectInputStream stream)
// Read in data for this class
originStopId = (String) stream.readObject();
destinationId = (String) stream.readObject();
distanceToNextStop = stream.readDouble();
distanceOfNextStopFromTripStart = stream.readDouble();
distanceAlongTrip = stream.readDouble();
distanceToNextStop = (Double)stream.readObject();
distanceOfNextStopFromTripStart = (Double)stream.readObject();
distanceAlongTrip =(Double) stream.readObject();
isCanceled=stream.readBoolean();
headway=stream.readDouble();
}
Expand Down Expand Up @@ -296,15 +295,15 @@ public String getDestinationId() {
return destinationId;
}

public double getDistanceToNextStop() {
public Double getDistanceToNextStop() {
return distanceToNextStop;
}

public double getDistanceOfNextStopFromTripStart() {
public Double getDistanceOfNextStopFromTripStart() {
return distanceOfNextStopFromTripStart;
}

public double getDistanceAlongTrip() {
public Double getDistanceAlongTrip() {
return distanceAlongTrip;
}
public double getHeadway()
Expand Down
21 changes: 21 additions & 0 deletions transitclock/src/main/java/org/transitclock/utils/Geo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ public static String distanceFormat(double arg) {
return twoDigitFormat.format(arg) + "m";
}

/**
* For formatting distances in meters to consistent 2 decimal places.
* Appends "m" to indicate units.
*
* @param arg
* @return
*/
public static String distanceFormat(Double arg) {
// Handle NaN and other special cases
if (arg == null)
return "null";
if (arg.isNaN())
return "NaN";
if (arg == Double.MAX_VALUE)
return "Double.MAX_VALUE";

// Not a special case so output the value with just two digits
// past decimal place and append "m" to indicate meters.
return twoDigitFormat.format(arg) + "m";
}

/**
* Outputs arg with just a single digit. No other formatting is done.
* Useful when want to output speed or heading but don't want to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public ApiVehicleDetails(IpcVehicle vehicle, Time timeForAgency, UiMode... uiTyp
licensePlate=vehicle.getLicensePlate();
isCanceled=false;
headway=-1;
if(vehicle instanceof IpcVehicleComplete )
if(vehicle instanceof IpcVehicleComplete && tripId!=null )
{
distanceAlongTrip=((IpcVehicleComplete)vehicle).getDistanceAlongTrip();
isCanceled=((IpcVehicleComplete)vehicle).isCanceled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ protected ApiVehiclesDetails() {
* @param uiTypesForVehicles
* Specifies how vehicles should be drawn in UI. Can be NORMAL,
* SECONDARY, or MINOR
* @param assigned
* @throws InvocationTargetException
* @throws IllegalAccessException
*/
public ApiVehiclesDetails(Collection<IpcVehicle> vehicles,
String agencyId, Map<String, UiMode> uiTypesForVehicles) throws IllegalAccessException, InvocationTargetException {
String agencyId, Map<String, UiMode> uiTypesForVehicles, boolean assigned) throws IllegalAccessException, InvocationTargetException {
// Get Time object based on timezone for agency
WebAgency webAgency = WebAgency.getCachedWebAgency(agencyId);
Agency agency = webAgency.getAgency();
Expand All @@ -79,7 +80,7 @@ public ApiVehiclesDetails(Collection<IpcVehicle> vehicles,
for (IpcVehicle vehicle : vehicles) {
// Determine UI type for vehicle
UiMode uiType = uiTypesForVehicles.get(vehicle.getId());

if((assigned && vehicle.getTripId()!=null ) || !assigned)
vehiclesData.add(new ApiVehicleDetails(vehicle, timeForAgency,
uiType));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public Response getVehicleLocation(@BeanParam StandardParameters stdParameters,
+ " adherence and driver IDs.",tags= {"vehicle"})
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getVehiclesDetails(@BeanParam StandardParameters stdParameters,
@Parameter(description="Specifies which vehicles to get data for",required=true)
@Parameter(description="Specifies which vehicles to get data for",required=false)
@QueryParam(value = "v") List<String> vehicleIds,
@Parameter(description="Specifies which routes to get data for",required=false)
@QueryParam(value = "r") List<String> routesIdOrShortNames,
Expand All @@ -306,7 +306,12 @@ public Response getVehiclesDetails(@BeanParam StandardParameters stdParameters,
@QueryParam(value = "s") String stopId,
@Parameter(description=" For when determining which vehicles are generating the"
+ "predictions so can label minor vehicles",required=false)@QueryParam(value = "numPreds")
@DefaultValue("3") int numberPredictions) throws WebApplicationException {
@DefaultValue("3") int numberPredictions
,
@Parameter(description=" Return only assigned vehicles",required=false)@QueryParam(value = "onlyAssigned")
@DefaultValue("false") boolean onlyAssigned

) throws WebApplicationException {
// Make sure request is valid
stdParameters.validate();

Expand Down Expand Up @@ -337,7 +342,7 @@ public Response getVehiclesDetails(@BeanParam StandardParameters stdParameters,

// Convert IpcVehiclesDetails to ApiVehiclesDetails
ApiVehiclesDetails apiVehiclesDetails = new ApiVehiclesDetails(vehicles, stdParameters.getAgencyId(),
uiTypesForVehicles);
uiTypesForVehicles,onlyAssigned);

// return ApiVehiclesDetails response
Response result = null;
Expand Down
2 changes: 1 addition & 1 deletion transitclockWebapp/src/main/webapp/maps/schAdhMap.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getVehiclePopupContent(vehicle) {
*/
function getAndProcessSchAdhData() {
// Do API call to get schedule adherence data
$.getJSON(apiUrlPrefix + "/command/vehiclesDetails",
$.getJSON(apiUrlPrefix + "/command/vehiclesDetails?onlyAssigned=true",
// Process data
function(jsonData) {
var newVehicleLayer = L.featureGroup();
Expand Down
16 changes: 14 additions & 2 deletions transitclockWebapp/src/main/webapp/synoptic/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,13 @@ function vehicleUpdate(vehicleDetail, status)
console.log("i: "+i);
vehicle=vehicleDetail.vehicles[i];
console.log(vehicle);
var directionVehicle=(vehicle.direction=="0")?0:1;
//if(vehicle.direction==undefined)
// vehicle.direction=="0";
var directionVehicle=(vehicle.direction=="0" || vehicle.direction==undefined)?0:1;
var _identifier=(vehicle.licensePlate==undefined)?vehicle.id:vehicle.licensePlate;
var gpsTimeStr = dateFormat(vehicle.loc.time);
buses.push({id:vehicle.id, projection:vehicle.distanceAlongTrip/getShapeLength(vehicle.tripPattern),identifier:vehicle.licensePlate,direction:directionVehicle,gpsTimeStr:gpsTimeStr,nextStopName:vehicle.nextStopName,schAdhStr:vehicle.schAdhStr,trip:vehicle.trip,schAdh:vehicle.schAdh,headway:vehicle.headway});
buses.push({id:vehicle.id, projection:vehicle.distanceAlongTrip/getShapeLength(vehicle.tripPattern),identifier:_identifier,direction:directionVehicle,gpsTimeStr:gpsTimeStr,nextStopName:vehicle.nextStopName,schAdhStr:vehicle.schAdhStr,trip:vehicle.trip,schAdh:vehicle.schAdh,headway:vehicle.headway});
}
synoptic.setBuses(buses);
synoptic.steps=100;
Expand Down Expand Up @@ -267,8 +271,11 @@ function routeConfigCallback(routeDetail, status)
setShortNameParam(routeDetail.routes[0].shortName);
for(var i in routeDetail.routes[0].direction)
{
//console.log(routeDetail.routes[0].direction[i]);
console.log("Direction "+routeDetail.routes[0].direction[i].id);
console.log(routeDetail.routes[0].direction[i]);
if(routeDetail.routes[0].direction[i]==undefined)
routeDetail.routes[0].direction[i]="0";
var distanceOverPath=0.0;
var routeLenght=-1;
Expand Down Expand Up @@ -304,7 +311,11 @@ function routeConfigCallback(routeDetail, status)
}
setShapeMapLenght(shapeMap);
synoptic=null;
var canvas = document.getElementById("synoptic");
while (canvas.firstChild) {
canvas.removeChild(canvas.firstChild);
}
var params={container:canvas,
onVehiClick:testFunc,
infoStop:function(data) {console.log(data.identifier);return "<table class=\"table\"><th >"+data.identifier+"</th><tr><td>distance: "+parseFloat(data.distance).toFixed(2) +" m. </td></tr></table>"},
Expand All @@ -315,6 +326,7 @@ function routeConfigCallback(routeDetail, status)
predictionFunction:getPredictionsJson,
vehicleAlternColorCallBack:vehicleAlternColorCallBack
}
synoptic=new Sinoptico(params);
synoptic.setStops(stops);
synoptic.setBuses(buses);
Expand Down

0 comments on commit 1271d36

Please sign in to comment.