Skip to content
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

Fares v2 #600

Open
wants to merge 2 commits into
base: dev
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<dependency>
<groupId>org.mobilitydata.gtfs-validator</groupId>
<artifactId>gtfs-validator-main</artifactId>
<version>4.2.0</version>
<version>5.0.0</version>
</dependency>
<!-- Used for loading/fetching/validating/writing GTFS entities. gtfs-lib also provides access to:
- commons-io - generic utilities
Expand All @@ -272,7 +272,7 @@
<groupId>com.github.ibi-group</groupId>
<artifactId>gtfs-lib</artifactId>
<!-- Latest dev build on jitpack.io -->
<version>a8a376c82b</version>
<version>1d95cf5dc5eb2907ccf2abd4ede5b55963807195</version>
<!-- Exclusions added in order to silence SLF4J warnings about multiple bindings:
http://www.slf4j.org/codes.html#multiple_bindings
-->
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/conveyal/datatools/manager/DataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,29 @@ static void registerRoutes() throws IOException {
SnapshotController.register(EDITOR_API_PREFIX);
EditorLockController.register(EDITOR_API_PREFIX);

new EditorControllerImpl(EDITOR_API_PREFIX, Table.AREAS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.AGENCY, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.ATTRIBUTIONS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.CALENDAR, DataManager.GTFS_DATA_SOURCE);
// NOTE: fare_attributes controller handles updates to nested table fare_rules.
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_ATTRIBUTES, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_LEG_RULES, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_MEDIAS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_PRODUCTS, DataManager.GTFS_DATA_SOURCE);
new EditorControllerImpl(EDITOR_API_PREFIX, Table.FARE_TRANSFER_RULES, DataManager.GTFS_DATA_SOURCE);
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);

// TODO: Add transfers.txt controller?
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.conveyal.datatools.manager.jobs.validation;

