Skip to content

Commit 6052421

Browse files
fuzzy alerts (#270)
1 parent a329d91 commit 6052421

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

include/nigiri/rt/service_alert.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,23 @@ struct alerts {
8383
using by_route = by_rt_transport;
8484
using by_route_type = by_rt_transport;
8585

86+
// fuzzy_stop parameter:
87+
// - true: alert.l_=invalid matches everything
88+
// => used for stop times
89+
// - false: alert.l_=invalid matches iff l=invalid
90+
// => used for itineraries
91+
// - leg (overall trip):
92+
// l == invalid => matches only not stop specific alerts
93+
// (addressing route/trip/agency)
94+
// - from/to/intermediateStop:
95+
// l != invalid => matches only concrete stop
8696
template <typename Fn>
8797
void for_each_alert(timetable const& tt,
8898
source_idx_t const src,
8999
trip_idx_t const t,
90100
rt_transport_idx_t const rt_t,
91101
location_idx_t const l,
102+
bool const fuzzy_stop,
92103
Fn&& fn) const {
93104
auto const route_id_idx = tt.trip_route_id_[t];
94105
auto const route_type = tt.route_ids_[src].route_id_type_[route_id_idx];
@@ -100,7 +111,9 @@ struct alerts {
100111
? location_idx_t::invalid()
101112
: tt.locations_.parents_[parent];
102113
auto const matches_location = [&](location_idx_t const x) {
103-
return x == l || (parent != location_idx_t::invalid() && parent == x) ||
114+
return (fuzzy_stop ? (x == location_idx_t::invalid() || x == l)
115+
: (x == l)) ||
116+
(parent != location_idx_t::invalid() && parent == x) ||
104117
(grandparent != location_idx_t::invalid() && grandparent == x);
105118
};
106119

0 commit comments

Comments
 (0)