-
Notifications
You must be signed in to change notification settings - Fork 42
WIP - Fix #154 start time of freq based trip should be immutable. #336
base: master
Are you sure you want to change the base?
Changes from 4 commits
7f21b52
95f03b1
27623ef
1e05604
4761991
0eb5739
9b93487
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| package edu.usf.cutr.gtfsrtvalidator.lib.validation.rules; | ||
|
|
||
| import com.google.transit.realtime.GtfsRealtime; | ||
| import com.google.transit.realtime.GtfsRealtime.TripUpdate; | ||
|
|
||
| import edu.usf.cutr.gtfsrtvalidator.lib.model.MessageLogModel; | ||
| import edu.usf.cutr.gtfsrtvalidator.lib.model.OccurrenceModel; | ||
| import edu.usf.cutr.gtfsrtvalidator.lib.model.helper.ErrorListHelperModel; | ||
|
|
@@ -27,6 +29,7 @@ | |
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
|
|
||
| import static edu.usf.cutr.gtfsrtvalidator.lib.validation.ValidationRules.*; | ||
|
|
@@ -37,21 +40,26 @@ | |
| * E006 - Missing required vehicle_position trip field for frequency-based exact_times = 0 | ||
| * E013 - Frequency type 0 trip schedule_relationship should be UNSCHEDULED or empty | ||
| * W005 - Missing vehicle_id in trip_update for frequency-based exact_times = 0 | ||
| * E053 - An exact_times = 0 frequencies.txt trip should have the same start_time through it's trip | ||
| */ | ||
| public class FrequencyTypeZeroValidator implements FeedEntityValidator { | ||
|
|
||
| private static final org.slf4j.Logger _log = LoggerFactory.getLogger(FrequencyTypeZeroValidator.class); | ||
|
|
||
| private HashMap<String, TripUpdate> previousTripUpdates=new HashMap<String, TripUpdate>(); | ||
|
|
||
| @Override | ||
| public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsMutableDao gtfsData, GtfsMetadata gtfsMetadata, GtfsRealtime.FeedMessage feedMessage, GtfsRealtime.FeedMessage previousFeedMessage, GtfsRealtime.FeedMessage combinedFeedMessage) { | ||
| List<OccurrenceModel> errorListE006 = new ArrayList<>(); | ||
| List<OccurrenceModel> errorListE013 = new ArrayList<>(); | ||
| List<OccurrenceModel> errorListW005 = new ArrayList<>(); | ||
| List<OccurrenceModel> errorListE053 = new ArrayList<>(); | ||
|
|
||
| for (GtfsRealtime.FeedEntity entity : feedMessage.getEntityList()) { | ||
| if (entity.hasTripUpdate()) { | ||
|
|
||
| GtfsRealtime.TripUpdate tripUpdate = entity.getTripUpdate(); | ||
|
|
||
| if (gtfsMetadata.getExactTimesZeroTripIds().contains(tripUpdate.getTrip().getTripId())) { | ||
| /** | ||
| * NOTE - W006 checks for missing trip_ids, because we can't check for that here - we need the trip_id to know if it's exact_times=0 | ||
|
|
@@ -75,9 +83,25 @@ public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsMutableDa | |
| // W005 - Missing vehicle_id in trip_update for frequency-based exact_times = 0 | ||
| RuleUtils.addOccurrence(W005, "trip_id " + tripUpdate.getTrip().getTripId(), errorListW005, _log); | ||
| } | ||
|
|
||
| if (tripUpdate.hasVehicle() && tripUpdate.getVehicle().hasId() && previousTripUpdates.get(tripUpdate.getVehicle().getId()) != null) { | ||
|
||
| if (tripUpdate.getStopTimeUpdateCount() > 0 && previousTripUpdates.get(tripUpdate.getVehicle().getId()).getStopTimeUpdateCount() > 0) { | ||
| if (tripUpdate.getStopTimeUpdate(tripUpdate.getStopTimeUpdateCount() - 1).getStopSequence() >= previousTripUpdates.get(tripUpdate.getVehicle().getId()).getStopTimeUpdate(previousTripUpdates.get(tripUpdate.getVehicle().getId()).getStopTimeUpdateCount() - 1).getStopSequence()) { | ||
| // E053 - start time of trip not consistent for trip updates for frequency-based exact_times = 0 | ||
| if (!tripUpdate.getTrip().getStartTime().equals(previousTripUpdates.get(tripUpdate.getVehicle().getId()).getTrip().getStartTime())) { | ||
|
|
||
| String errorMessage="vehicle_id " + tripUpdate.getVehicle().getId()+ " changed from "+previousTripUpdates.get(tripUpdate.getVehicle().getId()).getTrip().getStartTime() +" to " + tripUpdate.getTrip().getStartTime(); | ||
| RuleUtils.addOccurrence(E053, errorMessage, errorListE053, _log); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Need to store previous for checking E053. Not using previousFeedMessage on purpose. | ||
| if(tripUpdate.hasVehicle() && tripUpdate.getVehicle().hasId()) | ||
| previousTripUpdates.put(tripUpdate.getVehicle().getId(), tripUpdate); | ||
| } | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because a VehiclePositions feed can contain a TripDescriptor too, we should also check for this same rule within the below See There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking more, I think you'd need the |
||
| if (entity.hasVehicle()) { | ||
| GtfsRealtime.VehiclePosition vehiclePosition = entity.getVehicle(); | ||
| if (vehiclePosition.hasTrip() && | ||
|
|
@@ -119,6 +143,9 @@ public List<ErrorListHelperModel> validate(long currentTimeMillis, GtfsMutableDa | |
| if (!errorListW005.isEmpty()) { | ||
| errors.add(new ErrorListHelperModel(new MessageLogModel(W005), errorListW005)); | ||
| } | ||
| if (!errorListE053.isEmpty()) { | ||
| errors.add(new ErrorListHelperModel(new MessageLogModel(E053), errorListE053)); | ||
| } | ||
| return errors; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.