import com.conveyal.datatools.DatatoolsTest;
import com.conveyal.datatools.manager.auth.Auth0Connection;
import com.conveyal.datatools.manager.models.FeedSource;
import com.conveyal.datatools.manager.models.FeedVersion;
import com.conveyal.datatools.manager.models.Project;
import com.conveyal.datatools.manager.persistence.Persistence;
import org.bson.Document;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import static com.conveyal.datatools.TestUtils.createFeedVersion;
import static com.conveyal.datatools.TestUtils.zipFolderFiles;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class FaresV2ValidationTest {

private static Project project;
private static FeedVersion faresV2Version;

@BeforeAll
public static void setUp() throws IOException {
// Start server if it isn't already running.
DatatoolsTest.setUp();
Auth0Connection.setAuthDisabled(true);
// Create a project, feed sources, and feed versions to merge.
project = new Project();
project.name = String.format("Test %s", new Date());
Persistence.projects.create(project);

FeedSource faresV2FeedSource = new FeedSource("fares-v2");
faresV2FeedSource.projectId = project.id;
Persistence.feedSources.create(faresV2FeedSource);
faresV2Version = createFeedVersion(
faresV2FeedSource,
zipFolderFiles("fake-agency-with-fares-v2")
);
Persistence.feedVersions.replace(faresV2Version.id, faresV2Version);
}

@AfterAll
static void tearDown() {
Auth0Connection.setAuthDisabled(Auth0Connection.getDefaultAuthDisabled());
project.delete();
}

@Test
void canValidateFareV2Files() {
Document summary = (Document) faresV2Version.mobilityDataResult.get("summary");
List<String> files = summary.getList("files", String.class);
assertTrue(files.contains("areas.txt"));
assertTrue(files.contains("fare_leg_rules.txt"));
assertTrue(files.contains("fare_media.txt"));
assertTrue(files.contains("fare_products.txt"));
assertTrue(files.contains("fare_transfer_rules.txt"));
assertTrue(files.contains("networks.txt"));
assertTrue(files.contains("route_networks.txt"));
assertTrue(files.contains("stop_areas.txt"));
assertTrue(files.contains("timeframes.txt"));
}

/**
* This is not an exhaustive test, more of a sanity check that MobilityData can detect errors in fares v2 data.
* https://gtfs-validator.mobilitydata.org/rules.html
*/
@ParameterizedTest
@MethodSource("createValidationErrorChecks")
void canDetectValidationErrors(Set<String> codes, String expectedCode) {
assertTrue(codes.contains(expectedCode));
}

private static Stream<Arguments> createValidationErrorChecks() {
ArrayList<Document> notices = (ArrayList<Document>) faresV2Version.mobilityDataResult.get("notices");
Set<String> codes = new HashSet<>();
for (Document notice : notices) {
codes.add(notice.getString("code"));
}
return Stream.of(
Arguments.of(codes, "fare_transfer_rule_duration_limit_type_without_duration_limit"),
Arguments.of(codes, "fare_transfer_rule_duration_limit_without_type"),
Arguments.of(codes, "fare_transfer_rule_missing_transfer_count"),
Arguments.of(codes, "fare_transfer_rule_with_forbidden_transfer_count")
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
agency_id,agency_name,agency_url,agency_lang,agency_phone,agency_email,agency_timezone,agency_fare_url,agency_branding_url
1,Fake Transit,http://www.fake-agency.com,,,,America/Los_Angeles,,
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
area_id,area_name
area_bl,Blue Line
area_bl_airport,Blue Line - Airport Station
area_cf_zone_buzzards,CapeFLYER - Wareham/Buzzards Bay/Bourne
area_cf_zone_hyannis,CapeFLYER - Hyannis
area_commuter_rail_porter_zone_1a,Commuter Rail Zone 1A
area_commuter_rail_sumner_tunnel_zone_1a,Commuter Rail Zone 1A
area_commuter_rail_zone_1,Commuter Rail Zone 1
area_commuter_rail_zone_10,Commuter Rail Zone 10
area_commuter_rail_zone_1a,Commuter Rail Zone 1A
area_commuter_rail_zone_2,Commuter Rail Zone 2
area_commuter_rail_zone_3,Commuter Rail Zone 3
area_commuter_rail_zone_4,Commuter Rail Zone 4
area_commuter_rail_zone_5,Commuter Rail Zone 5
area_commuter_rail_zone_6,Commuter Rail Zone 6
area_commuter_rail_zone_7,Commuter Rail Zone 7
area_commuter_rail_zone_8,Commuter Rail Zone 8
area_commuter_rail_zone_9,Commuter Rail Zone 9
area_fairmount_line_zone_1a,Commuter Rail Zone 1A - Fairmount Line
area_gl_govt_ctr,Green Line - Government Center
area_green_b_west_of_kenmore,Green Line B - West of Kenmore
area_green_c_west_of_kenmore,Green Line C - West of Kenmore
area_green_e_west_of_symphony,Green Line E - West of Symphony
area_m_ashmont_mattapan,Mattapan Trolley - Ashmont and Mattapan
area_ol_state,Orange Line - State
area_red_south_station,Red Line - South Station
area_route_354_downtown,Route 354 - Downtown
area_route_354_outside_downtown,Route 354 - Outside Downtown
area_route_426_downtown,Route 426 - Downtown
area_route_426_outside_downtown,Route 426 - Outside Downtown
area_route_450_downtown,Route 450 - Downtown
area_route_450_outside_downtown,Route 450 - Outside Downtown
area_sl3_north_of_airport,Silver Line - North of Airport Station
area_sl_airport,Silver Line - Airport Station
area_sl_courthouse,Silver Line - Courthouse
area_sl_logan_terminal,Silver Line - Airport Terminals
area_sl_silver_line_way,Silver Line - Silver Line Way
area_sl_south_station,Silver Line - South Station
area_sl_world_trade_center,Silver Line - World Trade Center
area_ss_commuter_rail_zone_1a,Commuter Rail Zone 1A - South Station
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
04100312-8fe1-46a5-a9f2-556f39478f57,1,1,1,1,1,1,1,20170915,20170917
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service_id,date,exception_type
04100312-8fe1-46a5-a9f2-556f39478f57,20170916,2
calendar-date-service,20170917,1
Loading
Loading