Skip to content

Commit

Permalink
fix: comments on #1587 (#1592)
Browse files Browse the repository at this point in the history
* fix: comments on #1587

* fix: removed unused variable

* fix: formatting

* fix: rollback sources for acceptance test

* fix: removing source causing timeout

* fix: removing source causing timeout
  • Loading branch information
cka-y committed Oct 11, 2023
1 parent f3704d7 commit 85beb70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
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()
.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));
}
});
});
}

/** 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 @@ -34,11 +34,7 @@
SOURCES_TO_EXCLUDE = [
"de-unknown-rursee-schifffahrt-kg-gtfs-784",
"de-unknown-ulmer-eisenbahnfreunde-gtfs-1081",
"no-unknown-agder-kollektivtrafikk-as-gtfs-1078",
"hu-unknown-volanbusz-gtfs-1836",
"de-baden-wurttemberg-verkehrsverbund-rhein-neckar-gtfs-1173",
"de-baden-wurttemberg-db-zugbus-regionalverkehr-alb-bodensee-gtfs-773",
"au-new-south-wales-train-replacement-bus-operators-gtfs-1322"
"no-unknown-agder-kollektivtrafikk-as-gtfs-1078"
]

# Google Cloud constants
Expand Down

0 comments on commit 85beb70

Please sign in to comment.