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

fix: comments on #1587 #1592

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

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

import java.util.List;
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice.FileRefs;
Expand Down Expand Up @@ -53,38 +51,33 @@ public class TripAndShapeDistanceValidator extends FileValidator {

@Override
public void validate(NoticeContainer noticeContainer) {
List<String> uniqueShapeIds =
shapeTable.getEntities().stream()
.map(GtfsShape::shapeId)
.distinct()
.collect(Collectors.toList());

uniqueShapeIds.forEach(
shapeId -> {
double maxShapeDist =
shapeTable.getEntities().stream()
.filter(s -> s.shapeId().equals(shapeId))
.mapToDouble(GtfsShape::shapeDistTraveled)
.max()
.orElse(Double.NEGATIVE_INFINITY);

tripTable
.byShapeId(shapeId)
.forEach(
trip -> {
double maxStopTimeDist =
stopTimeTable.byTripId(trip.tripId()).stream()
.mapToDouble(GtfsStopTime::shapeDistTraveled)
.max()
.orElse(Double.NEGATIVE_INFINITY);

if (maxStopTimeDist > maxShapeDist) {
noticeContainer.addValidationNotice(
new TripDistanceExceedsShapeDistanceNotice(
trip.tripId(), shapeId, maxStopTimeDist, maxShapeDist));
}
});
});
shapeTable
.byShapeIdMap()
.forEach(
(shapeId, shape) -> {
double maxShapeDist =
shapeTable.byShapeId(shapeId).stream()
cka-y marked this conversation as resolved.
Show resolved Hide resolved
.mapToDouble(GtfsShape::shapeDistTraveled)
.max()
jcpitre marked this conversation as resolved.
Show resolved Hide resolved
.orElse(Double.NEGATIVE_INFINITY);

tripTable
.byShapeId(shapeId)
.forEach(
trip -> {
double maxStopTimeDist =
stopTimeTable.byTripId(trip.tripId()).stream()
.mapToDouble(GtfsStopTime::shapeDistTraveled)
.max()
jcpitre marked this conversation as resolved.
Show resolved Hide resolved
.orElse(Double.NEGATIVE_INFINITY);

if (maxStopTimeDist > maxShapeDist) {
noticeContainer.addValidationNotice(
new TripDistanceExceedsShapeDistanceNotice(
trip.tripId(), shapeId, maxStopTimeDist, maxShapeDist));
}
});
});
}

/** The distance traveled by a trip should be less or equal to the max length of its shape. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
# Sources to exclude because they are too big for the workflow.
SOURCES_TO_EXCLUDE = [
"de-unknown-rursee-schifffahrt-kg-gtfs-784",
"de-unknown-ulmer-eisenbahnfreunde-gtfs-1081",
"no-unknown-agder-kollektivtrafikk-as-gtfs-1078",
cka-y marked this conversation as resolved.
Show resolved Hide resolved
"hu-unknown-volanbusz-gtfs-1836",
"de-baden-wurttemberg-verkehrsverbund-rhein-neckar-gtfs-1173",
Expand Down
Loading