Search in sources :

Example 1 with VehicleStatus

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

the class VehicleSearchServiceImpl method searchVehiclesInRevenueService.

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

Example 2 with VehicleStatus

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

the class VehicleSearchServiceImpl method searchVehiclesTracked.

@Override
public List<VehicleStatus> searchVehiclesTracked(int minutes, List<VehicleStatus> vehicleStatusRecords) {
    Filter<VehicleStatus> timeWindowFilter = new TimeWindowFilter(minutes);
    List<VehicleStatus> vehiclesTracked = new ArrayList<VehicleStatus>();
    for (VehicleStatus vehicleStatus : vehicleStatusRecords) {
        if (timeWindowFilter.apply(vehicleStatus)) {
            vehiclesTracked.add(vehicleStatus);
        }
    }
    return vehiclesTracked;
}
Also used : TimeWindowFilter(org.onebusaway.admin.search.impl.TimeWindowFilter) ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus)

Example 3 with VehicleStatus

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

the class VehicleSearchServiceImpl method buildFilters.

private List<Filter<VehicleStatus>> buildFilters(Map<VehicleSearchParameters, String> searchParameters) {
    List<Filter<VehicleStatus>> filters = new ArrayList<Filter<VehicleStatus>>();
    // Since all parameters are optional we have to look for each one
    // To-do: there might be a better way of doing this
    String vehicleId = searchParameters.get(VehicleSearchParameters.VEHICLE_ID);
    if (StringUtils.isNotBlank(vehicleId)) {
        filters.add(new VehicleIdFilter(vehicleId));
    }
    String route = searchParameters.get(VehicleSearchParameters.ROUTE);
    if (StringUtils.isNotBlank(route)) {
        filters.add(new RouteFilter(route));
    }
    String inferredPhase = searchParameters.get(VehicleSearchParameters.INFERRED_PHASE);
    if (!inferredPhase.equalsIgnoreCase("All")) {
        filters.add(new InferredPhaseFilter(inferredPhase));
    }
    String dsc = searchParameters.get(VehicleSearchParameters.DSC);
    if (StringUtils.isNotBlank(dsc)) {
        filters.add(new DSCFilter(dsc));
    }
    String depot = searchParameters.get(VehicleSearchParameters.DEPOT);
    if (!depot.equalsIgnoreCase("All")) {
        filters.add(new DepotFilter(depot));
    }
    String pulloutStatus = searchParameters.get(VehicleSearchParameters.PULLOUT_STATUS);
    if (!pulloutStatus.equalsIgnoreCase("All")) {
        filters.add(new PulloutStatusFilter());
    }
    String emergencyStatus = searchParameters.get(VehicleSearchParameters.EMERGENCY_STATUS);
    if (emergencyStatus.equalsIgnoreCase("true")) {
        filters.add(new EmergencyStatusFilter());
    }
    String formalInferrence = searchParameters.get(VehicleSearchParameters.FORMAL_INFERRENCE);
    if (formalInferrence.equalsIgnoreCase("true")) {
        filters.add(new FormalInferrenceFilter());
    }
    return filters;
}
Also used : DepotFilter(org.onebusaway.admin.search.impl.DepotFilter) PulloutStatusFilter(org.onebusaway.admin.search.impl.PulloutStatusFilter) InferredPhaseFilter(org.onebusaway.admin.search.impl.InferredPhaseFilter) ArrayList(java.util.ArrayList) RouteFilter(org.onebusaway.admin.search.impl.RouteFilter) VehicleIdFilter(org.onebusaway.admin.search.impl.VehicleIdFilter) DSCFilter(org.onebusaway.admin.search.impl.DSCFilter) 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) FormalInferrenceFilter(org.onebusaway.admin.search.impl.FormalInferrenceFilter) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) EmergencyStatusFilter(org.onebusaway.admin.search.impl.EmergencyStatusFilter)

Example 4 with VehicleStatus

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

the class VehicleStatusServiceImpl method getVehicleStatus.

@Override
public List<VehicleStatus> getVehicleStatus(boolean loadNew) {
    List<VehicleStatus> vehicleStatusRecords = null;
    // Load new data only if asked explicitly
    if (loadNew) {
        VehicleStatusBuilder builder = new VehicleStatusBuilder();
        // get last known record data from operational API
        List<VehicleLastKnownRecord> vehicleLastKnownRecords = getLastKnownRecordData();
        // get vehicle pipo data
        Map<String, VehiclePullout> vehiclePullouts = getPulloutData();
        vehicleStatusRecords = new ArrayList<VehicleStatus>();
        // Build vehicle status objects by getting the required fields from both collections
        for (VehicleLastKnownRecord lastknownRecord : vehicleLastKnownRecords) {
            VehiclePullout pullout = vehiclePullouts.get(lastknownRecord.getVehicleId());
            VehicleStatus vehicleStatus = builder.buildVehicleStatus(pullout, lastknownRecord);
            vehicleStatusRecords.add(vehicleStatus);
        }
        // Add these records to the cache
        cache.add(vehicleStatusRecords);
    } else {
        // return data from the cache to improve performance
        vehicleStatusRecords = cache.fetch();
    }
    return vehicleStatusRecords;
}
Also used : VehicleStatusBuilder(org.onebusaway.admin.util.VehicleStatusBuilder) VehiclePullout(org.onebusaway.admin.model.json.VehiclePullout) VehicleLastKnownRecord(org.onebusaway.admin.model.json.VehicleLastKnownRecord) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus)

Example 5 with VehicleStatus

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

the class VehicleStatusServiceImplTest method testSortBlankPulloutFields.

@Test
public void testSortBlankPulloutFields() {
    VehicleStatus vehicle1 = new VehicleStatus();
    vehicle1.setVehicleId("1");
    vehicle1.setInferredPhase("IN PROGRESS");
    vehicle1.setLastUpdate("2012-07-19T13:48:20.030Z");
    vehicle1.setObservedDSC("4411");
    vehicle1.setPulloutTime("");
    vehicle1.setPullinTime("");
    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, "pulloutTime", "asc");
    assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
    assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
    service.sort(vehicleStatusRecords, "pulloutTime", "desc");
    assertEquals("2012-07-18T05:54:00-04:00", vehicleStatusRecords.get(0).getPulloutTime());
    assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
    service.sort(vehicleStatusRecords, "pullinTime", "asc");
    assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
    assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
    service.sort(vehicleStatusRecords, "pullinTime", "desc");
    assertEquals("2012-07-19T00:25:00-04:00", vehicleStatusRecords.get(0).getPullinTime());
    assertEquals("2", vehicleStatusRecords.get(0).getVehicleId());
}
Also used : ArrayList(java.util.ArrayList) VehicleStatus(org.onebusaway.admin.model.ui.VehicleStatus) Test(org.junit.Test)

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