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

Feat: 1640 add remaining gtfs features to the validator #1656

Merged
merged 15 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ web/service/src/main/resources/application.properties
web/service/newrelic/newrelic.yml

processor/tests/bin

.vscode/
app/gui/bin/
app/pkg/bin/
processor/notices/bin/
processor/notices/tests/bin/
web/service/bin/
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public class FeedMetadata {
new Pair<>("Fares V1", GtfsFareAttribute.FILENAME),
new Pair<>("Fare Products", GtfsFareProduct.FILENAME),
new Pair<>("Shapes", GtfsShape.FILENAME),
new Pair<>("Frequency-Based Trip", GtfsFrequency.FILENAME),
new Pair<>("Frequencies", GtfsFrequency.FILENAME),
new Pair<>("Feed Information", GtfsFeedInfo.FILENAME),
new Pair<>("Attributions", GtfsAttribution.FILENAME),
new Pair<>("Translations", GtfsTranslation.FILENAME),
new Pair<>("Fare Media", GtfsFareMedia.FILENAME),
new Pair<>("Zone-Based Fares", GtfsStopArea.FILENAME));
new Pair<>("Zone-Based Fares", GtfsArea.FILENAME),
new Pair<>("Route-Based Fares", GtfsNetwork.FILENAME),
new Pair<>("Transfer Rules", GtfsFareTransferRule.FILENAME),
new Pair<>("Time-Based Fares", GtfsTimeframe.FILENAME),
new Pair<>("Levels", GtfsLevel.FILENAME));

protected FeedMetadata() {}

Expand Down Expand Up @@ -151,6 +155,10 @@ private void loadSpecFeaturesBasedOnFieldPresence(GtfsFeedContainer feedContaine
loadBlocksComponent(feedContainer);
loadRouteBasedFaresComponent(feedContainer);
loadContinuousStopsComponent(feedContainer);
loadZoneBasedComponent(feedContainer);
loadTimeBaedFaresComponent(feedContainer);
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
loadTransferRulesComponent(feedContainer);
loadLevelsComponent(feedContainer);
}

private void loadContinuousStopsComponent(GtfsFeedContainer feedContainer) {
Expand Down Expand Up @@ -183,10 +191,11 @@ private void loadRouteBasedFaresComponent(GtfsFeedContainer feedContainer) {
List.of(
GtfsFareLegRule::hasFromAreaId,
(Function<GtfsFareLegRule, Boolean>) GtfsFareLegRule::hasToAreaId))
&& hasAtLeastOneRecordForFields(
feedContainer,
GtfsRoute.FILENAME,
List.of((Function<GtfsRoute, Boolean>) GtfsRoute::hasNetworkId)));
&& (hasAtLeastOneRecordForFields(
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
feedContainer,
GtfsRoute.FILENAME,
List.of((Function<GtfsRoute, Boolean>) GtfsRoute::hasNetworkId))
|| hasAtLeastOneRecordInFile(feedContainer, GtfsNetwork.FILENAME)));
}

private void loadBlocksComponent(GtfsFeedContainer feedContainer) {
Expand All @@ -206,7 +215,11 @@ private void loadPathwayDirectionsComponent(GtfsFeedContainer feedContainer) {
GtfsPathway.FILENAME,
List.of(
GtfsPathway::hasSignpostedAs,
(Function<GtfsPathway, Boolean>) GtfsPathway::hasReversedSignpostedAs)));
(Function<GtfsPathway, Boolean>) GtfsPathway::hasReversedSignpostedAs,
GtfsPathway::hasMaxSlope,
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
GtfsPathway::hasMinWidth,
GtfsPathway::hasLength,
GtfsPathway::hasStairCount)));
}

private void loadTraversalTimeComponent(GtfsFeedContainer feedContainer) {
Expand Down Expand Up @@ -306,6 +319,25 @@ private void loadRouteNamesComponent(GtfsFeedContainer feedContainer) {
(Function<GtfsRoute, Boolean>) GtfsRoute::hasRouteLongName)));
}

private void loadZoneBasedComponent(GtfsFeedContainer feedContainer) {
specFeatures.put(
"Zone-Based Fares", hasAtLeastOneRecordInFile(feedContainer, GtfsArea.FILENAME));
}

private void loadTimeBaedFaresComponent(GtfsFeedContainer feedContainer) {
specFeatures.put(
"Time-Based Fares", hasAtLeastOneRecordInFile(feedContainer, GtfsTimeframe.FILENAME));
}

private void loadTransferRulesComponent(GtfsFeedContainer feedContainer) {
specFeatures.put(
"Transfer Rules", hasAtLeastOneRecordInFile(feedContainer, GtfsFareTransferRule.FILENAME));
}

private void loadLevelsComponent(GtfsFeedContainer feedContainer) {
specFeatures.put("Levels", hasAtLeastOneRecordInFile(feedContainer, GtfsLevel.FILENAME));
}

