Skip to content

Commit

Permalink
MOTP-1653 Write Transformation to check for NJT route ids
Browse files Browse the repository at this point in the history
  • Loading branch information
Heidebritta committed Jun 8, 2020
1 parent bf26c81 commit 060a4ae
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public class GtfsTransformerMain {

private static final String ARG_OMNY_STOPS_FILE = "omnyStopsFile";

private static final String ARG_VERIFY_ROUTES_FILE = "verifyRoutesFile";

private static final String ARG_LOCAL_VS_EXPRESS = "localVsExpress";

private static final String ARG_CHECK_STOP_TIMES = "checkStopTimes";
Expand Down Expand Up @@ -158,6 +160,7 @@ protected void buildOptions(Options options) {
options.addOption(ARG_CONCURRENCY_FILE, true, "file to remap wrong way concurrencies");
options.addOption(ARG_OMNY_ROUTES_FILE, true, "file to add OMNY enabled routes to GTFS");
options.addOption(ARG_OMNY_STOPS_FILE, true, "file to add OMNY enabled stops to GTFS");
options.addOption(ARG_VERIFY_ROUTES_FILE, true, "file to check route names vs route ids in GTFS");

options.addOption(ARG_LOCAL_VS_EXPRESS, false,
"add additional local vs express fields");
Expand Down Expand Up @@ -257,6 +260,10 @@ protected void runApplication(CommandLine cli, String[] originalArgs)
configureOmnyStopsFile(transformer, option.getValue());
}

if (name.equals(ARG_VERIFY_ROUTES_FILE)) {
configureVerifyRoutesFile(transformer, option.getValue());
}

if (name.equals(ARG_LOCAL_VS_EXPRESS))
configureLocalVsExpressUpdates(transformer);

Expand Down Expand Up @@ -350,6 +357,10 @@ private void configureOmnyStopsFile(GtfsTransformer updater, String file) {
updater.addParameter("omnyStopsFile", file);
}

private void configureVerifyRoutesFile(GtfsTransformer updater, String file) {
updater.addParameter("verifyRoutesFile", file);
}

/*****************************************************************************
* Protected Methods
****************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ else if (opType.equals("update_stop_id_by_id")) {
else if (opType.equals("update_route_name")) {
handleTransformOperation(line, json, new UpdateRouteNames());
}
else if (opType.equals("validate_gtfs")) {
handleTransformOperation(line, json, new ValidateGTFS());
}
else if (opType.equals("count_and_test")) {
handleTransformOperation(line, json, new CountAndTest());
}
Expand Down Expand Up @@ -289,11 +292,14 @@ else if (opType.equals("add_omny_subway_data")) {
handleTransformOperation(line, json, new AddOmnySubwayData());
}
else if (opType.equals("add_omny_lirr_data")) {
handleTransformOperation(line, json, new AddOmnyLIRRData());
handleTransformOperation(line, json, new AddStopZoneId());
}
else if (opType.equals("add_omny_bus_data")) {
handleTransformOperation(line, json, new AddOmnyBusData());
}
else if (opType.equals("verify_route_ids")) {
handleTransformOperation(line, json, new VerifyRouteIds());
}
else if (opType.equals("transform")) {
handleTransformOperation(line, json);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/**
* Copyright (C) 2019 Cambridge Systematics, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onebusaway.gtfs_transformer.impl;

import org.onebusaway.gtfs.model.AgencyAndId;
import org.onebusaway.gtfs.model.Route;
import org.onebusaway.gtfs.services.GtfsMutableRelationalDao;
import org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy;
import org.onebusaway.gtfs_transformer.services.TransformContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.List;

public class VerifyRouteIds implements GtfsTransformStrategy {

//routes
private static final int ROUTE_ID = 0;
private static final int ROUTE_NAME = 1;


private static Logger _log = LoggerFactory.getLogger(VerifyRouteIds.class);

public String getName() {
return this.getClass().getName();
}

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {

String agency = dao.getAllTrips().iterator().next().getId().getAgencyId();

File routesFile = new File((String)context.getParameter("verifyRoutesFile"));
if(!routesFile.exists()) {
throw new IllegalStateException(
"verifyRouteIds Routes file does not exist: " + routesFile.getName());
}

List<String> routeLines = new InputLibrary().readList((String) context.getParameter("verifyRoutesFile"));
_log.info("Length of route file: {}", routeLines.size());

for (String routeInfo : routeLines) {
String[] routeArray = routeInfo.split(",");
if (routeArray == null) {
_log.info("routeArray is null");
continue;
}
if (routeArray.length < 2) {
_log.info("routeArray.length: {} {}", routeArray.length, routeInfo);
continue;
}

String routeId = routeArray[ROUTE_ID];
String routeName = routeArray[ROUTE_NAME];

Route route = dao.getRouteForId(new AgencyAndId(agency, routeId));
if (route != null ) {
if (!route.getLongName().contains(routeName)) {
_log.error("NJT MNR West of Hudson Route Id->Route name error. CSV routeId: {} routeName: {} GTFS Route id: {}, longName {}", routeId, routeName, route.getId().getId(), route.getLongName());
throw new IllegalStateException(
"NJT MNR West of Hudson Route Id->Route name error. Route id is for unexpected route name");
}
}
else {
_log.error("NJT MNR West of Hudson Route Id->Route name error. Route id is not present in GTFS. Expected CSV routeId: {} routeName: {}", routeId, routeName);
throw new IllegalStateException(
"NJT MNR West of Hudson Route Id->Route name error. Route is null");
}
}
}
}

0 comments on commit 060a4ae

Please sign in to comment.