From 1199a831bd0aee87f7e5d101836ada7446e73d61 Mon Sep 17 00:00:00 2001 From: Minh Pham Date: Thu, 11 Oct 2018 17:33:21 -0400 Subject: [PATCH] Add Rule W101 to count the frequency of issue #26 --- RULES.md | 1 + .../lib/validation/ValidationRules.java | 3 +++ .../rules/StopTimeUpdateValidator.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/RULES.md b/RULES.md index aa315515..678530d7 100644 --- a/RULES.md +++ b/RULES.md @@ -68,6 +68,7 @@ Rules are declared in the [`ValidationRules` class](https://github.com/CUTR-at-U | [W007](#W007) | Refresh interval is more than 35 seconds | [W008](#W008) | Header `timestamp` is older than 65 seconds | [W009](#W009) | `schedule_relationship` not populated +| [W101](#W101) | `StopTimeUpdate.schedule_relationship: SKIPPED` # Errors diff --git a/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/ValidationRules.java b/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/ValidationRules.java index 4e7b2a61..a31fdc44 100644 --- a/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/ValidationRules.java +++ b/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/ValidationRules.java @@ -56,6 +56,9 @@ public class ValidationRules { public static final ValidationRule W009 = new ValidationRule("W009", "WARNING", "schedule_relationship not populated", "trip.schedule_relationship and stop_time_update.schedule_relationship should be populated", "does not have a schedule_relationship"); + public static final ValidationRule W101 = new ValidationRule("W101", "WARNING", "StopTimeUpdate.schedule_relationship: SKIPPED", + "StopTimeUpdate.schedule_relationship: SKIPPED", + "StopTimeUpdate.schedule_relationship: SKIPPED"); /** * Errors diff --git a/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/rules/StopTimeUpdateValidator.java b/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/rules/StopTimeUpdateValidator.java index be407fae..f89f9f85 100644 --- a/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/rules/StopTimeUpdateValidator.java +++ b/gtfs-realtime-validator-lib/src/main/java/edu/usf/cutr/gtfsrtvalidator/lib/validation/rules/StopTimeUpdateValidator.java @@ -52,6 +52,7 @@ * E045 - GTFS-rt stop_time_update stop_sequence and stop_id do not match GTFS * E046 - GTFS-rt stop_time_update without time doesn't have arrival/departure_time in GTFS * E051 - GTFS-rt stop_sequence not found in GTFS data + * w101 - StopTimeUpdate.schedule_relationship: SKIPPED */ public class StopTimeUpdateValidator implements FeedEntityValidator { @@ -72,6 +73,7 @@ public List validate(long currentTimeMillis, GtfsMutableDa List e045List = new ArrayList<>(); List e046List = new ArrayList<>(); List e051List = new ArrayList<>(); + List W101List = new ArrayList<>(); for (GtfsRealtime.FeedEntity entity : entityList) { if (entity.hasTripUpdate()) { @@ -169,6 +171,7 @@ public List validate(long currentTimeMillis, GtfsMutableDa checkE042(entity, tripUpdate, stopTimeUpdate, e042List); checkE043(entity, tripUpdate, stopTimeUpdate, e043List); checkE044(entity, tripUpdate, stopTimeUpdate, e044List); + checkW101(entity, stopTimeUpdate, W101List); if (unknownRtStopSequence) { // E051 - GTFS-rt stop_sequence not found in GTFS data @@ -236,6 +239,9 @@ public List validate(long currentTimeMillis, GtfsMutableDa if (!e051List.isEmpty()) { errors.add(new ErrorListHelperModel(new MessageLogModel(ValidationRules.E051), e051List)); } + if (!W101List.isEmpty()) { + errors.add(new ErrorListHelperModel(new MessageLogModel(ValidationRules.W101), W101List)); + } return errors; } @@ -438,4 +444,14 @@ private void checkE046(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate t } } } + + private void checkW101(GtfsRealtime.FeedEntity entity, GtfsRealtime.TripUpdate.StopTimeUpdate stopTimeUpdate, List errors) { + if (stopTimeUpdate.hasScheduleRelationship()) { + GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship schedule_relationship = stopTimeUpdate.getScheduleRelationship(); + if (schedule_relationship.equals(GtfsRealtime.TripUpdate.StopTimeUpdate.ScheduleRelationship.SKIPPED)) { + String id = GtfsUtils.getTripId(entity, entity.getTripUpdate()); + RuleUtils.addOccurrence(ValidationRules.W101, id + " has schedule_relationship: SKIPPED " , errors, _log); + } + } + } }