Skip to content

Commit

Permalink
feat: Changed Fares Transfers to Fare Transfers (#1880)
Browse files Browse the repository at this point in the history
* Changed Fares Transfers to Fare Transfers
Changed Frequency-Based Service to Frequencies
Changed logic of Pathway Signs to "One signposted_as value OR one reversed_signposted_as in pathways.txt"

* formatted code

* fixed broken tests

* added tests for Pathway Signs and Pathway Details

* formatted code
  • Loading branch information
qcdyx authored Oct 16, 2024
1 parent 7426549 commit 3fa0c2f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,20 @@ public class FeedMetadata {
private final List<Pair<FeatureMetadata, String>> FILE_BASED_FEATURES =
List.of(
new Pair<>(new FeatureMetadata("Pathway Connections", "Pathways"), GtfsPathway.FILENAME),
new Pair<>(new FeatureMetadata("Pathway Signs", "Pathways"), GtfsPathway.FILENAME),
new Pair<>(new FeatureMetadata("Pathway Details", "Pathways"), GtfsPathway.FILENAME),
new Pair<>(new FeatureMetadata("Levels", "Pathways"), GtfsLevel.FILENAME),
new Pair<>(new FeatureMetadata("Transfers", null), GtfsTransfer.FILENAME),
new Pair<>(new FeatureMetadata("Shapes", null), GtfsShape.FILENAME),
new Pair<>(new FeatureMetadata("Frequency-Based Service", null), GtfsFrequency.FILENAME),
new Pair<>(new FeatureMetadata("Frequencies", null), GtfsFrequency.FILENAME),
new Pair<>(new FeatureMetadata("Feed Information", null), GtfsFeedInfo.FILENAME),
new Pair<>(new FeatureMetadata("Attributions", null), GtfsAttribution.FILENAME),
new Pair<>(new FeatureMetadata("Translations", null), GtfsTranslation.FILENAME),
new Pair<>(new FeatureMetadata("Fares V1", "Fares"), GtfsFareAttribute.FILENAME),
new Pair<>(new FeatureMetadata("Fare Products", "Fares"), GtfsFareProduct.FILENAME),
new Pair<>(new FeatureMetadata("Fare Media", "Fares"), GtfsFareMedia.FILENAME),
new Pair<>(new FeatureMetadata("Zone-Based Fares", "Fares"), GtfsArea.FILENAME),
new Pair<>(
new FeatureMetadata("Fares Transfers", "Fares"), GtfsFareTransferRule.FILENAME),
new Pair<>(new FeatureMetadata("Fare Transfers", "Fares"), GtfsFareTransferRule.FILENAME),
new Pair<>(new FeatureMetadata("Time-Based Fares", "Fares"), GtfsTimeframe.FILENAME),
new Pair<>(
new FeatureMetadata("Booking Rules", "Flexible Services"), GtfsBookingRules.FILENAME),
Expand Down Expand Up @@ -185,8 +186,9 @@ private void loadSpecFeaturesBasedOnFieldPresence(GtfsFeedContainer feedContaine
loadBikeAllowanceFeature(feedContainer);
loadLocationTypesFeature(feedContainer);
loadTraversalTimeFeature(feedContainer);
loadPathwayDirectionsFeature(feedContainer);
loadPathwayExtraFeature(feedContainer);
loadPathwaySignsFeature(feedContainer);
loadPathwayDetailsFeature(feedContainer);
loadPathwayConnectionsFeature(feedContainer);
loadRouteBasedFaresFeature(feedContainer);
loadContinuousStopsFeature(feedContainer);
loadZoneBasedDemandResponsiveTransitFeature(feedContainer);
Expand Down Expand Up @@ -289,18 +291,20 @@ private void loadRouteBasedFaresFeature(GtfsFeedContainer feedContainer) {
|| hasAtLeastOneRecordInFile(feedContainer, GtfsNetwork.FILENAME));
}

private void loadPathwayDirectionsFeature(GtfsFeedContainer feedContainer) {
private void loadPathwaySignsFeature(GtfsFeedContainer feedContainer) {
specFeatures.put(
new FeatureMetadata("Pathway Signs", "Pathways"),
hasAtLeastOneRecordForFields(
feedContainer,
GtfsPathway.FILENAME,
List.of(
GtfsPathway::hasSignpostedAs,
(Function<GtfsPathway, Boolean>) GtfsPathway::hasReversedSignpostedAs)));
feedContainer,
GtfsPathway.FILENAME,
List.of((Function<GtfsPathway, Boolean>) GtfsPathway::hasSignpostedAs))
|| hasAtLeastOneRecordForFields(
feedContainer,
GtfsPathway.FILENAME,
List.of((Function<GtfsPathway, Boolean>) GtfsPathway::hasReversedSignpostedAs)));
}

private void loadPathwayExtraFeature(GtfsFeedContainer feedContainer) {
private void loadPathwayDetailsFeature(GtfsFeedContainer feedContainer) {
specFeatures.put(
new FeatureMetadata("Pathway Details", "Pathways"),
hasAtLeastOneRecordForFields(
Expand All @@ -321,6 +325,12 @@ private void loadPathwayExtraFeature(GtfsFeedContainer feedContainer) {
List.of((Function<GtfsPathway, Boolean>) GtfsPathway::hasStairCount)));
}

private void loadPathwayConnectionsFeature(GtfsFeedContainer feedContainer) {
specFeatures.put(
new FeatureMetadata("Pathway Connections", "Pathways"),
hasAtLeastOneRecordInFile(feedContainer, GtfsPathway.FILENAME));
}

private void loadTraversalTimeFeature(GtfsFeedContainer feedContainer) {
specFeatures.put(
new FeatureMetadata("In-station Traversal Time", "Pathways"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,52 @@ public void omitsRouteColorsFeatureTest5() throws IOException, InterruptedExcept
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
public void containsPathwaySignsFeatureTest() throws IOException, InterruptedException {
String pathwayContent =
"pathway_id,from_stop_id,to_stop_id,pathway_mode,is_bidirectional,signposted_as,reversed_signposted_as\n"
+ "pathway1,stop1,stop2,1,1,sign1,rsign1\n"
+ "pathway2,stop2,stop3,2,0,sign2,rsign2\n";
createDataFile("pathways.txt", pathwayContent);
validateSpecFeature(
"Pathway Signs",
true,
ImmutableList.of(GtfsPathwayTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
public void omitsPathwaySignsFeatureTest() throws IOException, InterruptedException {
String pathwayContent = "pathway_id,from_stop_id,to_stop_id,pathway_mode,is_bidirectional\n";
createDataFile("pathways.txt", pathwayContent);
validateSpecFeature(
"Pathway Signs",
false,
ImmutableList.of(GtfsPathwayTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
public void containsPathwayDetailsFeatureTest() throws IOException, InterruptedException {
String pathwayContent =
"pathway_id,from_stop_id,to_stop_id,pathway_mode,is_bidirectional,traversal_time,max_slope\n"
+ "pathway1,stop1,stop2,1,1,120,0\n"
+ "pathway2,stop2,stop3,2,0,300,1.1\n";
createDataFile("pathways.txt", pathwayContent);
validateSpecFeature(
"Pathway Details",
true,
ImmutableList.of(GtfsPathwayTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
public void omitsPathwayDetailsFeatureTest() throws IOException, InterruptedException {
String pathwayContent = "pathway_id,from_stop_id,to_stop_id,pathway_mode,is_bidirectional\n";
createDataFile("pathways.txt", pathwayContent);
validateSpecFeature(
"Pathway Details",
false,
ImmutableList.of(GtfsPathwayTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
public void containsPathwayConnectionFeatureTest() throws IOException, InterruptedException {
String pathwayContent =
Expand Down Expand Up @@ -331,7 +377,7 @@ public void containsFrequencyBasedTripFeatureTest() throws IOException, Interrup
"trip_id, start_time, end_time, headway_secs\n" + "dummy1, 01:01:01, 01:01:02, 1\n";
createDataFile(GtfsFrequency.FILENAME, content);
validateSpecFeature(
"Frequency-Based Service",
"Frequencies",
true,
ImmutableList.of(GtfsFrequencyTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}
Expand All @@ -341,7 +387,7 @@ public void omitsFrequencyBasedTripFeatureTest() throws IOException, Interrupted
String content = "trip_id, start_time, end_time, headway_secs\n";
createDataFile(GtfsFrequency.FILENAME, content);
validateSpecFeature(
"Frequency-Based Service",
"Frequencies",
false,
ImmutableList.of(GtfsFrequencyTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}
Expand Down

0 comments on commit 3fa0c2f

Please sign in to comment.