Search in sources :

Example 6 with VehicleStatus

use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImplTest method testVehicleSort.

@Test
public void testVehicleSort() {
    VehicleStatus vehicle1 = new VehicleStatus();
    vehicle1.setVehicleId("1");
    vehicle1.setInferredPhase("IN PROGRESS");
    vehicle1.setLastUpdate("2012-07-19T13:48:20.030Z");
    vehicle1.setObservedDSC("4411");
    vehicle1.setPulloutTime("2012-07-18T05:51:00-04:00");
    vehicle1.setPullinTime("2012-07-19T00:23:00-04:00");
    VehicleStatus vehicle2 = new VehicleStatus();
    vehicle2.setVehicleId("2");
    vehicle2.setInferredPhase("LAYOVER");
    vehicle2.setLastUpdate("2012-07-19T13:50:20.030Z");
    vehicle2.setObservedDSC("4412");
    vehicle2.setPulloutTime("2012-07-18T05:54:00-04:00");
    vehicle2.setPullinTime("2012-07-19T00:25:00-04:00");
    List<VehicleStatus> vehicleStatusRecords = new ArrayList<VehicleStatus>();
    vehicleStatusRecords.add(vehicle1);
    vehicleStatusRecords.add(vehicle2);
    service.sort(vehicleStatusRecords, "vehicleId", "asc");
    assertEquals("1", vehicleStatusRecords.get(0).getVehicleId());
    service.sort(vehicleStatusRecords, "vehicleId", "desc");
    assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
    service.sort(vehicleStatusRecords, "lastUpdate", "asc");
    assertEquals("2012-07-19T13:48:20.030Z", vehicleStatusRecords.get(0).getLastUpdate());
    service.sort(vehicleStatusRecords, "lastUpdate", "desc");
    assertEquals("2012-07-19T13:50:20.030Z", vehicleStatusRecords.get(0).getLastUpdate());
    service.sort(vehicleStatusRecords, "inferredPhase", "asc");
    assertEquals("IN PROGRESS", vehicleStatusRecords.get(0).getInferredPhase());
    service.sort(vehicleStatusRecords, "inferredPhase", "desc");
    assertEquals("LAYOVER", vehicleStatusRecords.get(0).getInferredPhase());
    service.sort(vehicleStatusRecords, "observedDSC", "asc");
    assertEquals("4411", vehicleStatusRecords.get(0).getObservedDSC());
    service.sort(vehicleStatusRecords, "observedDSC", "desc");
    assertEquals("4412", vehicleStatusRecords.get(0).getObservedDSC());
    service.sort(vehicleStatusRecords, "pulloutTime", "asc");
    assertEquals("2012-07-18T05:51:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
    service.sort(vehicleStatusRecords, "pulloutTime", "desc");
    assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
    service.sort(vehicleStatusRecords, "pullinTime", "asc");
    assertEquals("2012-07-19T00:23:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
    service.sort(vehicleStatusRecords, "pullinTime", "desc");
    assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
}
Also used : ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) Test(org.junit.Test)

Example 7 with VehicleStatus

use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImplTest method testVehicleStatusMismatchVehicle.

@Test
public void testVehicleStatusMismatchVehicle() {
    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\": 344," + "\"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-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" + "}],\"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(), "344");
    assertEquals("Mismatched inferred phase", vehicleStatus.getInferredPhase(), "IN PROGRESS");
    assertEquals("Mismatched observed DSC", vehicleStatus.getObservedDSC(), "4611");
    assertNull("No pull in time", vehicleStatus.getPullinTime());
    assertNull("No pull out time", vehicleStatus.getPulloutTime());
    assertEquals("Mismatched inferred destination information", vehicleStatus.getInferredDestination(), "4611:B61 Direction: 1");
    assertEquals("Mismatched status image", vehicleStatus.getStatus(), "circle_red18x18.png");
}
Also used : VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) Test(org.junit.Test)

Example 8 with VehicleStatus

use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleSearchServiceImpl method search.

@Override
public List<VehicleStatus> search(List<VehicleStatus> vehicleStatusRecords, Map<VehicleSearchParameters, String> searchParameters) {
    List<VehicleStatus> matchingRecords = new ArrayList<VehicleStatus>();
    // Build filters corresponding to the search parameters
    List<Filter<VehicleStatus>> filters = buildFilters(searchParameters);
    // Since there are no filters specified, return all the records as matched records
    if (filters.isEmpty()) {
        matchingRecords.addAll(vehicleStatusRecords);
    } else {
        // Apply each filter to each record
        for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
            boolean matches = applyFilters(vehicleStatus, filters);
            if (matches) {
                matchingRecords.add(vehicleStatus);
            }
        }
    }
    return matchingRecords;
}
Also used : PulloutStatusFilter(org.onebusaway.admin.search.impl.PulloutStatusFilter) Filter(org.onebusaway.admin.search.Filter) DepotFilter(org.onebusaway.admin.search.impl.DepotFilter) FormalInferrenceFilter(org.onebusaway.admin.search.impl.FormalInferrenceFilter) RouteFilter(org.onebusaway.admin.search.impl.RouteFilter) InferredPhaseFilter(org.onebusaway.admin.search.impl.InferredPhaseFilter) RevenueServiceFilter(org.onebusaway.admin.search.impl.RevenueServiceFilter) TimeWindowFilter(org.onebusaway.admin.search.impl.TimeWindowFilter) DSCFilter(org.onebusaway.admin.search.impl.DSCFilter) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter) VehicleIdFilter(org.onebusaway.admin.search.impl.VehicleIdFilter) ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus)

