From 802aaea228b22fe9c8a60301e74070e7f935ccae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Sun, 24 Nov 2024 22:52:38 +0100 Subject: [PATCH] Fix loading GTFS frequencies with < 60 seconds headway (#156) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix loading GTFS frequencies with < 60 seconds headway * wip * wip --------- Co-authored-by: Felix Gündling --- src/loader/gtfs/trip.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/loader/gtfs/trip.cc b/src/loader/gtfs/trip.cc index 16409cdc..6f7bd44a 100644 --- a/src/loader/gtfs/trip.cc +++ b/src/loader/gtfs/trip.cc @@ -382,11 +382,18 @@ void read_frequencies(trip_data& trips, std::string_view file_content) { if (!frequencies.has_value()) { frequencies = std::vector{}; } + + // If the service operates multiple times per minute, make sure not + // to end up with zero. + auto const headway_minutes = duration_t{std::max( + static_cast( + std::round(static_cast(headway_secs) / 60.F)), + 1)}; frequencies->emplace_back( frequency{hhmm_to_min(freq.start_time_->view()), - hhmm_to_min(freq.end_time_->view()), - duration_t{headway_secs / 60}, schedule_relationship}); + hhmm_to_min(freq.end_time_->view()), headway_minutes, + schedule_relationship}); }); } -} // namespace nigiri::loader::gtfs \ No newline at end of file +} // namespace nigiri::loader::gtfs