From 3fa0c2f1988e138facd7f285057ed51d013dae41 Mon Sep 17 00:00:00 2001 From: Jingsi Lu Date: Wed, 16 Oct 2024 13:23:23 -0400 Subject: [PATCH] feat: Changed Fares Transfers to Fare Transfers (#1880) * 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 --- .../report/model/FeedMetadata.java | 34 ++++++++----- .../report/model/FeedMetadataTest.java | 50 ++++++++++++++++++- 2 files changed, 70 insertions(+), 14 deletions(-) diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java index 6c8918d0e3..87218332f2 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java @@ -61,10 +61,12 @@ public class FeedMetadata { private final List> 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), @@ -72,8 +74,7 @@ public class FeedMetadata { 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), @@ -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); @@ -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::hasReversedSignpostedAs))); + feedContainer, + GtfsPathway.FILENAME, + List.of((Function) GtfsPathway::hasSignpostedAs)) + || hasAtLeastOneRecordForFields( + feedContainer, + GtfsPathway.FILENAME, + List.of((Function) GtfsPathway::hasReversedSignpostedAs))); } - private void loadPathwayExtraFeature(GtfsFeedContainer feedContainer) { + private void loadPathwayDetailsFeature(GtfsFeedContainer feedContainer) { specFeatures.put( new FeatureMetadata("Pathway Details", "Pathways"), hasAtLeastOneRecordForFields( @@ -321,6 +325,12 @@ private void loadPathwayExtraFeature(GtfsFeedContainer feedContainer) { List.of((Function) 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"), diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java index 254b2bc3f5..9f6698da68 100644 --- a/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java @@ -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 = @@ -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)); } @@ -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)); }