Example 9 with VehicleStatus

use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleSearchServiceImpl method searchVehiclesInEmergency.

@Override
public List<VehicleStatus> searchVehiclesInEmergency(List<VehicleStatus> vehicleStatusRecords) {
    Filter<VehicleStatus> emergencyFilter = new EmergencyStatusFilter();
    List<VehicleStatus> vehiclesInEmergency = new ArrayList<VehicleStatus>();
    for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
        if (emergencyFilter.apply(vehicleStatus)) {
            vehiclesInEmergency.add(vehicleStatus);
        }
    }
    return vehiclesInEmergency;
}
Also used : ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter)

Example 10 with VehicleStatus

use of org.onebusaway.admin.model.ui.VehicleStatus in project onebusaway-application-modules by camsys.

the class VehicleStatusServiceImpl method sort.

@Override
public void sort(List<VehicleStatus> vehiclesPerPage, String field, String order) {
    VehicleSortFields sortField = VehicleSortFields.valueOf(field.toUpperCase());
    Comparator<VehicleStatus> fieldComparator = null;
    switch(sortField) {
        case VEHICLEID:
            fieldComparator = new VehicleIdComparator(order);
            break;
        case LASTUPDATE:
            fieldComparator = new LastUpdateComparator(order);
            break;
        case INFERREDPHASE:
            fieldComparator = new InferredPhaseComparator(order);
            break;
        case OBSERVEDDSC:
            fieldComparator = new ObservedDSCComparator(order);
            break;
        case PULLOUTTIME:
            fieldComparator = new PulloutTimeComparator(order);
            break;
        case PULLINTIME:
            fieldComparator = new PullinTimeComparator(order);
            break;
        default:
            fieldComparator = new VehicleIdComparator(order);
            break;
    }
    Collections.sort(vehiclesPerPage, fieldComparator);
}
Also used : PullinTimeComparator(org.onebusaway.admin.comparator.PullinTimeComparator) InferredPhaseComparator(org.onebusaway.admin.comparator.InferredPhaseComparator) PulloutTimeComparator(org.onebusaway.admin.comparator.PulloutTimeComparator) LastUpdateComparator(org.onebusaway.admin.comparator.LastUpdateComparator) VehicleIdComparator(org.onebusaway.admin.comparator.VehicleIdComparator) VehicleSortFields(org.onebusaway.admin.util.VehicleSortFields) ObservedDSCComparator(org.onebusaway.admin.comparator.ObservedDSCComparator) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus)

Aggregations

VehicleStatus (org.onebusaway.admin.model.ui.VehicleStatus)14 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)4 EmergencyStatusFilter (org.onebusaway.admin.search.impl.EmergencyStatusFilter)3 RevenueServiceFilter (org.onebusaway.admin.search.impl.RevenueServiceFilter)3 TimeWindowFilter (org.onebusaway.admin.search.impl.TimeWindowFilter)3 Filter (org.onebusaway.admin.search.Filter)2 DSCFilter (org.onebusaway.admin.search.impl.DSCFilter)2 DepotFilter (org.onebusaway.admin.search.impl.DepotFilter)2 FormalInferrenceFilter (org.onebusaway.admin.search.impl.FormalInferrenceFilter)2 InferredPhaseFilter (org.onebusaway.admin.search.impl.InferredPhaseFilter)2 PulloutStatusFilter (org.onebusaway.admin.search.impl.PulloutStatusFilter)2 RouteFilter (org.onebusaway.admin.search.impl.RouteFilter)2 VehicleIdFilter (org.onebusaway.admin.search.impl.VehicleIdFilter)2 InferredPhaseComparator (org.onebusaway.admin.comparator.InferredPhaseComparator)1 LastUpdateComparator (org.onebusaway.admin.comparator.LastUpdateComparator)1 ObservedDSCComparator (org.onebusaway.admin.comparator.ObservedDSCComparator)1 PullinTimeComparator (org.onebusaway.admin.comparator.PullinTimeComparator)1 PulloutTimeComparator (org.onebusaway.admin.comparator.PulloutTimeComparator)1 VehicleIdComparator (org.onebusaway.admin.comparator.VehicleIdComparator)1