Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimon Lucas (LCM) committed Jan 21, 2025
1 parent 7cc9d00 commit 968e94e
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 127 deletions.
Empty file modified .pkg.mutex
100755 → 100644
Empty file.
3 changes: 1 addition & 2 deletions include/nigiri/footpath.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

#include "fmt/ostream.h"

#include "utl/verify.h"
#include "utl/logging.h"
#include "utl/verify.h"

#include "cista/reflection/printable.h"

#include "nigiri/footpath.h"
#include "nigiri/types.h"

namespace nigiri {
Expand Down
8 changes: 6 additions & 2 deletions include/nigiri/loader/hrd/service/expand_local_to_utc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "utl/logging.h"

#include "nigiri/loader/hrd/service/ref_service.h"
#include "nigiri/loader/hrd/service/service.h"
#include "nigiri/loader/hrd/stamm/timezone.h"
Expand Down Expand Up @@ -55,7 +57,8 @@ std::optional<duration_t> build_utc_time_seq(
stop_timezones.front(), day, local_times.front(), true);

if (!first_valid) {
utl::log_error("loader.hrd.service.utc",
utl::log_error(
"loader.hrd.service.utc",
"first departure local to utc failed for {}: local_time={}, day={}",
origin, local_times.front(), day);
return std::nullopt;
Expand All @@ -67,7 +70,8 @@ std::optional<duration_t> build_utc_time_seq(
auto const [utc_mam, day_offset, valid] = local_mam_to_utc_mam(
tz, day + first_day_offset, local_time - first_day_offset);
if (day_offset != 0_days || pred > utc_mam || !valid) {
utl::log_error("loader.hrd.service.utc",
utl::log_error(
"loader.hrd.service.utc",
"local to utc failed, ignoring: {}, day={}, time={}, offset={}, "
"pred={}, utc_mam={}, valid={}",
origin, day, local_time, day_offset, pred, utc_mam, valid);
Expand Down
9 changes: 5 additions & 4 deletions include/nigiri/loader/hrd/service/read_services.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "utl/logging.h"
#include "utl/parser/cstr.h"

#include "nigiri/loader/hrd/service/expand_local_to_utc.h"
Expand Down Expand Up @@ -55,16 +56,16 @@ void parse_services(config const& c,
}

if (!spec.valid()) {
utl::log_error("loader.hrd.service",
"skipping invalid service at {}:{}", filename, line_number);
utl::log_error("loader.hrd.service", "skipping invalid service at {}:{}",
filename, line_number);
} else if (!spec.ignore()) {
// Store if relevant.
try {
expand_service(store.add(service{c, st, source_file_idx, spec}));
} catch (std::exception const& e) {
utl::log_error("loader.hrd.service.expand",
"unable to build service at {}:{}: {}", filename, line_number,
e.what());
"unable to build service at {}:{}: {}", filename,
line_number, e.what());
}
}

Expand Down
1 change: 1 addition & 0 deletions include/nigiri/timetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cista/memory_holder.h"
#include "cista/reflection/printable.h"

#include "utl/logging.h"
#include "utl/verify.h"
#include "utl/zip.h"

Expand Down
21 changes: 10 additions & 11 deletions src/abi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,33 @@
#include <memory>
#include <vector>

#include "cista/memory_holder.h"

#include "date/date.h"

#include "utl/helpers/algorithm.h"
#include "utl/logging.h"
#include "utl/overloaded.h"
#include "utl/progress_tracker.h"
#include "utl/verify.h"

#include "nigiri/abi.h"

#include "nigiri/loader/dir.h"
#include "nigiri/loader/gtfs/loader.h"
#include "nigiri/loader/hrd/loader.h"
#include "nigiri/loader/init_finish.h"
#include "nigiri/abi.h"
#include "nigiri/common/interval.h"
#include "nigiri/routing/journey.h"
#include "nigiri/routing/raptor/raptor.h"
#include "nigiri/routing/search.h"
#include "nigiri/rt/create_rt_timetable.h"
#include "nigiri/rt/frun.h"
#include "nigiri/rt/gtfsrt_update.h"
#include "nigiri/rt/rt_timetable.h"
#include "nigiri/shapes_storage.h"
#include "nigiri/timetable.h"
#include "nigiri/types.h"

#include "nigiri/routing/journey.h"
#include "nigiri/routing/raptor/raptor.h"
#include "nigiri/routing/search.h"
#include "nigiri/rt/frun.h"

#include "nigiri/common/interval.h"
#include "cista/memory_holder.h"

using namespace date;

struct nigiri_timetable {
Expand Down Expand Up @@ -61,7 +60,7 @@ nigiri_timetable_t* nigiri_load_from_dir(nigiri::loader::dir const& d,
utl::find_if(loaders, [&](auto&& l) { return l->applicable(d); });
utl::verify(c != end(loaders), "no loader applicable to the given file(s)");
utl::log_info("main", "loading nigiri timetable with configuration {}",
(*c)->name());
(*c)->name());

auto t = new nigiri_timetable_t;
t->tt = std::make_unique<nigiri::timetable>();
Expand Down
21 changes: 11 additions & 10 deletions src/loader/assistance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ assistance_times read_assistance(std::string_view file_content) {
auto a = assistance_times{};
utl::line_range{utl::make_buf_reader(file_content)} //
| utl::csv<assistance>() //
| utl::for_each([&](assistance const& x) {
a.names_.emplace_back(x.name_->trim().view());
a.pos_.emplace_back(*x.lat_, *x.lng_);
try {
a.rules_.emplace_back(oh::parse(x.time_->trim().view()));
} catch (std::exception const& e) {
utl::log_error("loader.assistance",
"bad assistance time \"{}\": {}", x.time_->view(), e.what());
}
});
|
utl::for_each([&](assistance const& x) {
a.names_.emplace_back(x.name_->trim().view());
a.pos_.emplace_back(*x.lat_, *x.lng_);
try {
a.rules_.emplace_back(oh::parse(x.time_->trim().view()));
} catch (std::exception const& e) {
utl::log_error("loader.assistance", "bad assistance time \"{}\": {}",
x.time_->view(), e.what());
}
});
a.rtree_ = geo::make_point_rtree(a.pos_);
return a;
}
Expand Down
4 changes: 2 additions & 2 deletions src/loader/build_footpaths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#include "nigiri/common/day_list.h"
#include "nigiri/constants.h"
#include "nigiri/routing/dijkstra.h"
#include "nigiri/scoped_timer.h"
#include "nigiri/rt/frun.h"
#include "nigiri/scoped_timer.h"
#include "nigiri/types.h"

namespace nigiri::loader {
Expand Down Expand Up @@ -303,7 +303,7 @@ void connect_components(timetable& tt,
static_cast<duration_t::rep>(distance / kWalkSpeed / 60));
if (adjusted_int > std::numeric_limits<u8_minutes::rep>::max()) {
utl::log_error("loader.footpath.adjust",
"too long after adjust: {}>256", adjusted_int);
"too long after adjust: {}>256", adjusted_int);
}
adjusted = u8_minutes{adjusted_int};
}
Expand Down
4 changes: 2 additions & 2 deletions src/loader/dir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ file fs_dir::get_file(std::filesystem::path const& p) const {
mmap_content& operator=(mmap_content const&) = delete;
explicit mmap_content(std::filesystem::path const& p)
: mmap_{p.string().c_str(), cista::mmap::protection::READ} {
utl::log_info("loader.fs_dir", "loaded {}: {} bytes",
p.generic_string(), mmap_.size());
utl::log_info("loader.fs_dir", "loaded {}: {} bytes", p.generic_string(),
mmap_.size());
}
~mmap_content() final = default;
std::string_view get() const final { return mmap_.view(); }
Expand Down
2 changes: 1 addition & 1 deletion src/loader/gtfs/load_timetable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "wyhash.h"

#include "nigiri/common/sort_by.h"
#include "nigiri/loader/get_index.h"
#include "nigiri/loader/gtfs/agency.h"
#include "nigiri/loader/gtfs/calendar.h"
Expand All @@ -31,6 +30,7 @@
#include "nigiri/loader/gtfs/stop_time.h"
#include "nigiri/loader/gtfs/trip.h"
#include "nigiri/loader/loader_interface.h"
#include "nigiri/common/sort_by.h"
#include "nigiri/scoped_timer.h"
#include "nigiri/timetable.h"

Expand Down
3 changes: 2 additions & 1 deletion src/loader/gtfs/route.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ route_map_t read_routes(timetable& tt,
agencies.size() == 1U
? agencies.begin()->second
: utl::get_or_create(agencies, r.agency_id_->view(), [&]() {
utl::log_error("gtfs.route",
utl::log_error(
"gtfs.route",
"agency {} not found, using UNKNOWN with local "
"timezone",
r.agency_id_->view());
Expand Down
4 changes: 2 additions & 2 deletions src/loader/gtfs/stop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ void read_transfers(stop_map_t& stops, std::string_view file_content) {
auto const from_stop_it = stops.find(t.from_stop_id_->view());
if (from_stop_it == end(stops)) {
utl::log_error("loader.gtfs.transfers", "stop {} not found\n",
t.from_stop_id_->view());
t.from_stop_id_->view());
return;
}

auto const to_stop_it = stops.find(t.to_stop_id_->view());
if (to_stop_it == end(stops)) {
utl::log_error("loader.gtfs.transfers", "stop {} not found\n",
t.to_stop_id_->view());
t.to_stop_id_->view());
return;
}

Expand Down
7 changes: 4 additions & 3 deletions src/loader/gtfs/stop_time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "utl/pipes/vec.h"
#include "utl/progress_tracker.h"

#include "nigiri/common/cached_lookup.h"
#include "nigiri/loader/gtfs/parse_time.h"
#include "nigiri/loader/gtfs/trip.h"
#include "nigiri/common/cached_lookup.h"
#include "nigiri/scoped_timer.h"

namespace nigiri::loader::gtfs {
Expand Down Expand Up @@ -79,7 +79,7 @@ void read_stop_times(timetable& tt,
auto const trip_it = trips.trips_.find(t_id);
if (trip_it == end(trips.trips_)) {
utl::log_error("loader.gtfs.stop_time",
"stop_times.txt:{} trip \"{}\" not found", i, t_id);
"stop_times.txt:{} trip \"{}\" not found", i, t_id);
return;
}
t = &trips.data_[trip_it->second];
Expand Down Expand Up @@ -121,7 +121,8 @@ void read_stop_times(timetable& tt,
}
} catch (...) {
utl::log_error("loader.gtfs.stop_time",
"stop_times.txt:{}: unknown stop \"{}\"", i, s.stop_id_->view());
"stop_times.txt:{}: unknown stop \"{}\"", i,
s.stop_id_->view());
}
});

Expand Down
16 changes: 9 additions & 7 deletions src/loader/gtfs/trip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ block::rule_services(trip_data& trips) {
auto const is_empty = trips.data_[t].stop_seq_.empty();
if (is_empty) {
utl::log_error("loader.gtfs.trip", "trip \"{}\": no stop times",
trips.data_[t].id_);
trips.data_[t].id_);
}
return is_empty;
});
Expand Down Expand Up @@ -331,16 +331,16 @@ trip_data read_trips(
auto const traffic_days_it = services.find(t.service_id_->view());
if (traffic_days_it == end(services)) {
utl::log_error("loader.gtfs.trip",
R"(trip "{}": service_id "{}" not found)", t.trip_id_->view(),
t.service_id_->view());
R"(trip "{}": service_id "{}" not found)",
t.trip_id_->view(), t.service_id_->view());
return;
}

auto const route_it = routes.find(t.route_id_->view());
if (route_it == end(routes)) {
utl::log_error("loader.gtfs.trip",
R"(trip "{}": route_id "{}" not found)", t.trip_id_->view(),
t.route_id_->view());
R"(trip "{}": route_id "{}" not found)",
t.trip_id_->view(), t.route_id_->view());
return;
}

Expand Down Expand Up @@ -402,7 +402,8 @@ void read_frequencies(trip_data& trips, std::string_view file_content) {
auto const t = freq.trip_id_->trim().view();
auto const trip_it = trips.trips_.find(t);
if (trip_it == end(trips.trips_)) {
utl::log_error("loader.gtfs.frequencies",
utl::log_error(
"loader.gtfs.frequencies",
"frequencies.txt: skipping frequency (trip \"{}\" not found)",
t);
return;
Expand All @@ -411,7 +412,8 @@ void read_frequencies(trip_data& trips, std::string_view file_content) {
auto const headway_secs_str = *freq.headway_secs_;
auto const headway_secs = parse<int>(headway_secs_str, -1);
if (headway_secs == -1) {
utl::log_error("loader.gtfs.frequencies",
utl::log_error(
"loader.gtfs.frequencies",
R"(frequencies.txt: skipping frequency (invalid headway secs "{}"))",
headway_secs_str.view());
return;
Expand Down
10 changes: 5 additions & 5 deletions src/loader/hrd/load_timetable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "utl/enumerate.h"
#include "utl/helpers/algorithm.h"
#include "utl/logging.h"
#include "utl/pipes.h"
#include "utl/progress_tracker.h"

Expand All @@ -26,9 +27,9 @@ bool applicable(config const& c, dir const& d) {
auto const exists = d.exists(path);
if (!exists) {
utl::log_info("loader.hrd",
"input={}, missing file for config {}: {}",
d.path().generic_string(), c.version_.view(),
path.generic_string());
"input={}, missing file for config {}: {}",
d.path().generic_string(), c.version_.view(),
path.generic_string());
}
return exists;
});
Expand Down Expand Up @@ -92,8 +93,7 @@ void load_timetable(source_idx_t const src,
continue;
}

utl::log_info("loader.hrd.services", "loading {}",
path.generic_string());
utl::log_info("loader.hrd.services", "loading {}", path.generic_string());
auto const file = d.get_file(path);
sb.add_services(
c, relative(path, c.fplan_).string().c_str(), file.data(),
Expand Down
5 changes: 3 additions & 2 deletions src/loader/hrd/service/service_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "utl/erase_duplicates.h"
#include "utl/get_or_create.h"
#include "utl/helpers/algorithm.h"
#include "utl/logging.h"

#include "nigiri/loader/get_index.h"
#include "nigiri/loader/hrd/service/read_services.h"
Expand Down Expand Up @@ -217,8 +218,8 @@ void service_builder::write_services(source_idx_t const src) {
.stop_seq_numbers_ = stop_seq_numbers_,
.route_colors_ = route_colors_});
} catch (std::exception const& e) {
utl::log_error("loader.hrd.service",
"unable to load service {}: {}", ref.origin_, e.what());
utl::log_error("loader.hrd.service", "unable to load service {}: {}",
ref.origin_, e.what());
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/loader/hrd/stamm/attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ attribute_map_t parse_attributes(config const& c,
return;
} else if (line.len < 13 || (is_multiple_spaces(line) && line.len < 22)) {
utl::log_error("loader.hrd.attribute",
"invalid attribute line - skipping {}", line_number);
"invalid attribute line - skipping {}", line_number);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/loader/hrd/stamm/category.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "utl/parser/arg_parser.h"

#include "nigiri/clasz.h"
#include "nigiri/loader/hrd/stamm/category.h"
#include "nigiri/loader/hrd/util.h"
#include "nigiri/clasz.h"
#include "nigiri/scoped_timer.h"

namespace nigiri::loader::hrd {

Expand Down
2 changes: 1 addition & 1 deletion src/loader/hrd/stamm/stamm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ provider_idx_t stamm::resolve_provider(utl::cstr s) {
auto const it = providers_.find(s.view());
if (it == end(providers_)) {
utl::log_error("nigiri.loader.hrd.provider",
"creating new provider for missing {}", s.view());
"creating new provider for missing {}", s.view());
auto const idx = provider_idx_t{tt_.providers_.size()};
tt_.providers_.emplace_back(
provider{.short_name_ = s.view(), .long_name_ = s.view(), .url_ = ""});
Expand Down
Loading

0 comments on commit 968e94e

Please sign in to comment.