use of org.onebusaway.admin.model.ui.DataValidationStopCt in project onebusaway-application-modules by camsys.
the class CompareBundlesAction method compareDirections.
private DataValidationDirectionCts compareDirections(DataValidationDirectionCts currentDirection, DataValidationDirectionCts selectedDirection) {
DataValidationDirectionCts diffDirection = new DataValidationDirectionCts();
diffDirection.setDirection(currentDirection.getDirection());
diffDirection.setStopCounts(new TreeSet<DataValidationStopCt>());
for (DataValidationStopCt currentStopCt : currentDirection.getStopCounts()) {
boolean stopCtMatched = false;
// Check if this stop count exists in selectedMode
for (DataValidationStopCt selectedStopCt : selectedDirection.getStopCounts()) {
if (currentStopCt.getStopCt() == selectedStopCt.getStopCt()) {
stopCtMatched = true;
selectedDirection.getStopCounts().remove(selectedStopCt);
if ((currentStopCt.getTripCts()[0] != selectedStopCt.getTripCts()[0]) || (currentStopCt.getTripCts()[1] != selectedStopCt.getTripCts()[1]) || (currentStopCt.getTripCts()[2] != selectedStopCt.getTripCts()[2])) {
currentStopCt.setSrcCode("1");
diffDirection.getStopCounts().add(currentStopCt);
selectedStopCt.setSrcCode("2");
diffDirection.getStopCounts().add(selectedStopCt);
}
break;
}
}
if (stopCtMatched) {
continue;
} else {
currentStopCt.setSrcCode("1");
diffDirection.getStopCounts().add(currentStopCt);
}
}
if (selectedDirection.getStopCounts().size() > 0) {
for (DataValidationStopCt selectedStopCt : selectedDirection.getStopCounts()) {
selectedStopCt.setSrcCode("2");
diffDirection.getStopCounts().add(selectedStopCt);
}
}
return diffDirection;
}
use of org.onebusaway.admin.model.ui.DataValidationStopCt in project onebusaway-application-modules by camsys.
the class CompareBundlesAction method buildModes.
private List<DataValidationMode> buildModes(int buildId) {
List<DataValidationMode> modes = new ArrayList<>();
// Check service ids
List<ArchivedCalendar> calendars = _gtfsArchiveService.getAllCalendarsByBundleId(buildId);
// Get dates for checking trips for days of the week
LocalDate startDate = getStartDate(calendars);
LocalDate firstMon = getFirstDay(DateTimeConstants.MONDAY, startDate);
LocalDate firstTues = getFirstDay(DateTimeConstants.TUESDAY, startDate);
LocalDate firstWed = getFirstDay(DateTimeConstants.WEDNESDAY, startDate);
LocalDate firstThur = getFirstDay(DateTimeConstants.THURSDAY, startDate);
LocalDate firstFri = getFirstDay(DateTimeConstants.FRIDAY, startDate);
LocalDate firstSat = getFirstDay(DateTimeConstants.SATURDAY, startDate);
LocalDate firstSun = getFirstDay(DateTimeConstants.SUNDAY, startDate);
// Get the service ids for weekdays, Saturdays, and Sundays
Set<AgencyAndId> weekdaySvcIds = new HashSet<>();
Set<AgencyAndId> saturdaySvcIds = new HashSet<>();
Set<AgencyAndId> sundaySvcIds = new HashSet<>();
for (ArchivedCalendar calendar : calendars) {
Date svcStartDate = calendar.getStartDate().getAsDate();
LocalDate jodaStartDate = new LocalDate(svcStartDate);
Date svcEndDate = calendar.getEndDate().getAsDate();
LocalDate jodaEndDate = new LocalDate(svcEndDate);
if (calendar.getMonday() == 1 && !firstMon.isBefore(jodaStartDate) && !firstMon.isAfter(jodaEndDate)) {
weekdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getTuesday() == 1 && !firstTues.isBefore(jodaStartDate) && !firstTues.isAfter(jodaEndDate)) {
weekdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getWednesday() == 1 && !firstWed.isBefore(jodaStartDate) && !firstWed.isAfter(jodaEndDate)) {
weekdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getThursday() == 1 && !firstThur.isBefore(jodaStartDate) && !firstThur.isAfter(jodaEndDate)) {
weekdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getFriday() == 1 && !firstFri.isBefore(jodaStartDate) && !firstFri.isAfter(jodaEndDate)) {
weekdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getSaturday() == 1 && !firstSat.isBefore(jodaStartDate) && !firstSat.isAfter(jodaEndDate)) {
saturdaySvcIds.add(calendar.getServiceId());
}
if (calendar.getSunday() == 1 && !firstSun.isBefore(jodaStartDate) && !firstSun.isAfter(jodaEndDate)) {
sundaySvcIds.add(calendar.getServiceId());
}
}
// Get all the routes for this build id
List<ArchivedRoute> allRoutes = _gtfsArchiveService.getAllRoutesByBundleId(buildId);
// Get all the trips for this build id
List<ArchivedTrip> allTrips = _gtfsArchiveService.getAllTripsByBundleId(buildId);
// Get trip stop countt for all the trips in this build
// This call returns a list of arrays of Objects of the form
// [String trip_agencyId, String trip_id, int stop_count]
List allStopCts = _gtfsArchiveService.getTripStopCounts(buildId);
Map<AgencyAndId, Integer> tripStopCounts = new HashMap<>();
for (int i = 0; i < allStopCts.size(); ++i) {
Object[] tripStopCt = (Object[]) allStopCts.get(i);
String tripAgencyId = (String) tripStopCt[0];
String tripId = (String) tripStopCt[1];
int stopCt = (int) tripStopCt[2];
AgencyAndId agencyAndId = new AgencyAndId(tripAgencyId, tripId);
tripStopCounts.put(agencyAndId, stopCt);
}
Map<String, List<String>> reportModes = getReportModes();
Collection<ArchivedAgency> agencies = _gtfsArchiveService.getAllAgenciesByBundleId(buildId);
for (String currentMode : reportModes.keySet()) {
DataValidationMode newMode = new DataValidationMode();
newMode.setModeName(currentMode);
SortedSet<DataValidationRouteCounts> newModeRouteCts = new TreeSet<DataValidationRouteCounts>();
// Note: currentRoutes entries might be just an agency id
List<String> agenciesOrRoutes = reportModes.get(currentMode);
for (String agencyOrRoute : agenciesOrRoutes) {
// or a route, i.e. <agencyId>_<routeId>
// List<ArchivedRoute> routes = null;
// check if agency or route id
int idx = agencyOrRoute.indexOf("_");
int routeCt = allRoutes.size();
int currentRouteCt = 0;
for (ArchivedRoute route : allRoutes) {
if (!route.getAgencyId().equals(agencyOrRoute)) {
continue;
}
currentRouteCt++;
int[] wkdayTrips = null;
int[] satTrips = null;
int[] sunTrips = null;
Map<String, TripTotals> tripMap = new HashMap<>();
String routeId = route.getAgencyId() + ID_SEPARATOR + route.getId();
DataValidationRouteCounts newRouteCts = new DataValidationRouteCounts();
String routeName = route.getDesc();
if (routeName == null || routeName.equals("null") || routeName.isEmpty()) {
routeName = route.getLongName();
}
if (routeName == null || routeName.equals("null")) {
routeName = "";
}
newRouteCts.setRouteName(routeName);
String routeNum = route.getShortName();
if (routeNum == null || routeNum.equals("null") || routeNum.isEmpty()) {
routeNum = route.getId();
}
if (routeNum == null || routeNum.equals("null")) {
routeNum = "";
}
newRouteCts.setRouteNum(routeNum);
// Build DataValidationHeadsignCts
SortedSet<DataValidationHeadsignCts> headsignCounts = new TreeSet<>();
int stopCtIdx = 0;
for (ArchivedTrip trip : allTrips) {
if (trip.getRoute_agencyId().compareTo(route.getAgencyId()) > 0 || (trip.getRoute_agencyId().equals(route.getAgencyId()) && trip.getRoute_id().compareTo(route.getId()) > 0)) {
break;
}
if (!trip.getRoute_agencyId().equals(route.getAgencyId()) || !trip.getRoute_id().equals(route.getId())) {
continue;
}
AgencyAndId tripAgencyAndId = new AgencyAndId(trip.getAgencyId(), trip.getId());
int stopCt = tripStopCounts.get(tripAgencyAndId) != null ? tripStopCounts.get(tripAgencyAndId) : 0;
if (stopCt > MAX_STOP_CT) {
stopCt = MAX_STOP_CT;
}
TripTotals tripTotals = null;
String tripHeadsign = trip.getTripHeadsign();
tripHeadsign = tripHeadsign == null ? "" : tripHeadsign;
if (tripMap.containsKey(tripHeadsign)) {
tripTotals = tripMap.get(tripHeadsign);
} else {
tripTotals = new TripTotals();
tripMap.put(tripHeadsign, tripTotals);
}
/*
* TODO: if stopCt exceeds array sizes, resize arrays
*/
if (trip.getDirectionId() == null || trip.getDirectionId().equals("0")) {
wkdayTrips = tripTotals.wkdayTrips_0;
satTrips = tripTotals.satTrips_0;
sunTrips = tripTotals.sunTrips_0;
} else {
wkdayTrips = tripTotals.wkdayTrips_1;
satTrips = tripTotals.satTrips_1;
sunTrips = tripTotals.sunTrips_1;
}
AgencyAndId tripSvcId = new AgencyAndId(trip.getServiceId_agencyId(), trip.getServiceId_id());
if (weekdaySvcIds.contains(tripSvcId)) {
++wkdayTrips[stopCt];
} else if (saturdaySvcIds.contains(tripSvcId)) {
++satTrips[stopCt];
} else if (sundaySvcIds.contains(tripSvcId)) {
++sunTrips[stopCt];
}
tripMap.put(tripHeadsign, tripTotals);
}
// End of trips loop. Stop counts by direction for this route have been set.
for (String headSign : tripMap.keySet()) {
TripTotals tripTotals = tripMap.get(headSign);
DataValidationHeadsignCts newHeadsignCt = new DataValidationHeadsignCts();
newHeadsignCt.setHeadsign(headSign);
SortedSet<DataValidationDirectionCts> newDirCountSet = new TreeSet<DataValidationDirectionCts>();
DataValidationDirectionCts newDirCt_0 = new DataValidationDirectionCts();
newDirCt_0.setDirection("0");
SortedSet<DataValidationStopCt> stopCounts_0 = new TreeSet<>();
for (int i = 0; i < MAX_STOP_CT; ++i) {
if (tripTotals.wkdayTrips_0[i] > 0 || tripTotals.satTrips_0[i] > 0 || tripTotals.sunTrips_0[i] > 0) {
DataValidationStopCt stopCt_0 = new DataValidationStopCt();
stopCt_0.setStopCt(i);
stopCt_0.setTripCts(new int[] { tripTotals.wkdayTrips_0[i], tripTotals.satTrips_0[i], tripTotals.sunTrips_0[i] });
stopCounts_0.add(stopCt_0);
}
}
if (stopCounts_0.size() > 0) {
newDirCt_0.setStopCounts(stopCounts_0);
newDirCountSet.add(newDirCt_0);
}
DataValidationDirectionCts newDirCt_1 = new DataValidationDirectionCts();
newDirCt_1.setDirection("1");
SortedSet<DataValidationStopCt> stopCounts_1 = new TreeSet<>();
for (int i = 0; i < MAX_STOP_CT; ++i) {
if (tripTotals.wkdayTrips_1[i] > 0 || tripTotals.satTrips_1[i] > 0 || tripTotals.sunTrips_1[i] > 0) {
DataValidationStopCt stopCt_1 = new DataValidationStopCt();
stopCt_1.setStopCt(i);
stopCt_1.setTripCts(new int[] { tripTotals.wkdayTrips_1[i], tripTotals.satTrips_1[i], tripTotals.sunTrips_1[i] });
stopCounts_1.add(stopCt_1);
}
if (stopCounts_1.size() > 0) {
newDirCt_1.setStopCounts(stopCounts_1);
newDirCountSet.add(newDirCt_1);
}
}
if (newDirCountSet.size() > 0) {
newHeadsignCt.setDirCounts(newDirCountSet);
headsignCounts.add(newHeadsignCt);
}
}
if (headsignCounts.size() > 0) {
newRouteCts.setHeadsignCounts(headsignCounts);
newModeRouteCts.add(newRouteCts);
}
}
}
if (newModeRouteCts.size() > 0) {
newMode.setRoutes(newModeRouteCts);
modes.add(newMode);
}
}
return modes;
}
use of org.onebusaway.admin.model.ui.DataValidationStopCt in project onebusaway-application-modules by camsys.
the class FixedRouteParserServiceImpl method parseRecord.
/**
* Parses a csv record representing one line of a FixedRouteDataValidation
* report. If the line is part of the mode currently being processed, it
* is added to that DataValidationMode object. If it is for a new mode, the
* current mode is added to the parsedModes list and the record being
* parsed becomes the new current mode.
*
* @param record the record to be parsed
* @param currentMode the DataValidationMode currently being built
* @param parsedModes the list of modes already created.
* @return the DataValidationMode currently being built
*/
private DataValidationMode parseRecord(CSVRecord record, DataValidationMode currentMode, List<DataValidationMode> parsedModes) {
if (record.size() < 8 || record.get(4).isEmpty() || !record.get(4).matches("^\\d+$")) {
// Stop count should be numeric
return currentMode;
}
// Create the StopCt for this line (every line should have a stop count)
DataValidationStopCt currentStopCt = new DataValidationStopCt();
currentStopCt.setStopCt(Integer.parseInt(record.get(4)));
int[] stopCtTrips = { 0, 0, 0 };
for (int i = 0; i < 3; i++) {
try {
int tripCt = Integer.parseInt(record.get(5 + i));
stopCtTrips[i] = tripCt;
} catch (NumberFormatException ex) {
// Do nothing, leave array value at 0.
}
}
currentStopCt.setTripCts(stopCtTrips);
String modeName = record.get(0);
String routeName = record.get(1);
String headsign = record.get(2);
String dirName = record.get(3);
// If routeName is prefixed with the route number, extract the route number
String routeNum = "";
if (routeName.length() > 0) {
int idx = routeName.substring(0, Math.min(5, routeName.length())).indexOf("-");
if (idx > 0) {
routeNum = routeName.substring(0, idx).trim();
routeName = routeName.substring(idx + 1);
}
}
if (modeName.length() > 0) {
// new mode
if (routeName.isEmpty()) {
// this shouldn't happen. Any line with a mode
return currentMode;
// name should also have a route name.
}
if (currentMode != null) {
parsedModes.add(currentMode);
}
currentMode = new DataValidationMode(modeName, routeNum, routeName, headsign, dirName);
currentRoute = currentMode.getRoutes().first();
currentHeadsign = currentRoute.getHeadsignCounts().first();
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (routeName.length() > 0) {
// New route for current mode
currentRoute = new DataValidationRouteCounts(routeNum, routeName, headsign, dirName);
currentMode.getRoutes().add(currentRoute);
currentHeadsign = currentRoute.getHeadsignCounts().first();
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (headsign.length() > 0) {
currentHeadsign = new DataValidationHeadsignCts(headsign, dirName);
currentRoute.getHeadsignCounts().add(currentHeadsign);
currentDirection = currentHeadsign.getDirCounts().first();
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (dirName.length() > 0) {
currentDirection = new DataValidationDirectionCts(dirName);
currentHeadsign.getDirCounts().add(currentDirection);
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
} else if (dirName.isEmpty()) {
SortedSet<DataValidationStopCt> stopCountsList = currentDirection.getStopCounts();
stopCountsList.add(currentStopCt);
}
return currentMode;
}
Aggregations