Skip to content

Merge stop areas and route networks #632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: feature/DT-448-fares-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<groupId>com.github.ibi-group</groupId>
<artifactId>gtfs-lib</artifactId>
<!-- Latest dev build on jitpack.io -->
<version>a3481b0660acf998c6179be89033e6d45b94583f</version>
<version>6739bc6f50295f930b8f0d0c2ee999066c6f4cc5</version>
<!-- Exclusions added in order to silence SLF4J warnings about multiple bindings:
http://www.slf4j.org/codes.html#multiple_bindings
-->
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/conveyal/datatools/manager/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,10 @@ static void registerRoutes() throws IOException {
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FEED_INFO, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.NETWORKS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.ROUTES, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.ROUTE_NETWORKS, DataManager.GTFS_DATA_SOURCE);
// NOTE: Patterns controller handles updates to nested tables shapes, pattern stops, and frequencies.
new EditorControllerImpl(EDITOR_API_PREFIX, Table.PATTERNS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.SCHEDULE_EXCEPTIONS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.STOPS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.STOP_AREAS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.TIME_FRAMES, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.TRANSLATIONS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.TRIPS, DataManager.GTFS_DATA_SOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.conveyal.gtfs.loader.Field;
import com.conveyal.gtfs.loader.ReferenceTracker;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.util.CsvReaderUtil;
import com.csvreader.CsvReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -131,7 +132,7 @@ public void startNewFeed(int feedIndex) throws IOException {
keyFieldMissing = false;

idScope = makeIdScope(version);
csvReader = table.getCsvReader(feed.zipFile, null);
csvReader = CsvReaderUtil.getCsvReaderAccordingToFileName(table, feed.zipFile, null);
// If csv reader is null, the table was not found in the zip file. There is no need
// to handle merging this table for this zip file.
// No need to iterate over second (active) file if strategy is to simply extend the future GTFS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.conveyal.gtfs.error.NewGTFSError;
import com.conveyal.gtfs.loader.Field;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.util.CsvReaderUtil;
import com.csvreader.CsvReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,7 +75,7 @@ private void checkThatStopCodesArePopulatedWhereRequired() throws IOException {
int stopCodeIndex = getFieldIndex("stop_code");
// Get special stops reader to iterate over every stop and determine if stop_code values
// are present.
CsvReader stopsReader = table.getCsvReader(feed.zipFile, null);
CsvReader stopsReader = CsvReaderUtil.getCsvReaderAccordingToFileName(table, feed.zipFile, null);
while (stopsReader.readRecord()) {
stopsCount++;
// Special stop records (i.e., a station, entrance, or anything with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.conveyal.datatools.manager.utils.json.JsonUtil;
import com.conveyal.gtfs.loader.Field;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.util.CsvReaderUtil;
import com.csvreader.CsvReader;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.WordUtils;
Expand Down Expand Up @@ -199,7 +200,11 @@ public void transform(FeedTransformZipTarget zipTarget, MonitorableJob.Status st
status.fail(String.format("Unsupported GTFS file '%s'", tableName));
return;
}
CsvReader csvReader = gtfsTable.getCsvReader(new ZipFile(tempZipPath.toAbsolutePath().toString()), null);
CsvReader csvReader = CsvReaderUtil.getCsvReaderAccordingToFileName(
gtfsTable,
new ZipFile(tempZipPath.toAbsolutePath().toString()),
null
);
if (csvReader == null) {
status.fail(String.format("'Normalize Field' failed because file '%s' was not found in the GTFS archive", tableName));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.conveyal.datatools.manager.utils.GtfsUtils;
import com.conveyal.gtfs.loader.Field;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.util.CsvReaderUtil;
import com.csvreader.CsvReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -58,7 +59,11 @@ public void transform(FeedTransformZipTarget zipTarget, MonitorableJob.Status st
Files.copy(originalZipPath, tempZipPath, StandardCopyOption.REPLACE_EXISTING);

Table gtfsTable = GtfsUtils.getGtfsTable("stop_times");
CsvReader csvReaderForStopTimes = gtfsTable.getCsvReader(new ZipFile(tempZipPath.toAbsolutePath().toString()), null);
CsvReader csvReaderForStopTimes = CsvReaderUtil.getCsvReaderAccordingToFileName(
gtfsTable,
new ZipFile(tempZipPath.toAbsolutePath().toString()),
null
);
final String[] headersForStopTime = csvReaderForStopTimes.getHeaders();
Field[] fieldsFoundInStopTimes = gtfsTable.getFieldsFromFieldHeaders(headersForStopTime, null);
Map<String, Integer> fieldIndexes = getFieldIndexes(fieldsFoundInStopTimes);
Expand All @@ -73,7 +78,11 @@ public void transform(FeedTransformZipTarget zipTarget, MonitorableJob.Status st
);

gtfsTable = GtfsUtils.getGtfsTable("trips");
CsvReader csvReaderForTrips = gtfsTable.getCsvReader(new ZipFile(tempZipPath.toAbsolutePath().toString()), null);
CsvReader csvReaderForTrips = CsvReaderUtil.getCsvReaderAccordingToFileName(
gtfsTable,
new ZipFile(tempZipPath.toAbsolutePath().toString()),
null
);
final String[] headersForTrips = csvReaderForTrips.getHeaders();
Field[] fieldsFoundInStopTrips = gtfsTable.getFieldsFromFieldHeaders(headersForTrips, null);
int tripIdFieldIndex = getFieldIndex(fieldsFoundInStopTrips, TRIP_ID_FIELD_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.conveyal.gtfs.loader.Field;
import com.conveyal.gtfs.loader.Table;
import com.conveyal.gtfs.model.StopTime;
import com.conveyal.gtfs.util.CsvReaderUtil;
import com.csvreader.CsvReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -45,7 +46,7 @@ public class MergeFeedUtils {
public static Set<String> getIdsForTable(ZipFile zipFile, Table table) throws IOException {
Set<String> ids = new HashSet<>();
String keyField = table.getKeyFieldName();
CsvReader csvReader = table.getCsvReader(zipFile, null);
CsvReader csvReader = CsvReaderUtil.getCsvReaderAccordingToFileName(table, zipFile, null);
if (csvReader == null) {
LOG.warn("Table {} not found in zip file: {}", table.name, zipFile.getName());
return ids;
Expand Down Expand Up @@ -117,7 +118,7 @@ public static Set<Field> getAllFields(List<FeedToMerge> feedsToMerge, Table tabl
Set<Field> sharedFields = new HashSet<>();
// First, iterate over each feed to collect the shared fields that need to be output in the merged table.
for (FeedToMerge feed : feedsToMerge) {
CsvReader csvReader = table.getCsvReader(feed.zipFile, null);
CsvReader csvReader = CsvReaderUtil.getCsvReaderAccordingToFileName(table, feed.zipFile, null);
// If csv reader is null, the table was not found in the zip file.
if (csvReader == null) {
continue;
Expand Down
Loading