private void loadAgencyData(GtfsTableContainer<GtfsAgency> agencyTable) {
for (GtfsAgency agency : agencyTable.getEntities()) {
agencies.add(AgencyMetadata.from(agency));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.mobilitydata.gtfsvalidator.input.DateForValidation;
Expand Down Expand Up @@ -100,7 +101,10 @@ public Status run(ValidationRunnerConfig config) {
GtfsFeedContainer feedContainer;
GtfsInput gtfsInput = null;
try {
gtfsInput = createGtfsInput(config, versionInfo.currentVersion().get(), noticeContainer);
Optional<String> optionalValue = versionInfo.currentVersion();
if (optionalValue.isPresent()) {
gtfsInput = createGtfsInput(config, versionInfo.currentVersion().get(), noticeContainer);
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
}
} catch (IOException e) {
logger.atSevere().withCause(e).log("Cannot load GTFS feed");
noticeContainer.addSystemError(new IOError(e));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.mobilitydata.gtfsvalidator.table;

import org.mobilitydata.gtfsvalidator.annotation.*;

@GtfsTable("agency.txt")
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
@Required
public interface GtfsNetworkSchema extends GtfsEntity {
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
@FieldType(FieldTypeEnum.ID)
@PrimaryKey
@Required
String networkId();

@MixedCase
String networkName();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public class FareAttributeAgencyIdValidator extends FileValidator {

@Override
public void validate(NoticeContainer noticeContainer) {

int totalAgencies = 0;
// routes.agency_id is required when there are multiple agencies
int totalAgencies = agencyTable.entityCount();

if (agencyTable != null) {
totalAgencies = agencyTable.entityCount();
}
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
for (GtfsFareAttribute fare : attributeTable.getEntities()) {
if (!fare.hasAgencyId()) {
if (totalAgencies > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ public void validate(NoticeContainer noticeContainer) {
// A multilanguage feed may have different agency_lang.
return;
}
for (GtfsAgency agency : agencyTable.getEntities()) {
if (agency.hasAgencyLang() && !feedLang.equals(agency.agencyLang())) {
noticeContainer.addValidationNotice(
new FeedInfoLangAndAgencyLangMismatchNotice(
agency.csvRowNumber(),
agency.agencyId(),
agency.agencyName(),
agency.agencyLang().toLanguageTag(),
feedLang.toLanguageTag()));

if (agencyTable != null) {
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
for (GtfsAgency agency : agencyTable.getEntities()) {
if (agency.hasAgencyLang() && !feedLang.equals(agency.agencyLang())) {
noticeContainer.addValidationNotice(
new FeedInfoLangAndAgencyLangMismatchNotice(
agency.csvRowNumber(),
agency.agencyId(),
agency.agencyName(),
agency.agencyLang().toLanguageTag(),
feedLang.toLanguageTag()));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ public class RouteAgencyIdValidator extends FileValidator {

@Override
public void validate(NoticeContainer noticeContainer) {

int totalAgencies = 0;
// routes.agency_id is required when there are multiple agencies
int totalAgencies = agencyTable.entityCount();
if (agencyTable != null) {
totalAgencies = agencyTable.entityCount();
}
qcdyx marked this conversation as resolved.
Show resolved Hide resolved

for (GtfsRoute route : routeTable.getEntities()) {
if (!route.hasAgencyId()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ private ListMultimap<String, GtfsRoute> routesByUrlMap(GtfsRouteTableContainer r
*/
private ListMultimap<String, GtfsAgency> agenciesByUrlMap(GtfsAgencyTableContainer agencyTable) {
ListMultimap<String, GtfsAgency> agenciesByUrl = ArrayListMultimap.create();
for (GtfsAgency agency : agencyTable.getEntities()) {
if (agency.hasAgencyUrl()) {
agenciesByUrl.put(Ascii.toLowerCase(agency.agencyUrl()), agency);
if (agencyTable != null) {
for (GtfsAgency agency : agencyTable.getEntities()) {
if (agency.hasAgencyUrl()) {
agenciesByUrl.put(Ascii.toLowerCase(agency.agencyUrl()), agency);
}
qcdyx marked this conversation as resolved.
Show resolved Hide resolved
}
}
return agenciesByUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public void containsFrequencyBasedTripComponentTest() throws IOException, Interr
"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 Trip",
"Frequencies",
true,
ImmutableList.of(GtfsFrequencyTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}
Expand All @@ -314,7 +314,7 @@ public void omitsFrequencyBasedTripComponentTest() throws IOException, Interrupt
String content = "trip_id, start_time, end_time, headway_secs\n";
createDataFile(GtfsFrequency.FILENAME, content);
validateSpecFeature(
"Frequency-Based Trip",
"Frequencies",
false,
ImmutableList.of(GtfsFrequencyTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}
Expand Down Expand Up @@ -406,11 +406,11 @@ public void omitsFareMediaComponentTest() throws IOException, InterruptedExcepti
@Test
public void containsZoneBasedFaresComponentTest() throws IOException, InterruptedException {
String content = "area_id, stop_id\n" + "dummyArea, dummyStop\n";
createDataFile(GtfsStopArea.FILENAME, content);
createDataFile(GtfsArea.FILENAME, content);
validateSpecFeature(
"Zone-Based Fares",
true,
ImmutableList.of(GtfsStopAreaTableDescriptor.class, GtfsAgencyTableDescriptor.class));
ImmutableList.of(GtfsAreaTableDescriptor.class, GtfsAgencyTableDescriptor.class));
}

@Test
Expand Down
Loading