use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method getVehicleStatistics.
@Override
public VehicleStatistics getVehicleStatistics(String... parameters) {
VehicleStatistics statistics = new VehicleStatistics();
List<VehicleStatus> vehicleStatusRecords = cache.fetch();
if (vehicleStatusRecords.isEmpty()) {
// this should ideally never happen as statistics call should trigger after data
// is loaded in the grid. Still get the records from web services if cache is empty to be
// safe
vehicleStatusRecords = getVehicleStatus(true);
}
List<VehicleStatus> vehiclesInEmergency = vehicleSearchService.searchVehiclesInEmergency(vehicleStatusRecords);
List<VehicleStatus> vehiclesInRevenueService = vehicleSearchService.searchVehiclesInRevenueService(vehicleStatusRecords);
List<VehicleStatus> vehiclesTracked = vehicleSearchService.searchVehiclesTracked(5, vehicleStatusRecords);
statistics.setVehiclesInEmergency(vehiclesInEmergency.size());
statistics.setVehiclesInRevenueService(vehiclesInRevenueService.size());
statistics.setVehiclesTracked(vehiclesTracked.size());
return statistics;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleSearchServiceImplTest method buildVehicleStatusRecords.
private List<VehicleStatus> buildVehicleStatusRecords() {
List<VehicleStatus> vehicleStatusRecords = new ArrayList<VehicleStatus>();
VehicleStatus vehicle1 = mock(VehicleStatus.class);
when(vehicle1.getVehicleId()).thenReturn("242");
when(vehicle1.getRoute()).thenReturn("B63");
when(vehicle1.getInferredPhase()).thenReturn("IN PROGRESS");
when(vehicle1.getObservedDSC()).thenReturn("436");
when(vehicle1.getEmergencyStatus()).thenReturn("");
when(vehicle1.isInferrenceFormal()).thenReturn(false);
VehicleStatus vehicle2 = mock(VehicleStatus.class);
when(vehicle2.getVehicleId()).thenReturn("243");
when(vehicle2.getRoute()).thenReturn("B62");
when(vehicle2.getInferredPhase()).thenReturn("IN PROGRESS");
when(vehicle2.getObservedDSC()).thenReturn("437");
when(vehicle2.getEmergencyStatus()).thenReturn(" ");
when(vehicle2.isInferrenceFormal()).thenReturn(true);
VehicleStatus vehicle3 = mock(VehicleStatus.class);
when(vehicle3.getVehicleId()).thenReturn("244");
when(vehicle3.getRoute()).thenReturn("B63");
when(vehicle3.getInferredPhase()).thenReturn("DEADHEAD");
when(vehicle3.getObservedDSC()).thenReturn("437");
when(vehicle3.getEmergencyStatus()).thenReturn("1");
when(vehicle3.isInferrenceFormal()).thenReturn(true);
vehicleStatusRecords.add(vehicle1);
vehicleStatusRecords.add(vehicle2);
vehicleStatusRecords.add(vehicle3);
return vehicleStatusRecords;
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImplTest method testGetVehicleStatus.
@Test
public void testGetVehicleStatus() {
String pulloutData = "{\"pullouts\":[{\"vehicle-id\":\"5638\"," + "\"agency-id-tcip\":\"2008\",\"agency-id\":\"MTA NYCT\",\"depot\":\"OS\"," + "\"service-date\":\"2012-07-18\",\"pullout-time\":\"2012-07-18T05:51:00-04:00\"," + "\"run\":\"M15-012\",\"operator-id\":\"1663\",\"pullin-time\":\"2012-07-19T00:23:00-04:00\"" + "}],\"status\":\"OK\"}";
String lastKnownData = "{\"records\":[{" + "\"uuid\": \"67f843e0-d1a8-11e1-8614-123139243533\"," + "\"vehicle-agency-id\": 2008," + "\"time-reported\": \"2012-07-19T13:48:20.030Z\"," + "\"time-received\": \"2012-07-19T13:48:22.686Z\"," + "\"archive-time-received\": \"2012-07-19T13:48:24.657Z\"," + "\"operator-id-designator\": \"913450\"," + "\"route-id-designator\": \"61\"," + "\"run-id-designator\": \"144\"," + "\"dest-sign-code\": 4611," + "\"latitude\": 40.683021," + "\"longitude\": -74.003720," + "\"speed\": 16.0," + "\"direction-deg\": 207.72," + "\"agency-id\": \"MTA NYCT\"," + "\"vehicle-id\": 5638," + "\"depot-id\": \"JG\"," + "\"service-date\": \"2012-07-19\"," + "\"inferred-run-id\": \"B61-14\"," + "\"inferred-block-id\": \"MTA NYCT_20120701CC_JG_22200_B61-14-JG_1972\"," + "\"inferred-trip-id\": \"MTA NYCT_20120701CC_057500_B61_0103_B61_14\"," + "\"inferred-route-id\": \"MTA NYCT_B61\"," + "\"inferred-direction-id\": \"1\"," + "\"inferred-dest-sign-code\": 4611," + "\"inferred-latitude\": 40.683001," + "\"inferred-longitude\": -74.003678," + "\"inferred-phase\": \"IN_PROGRESS\"," + "\"inferred-status\": \"default\"," + "\"inference-is-formal\": false," + "\"distance-along-block\": 30650.503480107127," + "\"distance-along-trip\": 2374.6309121986087," + "\"next-scheduled-stop-id\": \"MTA NYCT_305226\"," + "\"next-scheduled-stop-distance\": 26.791625996334915," + "\"emergency-code\": \"1\"" + "}],\"status\":\"OK\"}";
when(remoteConnectionService.getContent("http://tdm.dev.obanyc.com/api/pullouts/list")).thenReturn(pulloutData);
when(configurationService.getConfigurationValueAsString("operational-api.host", "archive")).thenReturn("archive.dev.obanyc.com");
when(remoteConnectionService.getContent("http://archive.dev.obanyc.com/api/record/last-known/list")).thenReturn(lastKnownData);
List<VehicleStatus> vehicleStatusRecords = service.getVehicleStatus(true);
VehicleStatus vehicleStatus = vehicleStatusRecords.get(0);
assertEquals("Mismatched vehicle id", vehicleStatus.getVehicleId(), "5638");
assertEquals("Mismatched inferred phase", vehicleStatus.getInferredPhase(), "IN PROGRESS");
assertEquals("Mismatched observed DSC", vehicleStatus.getObservedDSC(), "4611");
// This has a dependency on Easter Time!
assertEquals("Mismatched pull in time", vehicleStatus.getFormattedPullinTime(), "00:23 +1 day");
assertEquals("Mismatched pull out time", vehicleStatus.getFormattedPulloutTime(), "05:51");
assertEquals("Mismatched inferred DSC", vehicleStatus.getInferredDestination(), "4611:B61 Direction: 1");
assertEquals("Mismatched status image", vehicleStatus.getStatus(), "circle_orange_alert_18x18.png");
assertEquals("Mismatched emergency status", vehicleStatus.getEmergencyStatus(), "1");
}
use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.
the class VehicleStatusBuilder method buildVehicleStatus.
public VehicleStatus buildVehicleStatus(VehiclePullout pullout, VehicleLastKnownRecord lastknownRecord) {
VehicleStatus vehicleStatus = new VehicleStatus();
if (pullout != null) {
// Set the actual times for filtering
vehicleStatus.setPullinTime(pullout.getPullinTime());
vehicleStatus.setPulloutTime(pullout.getPulloutTime());
// Set formatted time for display
vehicleStatus.setFormattedPullinTime(getPullinTime(pullout.getPulloutTime(), pullout.getPullinTime()));
vehicleStatus.setFormattedPulloutTime(extractTime(pullout.getPulloutTime()));
}
vehicleStatus.setVehicleId(lastknownRecord.getVehicleId());
String inferredDestination = getInferredDestination(lastknownRecord);
vehicleStatus.setInferredDestination(inferredDestination);
vehicleStatus.setInferredPhase(getInferredPhase(lastknownRecord));
vehicleStatus.setObservedDSC(lastknownRecord.getDestinationSignCode());
vehicleStatus.setDetails(lastknownRecord.getVehicleId());
vehicleStatus.setRoute(getRoute(lastknownRecord.getInferredRouteId()));
vehicleStatus.setDepot(lastknownRecord.getDepotId());
vehicleStatus.setEmergencyStatus(lastknownRecord.getEmergencyCode());
vehicleStatus.setLastUpdate(getLastUpdate(lastknownRecord.getTimeReported()));
vehicleStatus.setStatus(getStatus(lastknownRecord.getInferredPhase(), lastknownRecord.getTimeReported(), lastknownRecord.getEmergencyCode(), lastknownRecord.getInferredTripId()));
vehicleStatus.setInferredDSC(lastknownRecord.getInferredDSC());
vehicleStatus.setTimeReported(lastknownRecord.getTimeReported());
vehicleStatus.setInferrenceFormal(lastknownRecord.isInferrenceFormal());
return vehicleStatus;
}
Aggregations