Skip to content

Commit

Permalink
revised logic and test
Browse files Browse the repository at this point in the history
  • Loading branch information
qcdyx committed Jan 22, 2025
1 parent 545866a commit 406efd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.ERROR;

import java.util.HashSet;
import java.util.Set;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
Expand All @@ -10,9 +12,6 @@
import org.mobilitydata.gtfsvalidator.table.GtfsStopTime;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTimeTableContainer;

import java.util.HashSet;
import java.util.Set;

/**
* Validates `stop_times.start_pickup_dropoff_window`, `stop_times.end_pickup_dropoff_window`,
* `stop_times.pickup_type`, and `stop_times.drop_off_type` for a single `GtfsStopTime`.
Expand All @@ -33,38 +32,24 @@ public StopTimesRecordValidator(GtfsStopTimeTableContainer stopTimeTable) {

@Override
public void validate(NoticeContainer noticeContainer) {
Set<String> processedTripIds = new HashSet<>();
for (GtfsStopTime entity : stopTimeTable.getEntities()) {
if (processedTripIds.contains(entity.tripId())) {
continue;
}
if (entity.hasStartPickupDropOffWindow()
&& entity.hasEndPickupDropOffWindow()
&& entity.pickupType() == GtfsPickupDropOff.MUST_PHONE
&& entity.dropOffType() == GtfsPickupDropOff.MUST_PHONE) {
&& entity.hasEndPickupDropOffWindow()
&& entity.pickupType() == GtfsPickupDropOff.MUST_PHONE
&& entity.dropOffType() == GtfsPickupDropOff.MUST_PHONE) {
int tripStopCount = stopTimeTable.byTripId(entity.tripId()).size();
if (tripStopCount == 1) {
noticeContainer.addValidationNotice(
new MissingStopTimesRecordNotice(entity.csvRowNumber(), entity.tripId()));
processedTripIds.add(entity.tripId());
new MissingStopTimesRecordNotice(entity.csvRowNumber(), entity.tripId()));
}
}

}
}

/**
* Only 1 stop_times.txt record for the associated trip when
* `stop_times.start_pickup_dropoff_window` and `stop_times.end_pickup_dropoff_window` are
* defined, and`stop_times.pickup_type` and `stop_times.drop_off_type` are both set to `2`
* (MUST_PHONE), and there is only one record in `stop_times.txt` for the associated trip.
*
* <p>Fields:
*
* <ul>
* <li>csvRowNumber: The row number of the faulty record in `stop_times.txt`.
* <li>tripId: The ID of the trip associated with the faulty record.
* </ul>
* Only one stop_times record is found where two are required. Travel within the same location
* group or GeoJSON location requires two records in stop_times.txt with the same
* location_group_id or location_id.
*/
@GtfsValidationNotice(severity = ERROR)
static class MissingStopTimesRecordNotice extends ValidationNotice {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,40 +42,19 @@ private static List<ValidationNotice> generateNotices(List<GtfsStopTime> stopTim
return noticeContainer.getValidationNotices();
}

@Test
public void containsStopTimesRecordShouldNotGenerateNotice() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(
1,
"trip1",
GtfsPickupDropOff.MUST_PHONE,
GtfsPickupDropOff.MUST_PHONE,
GtfsTime.fromString("08:00:00"),
GtfsTime.fromString("09:00:00")),
createStopTime(2,
"trip1",
GtfsPickupDropOff.ALLOWED,
GtfsPickupDropOff.ALLOWED,
GtfsTime.fromString("08:00:00"),
GtfsTime.fromString("09:00:00")))))
.isEmpty();
}

@Test
public void containsStopTimesRecordShouldNotGenerateNotice1() {
assertThat(
generateNotices(
ImmutableList.of(
createStopTime(
1,
"trip1",
GtfsPickupDropOff.MUST_PHONE,
GtfsPickupDropOff.MUST_PHONE,
GtfsTime.fromString("08:00:00"),
GtfsTime.fromString("09:00:00")))))
.isEmpty();
ImmutableList.of(
createStopTime(
1,
"trip1",
GtfsPickupDropOff.ALLOWED,
GtfsPickupDropOff.ALLOWED,
GtfsTime.fromString("08:00:00"),
GtfsTime.fromString("09:00:00")))))
.isEmpty();
}

@Test
Expand Down

0 comments on commit 406efd1

Please sign in to comment.