Skip to content

Commit e3d2c19

Browse files
authored
🐛 adjust duration tolerance for trip segments to include minimum (#4574)
1 parent ca903b0 commit e3d2c19

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

app/Repositories/TripRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ public function getRouteSegmentBetweenStops(
2323
int $duration,
2424
OpenRailRoutingProfile $pathType = OpenRailRoutingProfile::ALL_TRACKS
2525
): ?RouteSegment {
26+
// Use ±10% tolerance, but at least ±5 minutes for short-distance segments
27+
$tolerance = max(300, (int) round($duration * 0.1));
28+
2629
return RouteSegment::where('from_station_id', $start->train_station_id)
2730
->where('to_station_id', $end->train_station_id)
2831
->where(fn ($q) => $q->where('path_type', $pathType)->orWhereNull('path_type'))
29-
->whereBetween('duration', [$duration * 0.9, $duration * 1.1])
32+
->whereBetween('duration', [max(0, $duration - $tolerance), $duration + $tolerance])
3033
->first();
3134
}
3235

0 commit comments

Comments
 (0)