Skip to content

Commit

Permalink
fix bug for /trip with trip departure times >24h (#568)
Browse files Browse the repository at this point in the history
* fix bug for /trip with trip departure times >24h

* wip
  • Loading branch information
felixguendling authored Oct 15, 2024
1 parent e128908 commit ad5060b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .pkg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[nigiri]
[email protected]:motis-project/nigiri.git
branch=master
commit=42af8534d24f032eca9029bc9987dc7f5c3f3dcf
commit=1da303566f641aaf1a5218bea08a086de30f0f2d
[cista]
[email protected]:felixguendling/cista.git
branch=master
Expand Down
4 changes: 2 additions & 2 deletions .pkg.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
17559634994335302388
16254042641322605199
cista 0f316f13cd9491407f3af2a26b0ba4c833a136b0
zlib-ng 68ab3e2d80253ec5dc3c83691d9ff70477b32cd3
boost 73549ebca677fe6214202a1ab580362b4f80e653
Expand All @@ -23,7 +23,7 @@ opentelemetry-cpp 60770dc9dc63e3543fc87d605b2e88fd53d7a414
pugixml 60175e80e2f5e97e027ac78f7e14c5acc009ce50
unordered_dense e9e0577fcb082fc660fd548946f92c42fc85a9fa
wyhash 1e012b57fc2227a9e583a57e2eacb3da99816d99
nigiri 42af8534d24f032eca9029bc9987dc7f5c3f3dcf
nigiri 1da303566f641aaf1a5218bea08a086de30f0f2d
conf f9bf4bd83bf55a2170725707e526cbacc45dcc66
expat 636c9861e8e7c119f3626d1e6c260603ab624516
libosmium 6e6d6b3081cc8bdf25dda89730e25c36eb995516
Expand Down
4 changes: 2 additions & 2 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ config config::read_simple(std::vector<std::string> const& args) {
auto c = config{};
for (auto const& arg : args) {
auto const p = fs::path{arg};
utl::verify(fs::is_regular_file(p), "path {} does not exist", p);
if (p.generic_string().ends_with("osm.pbf")) {
utl::verify(fs::exists(p), "path {} does not exist", p);
if (fs::is_regular_file(p) && p.generic_string().ends_with("osm.pbf")) {
c.osm_ = p;
c.street_routing_ = true;
c.geocoding_ = true;
Expand Down
63 changes: 14 additions & 49 deletions src/endpoints/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "nigiri/routing/journey.h"
#include "nigiri/rt/frun.h"
#include "nigiri/rt/gtfsrt_resolve_run.h"
#include "nigiri/timetable.h"

#include "motis/data.h"
Expand All @@ -13,61 +14,25 @@ namespace n = nigiri;

namespace motis::ep {

n::rt::run resolve_run(n::timetable const& tt,
date::sys_days const day,
n::source_idx_t const src,
std::string_view trip_id) {
auto const day_idx = static_cast<int>(to_idx(tt.day_idx(day)));

auto const lb = std::lower_bound(
begin(tt.trip_id_to_idx_), end(tt.trip_id_to_idx_), trip_id,
[&](n::pair<n::trip_id_idx_t, n::trip_idx_t> const& a,
n::string const& b) {
return std::tuple(tt.trip_id_src_[a.first],
tt.trip_id_strings_[a.first].view()) <
std::tuple(src, std::string_view{b});
});

auto const id_matches = [src, trip_id = trip_id,
&tt](n::trip_id_idx_t const t_id_idx) {
return tt.trip_id_src_[t_id_idx] == src &&
tt.trip_id_strings_[t_id_idx].view() == trip_id;
};

for (auto i = lb; i != end(tt.trip_id_to_idx_) && id_matches(i->first); ++i) {
for (auto const [t_idx, stop_range] :
tt.trip_transport_ranges_[i->second]) {
auto const day_offset =
tt.event_mam(t_idx, stop_range.from_, n::event_type::kDep).days();
auto const first_dep_day = day_idx - day_offset;
auto const t = n::transport{t_idx, n::day_idx_t{first_dep_day}};

auto const& traffic_days =
tt.bitfields_[tt.transport_traffic_days_[t_idx]];
if (!traffic_days.test(static_cast<std::size_t>(first_dep_day))) {
continue;
}

return n::rt::run{.t_ = t, .stop_range_ = stop_range};
}
}

return {};
}

api::Itinerary trip::operator()(boost::urls::url_view const& url) const {
auto const rt = rt_;
auto const rtt = rt->rtt_.get();

auto const query = api::trip_params{url.params()};
auto const day = parse_iso_date(query.date_);
auto query = api::trip_params{url.params()};
auto const [tag, id] = split_tag_id(query.tripId_);
auto const r = resolve_run(tt_, day, tags_.get_src(tag), id);
auto const src = tags_.get_src(tag);

// transform YYYY-MM-DD to YYYYMMDD
query.date_.erase(std::remove(begin(query.date_), end(query.date_), '-'),
end(query.date_));

transit_realtime::TripDescriptor td;
td.set_trip_id(id);
td.set_start_date(query.date_);

if (!r.valid()) {
throw utl::fail("trip not found: tripId={}, date={}", query.tripId_,
query.date_);
}
auto const [r, _] = n::rt::gtfsrt_resolve_run({}, tt_, rtt, src, td);
utl::verify(r.valid(), "trip not found: tripId={}, date={}, tt={}",
query.tripId_, query.date_, tt_.external_interval());

auto fr = n::rt::frun{tt_, rtt, r};
fr.stop_range_.to_ = fr.size();
Expand Down

0 comments on commit ad5060b

Please sign in to comment.