8000 VDV AUS support by mority · Pull Request #840 · motis-project/motis · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

VDV AUS support #840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 54 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2739aa8
add vdv dep
mority Apr 7, 2025
99a4fc9
wip
mority Apr 7, 2025
dc8937f
wip
mority Apr 8, 2025
0081825
wip
mority Apr 8, 2025
04e4157
wip
mority Apr 8, 2025
379c845
wip
mority Apr 8, 2025
e80627e
wip
mority Apr 8, 2025
9a76583
wip
mority Apr 8, 2025
7bb0308
wip
mority Apr 8, 2025
faf8d4e
wip
mority Apr 8, 2025
a8866b3
wip
mority Apr 8, 2025
3c55287
wip
mority Apr 9, 2025
0943848
wip
mority Apr 9, 2025
bee72ca
wip
mority Apr 9, 2025
3dc85e6
wip
mority Apr 10, 2025
26239b7
wip
mority Apr 10, 2025
b5dbb4f
wip
mority Apr 10, 2025
3970706
wip
mority Apr 10, 2025
06ed810
wip
mority Apr 11, 2025
60be11e
wip
mority Apr 11, 2025
6538460
wip
mority Apr 11, 2025
eab0b1a
wip
mority Apr 11, 2025
9715e3c
wip
mority Apr 16, 2025
19f1711
wip
mority Apr 16, 2025
73e543f
wip
mority Apr 16, 2025
2fe0107
wip
mority Apr 16, 2025
84b39b7
wip
mority Apr 16, 2025
26c54fb
rt tagged union
mority Apr 17, 2025
1e6eeb0
wip
mority Apr 17, 2025
729d592
shutdown
mority Apr 22, 2025
3a4dee6
vdv rt requires incremental rt update
mority Apr 22, 2025
5e579b5
wip
mority Apr 22, 2025
9902a54
Merge branch 'master' into vdv-rt
mority Apr 24, 2025
d4237b3
wip
mority Apr 24, 2025
fc71969
nigiri version
mority Apr 25, 2025
a8fa654
Merge branch 'master' into vdv-rt
mority Apr 25, 2025
3fadd0b
prometheus wip
mority Apr 25, 2025
6370bd1
prometheus wip
mority Apr 25, 2025
22607cf
proper protocol name VDV AUS
mority Apr 25, 2025
b95af31
wip
mority Apr 25, 2025
e248e66
wip
mority Apr 25, 2025
e18d7ea
wip
mority Apr 25, 2025
a4219cc
wip
mority Apr 28, 2025
a154d88
wip
mority Apr 28, 2025
c7bbdff
wip
mority Apr 28, 2025
6eb3656
Merge branch 'master' into vdv-rt
mority Apr 28, 2025
c6c6680
wip
mority Apr 28, 2025
16f1de1
nigiri version
mority Apr 29, 2025
7efa663
wip
mority Apr 29, 2025
1451ec1
Merge branch 'master' into vdv-rt
mority Apr 29, 2025
2a4d939
fixes after merge
mority Apr 29, 2025
c6e1202
format
mority Apr 29, 2025
f4a83aa
fix: control reaches end of non-void function
mority Apr 29, 2025
4768a32
nigiri version
mority Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .pkg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[nigiri]
url=git@github.com:motis-project/nigiri.git
branch=master
commit=8a51f617373ad9cfbe1a78430ffac9d364ac1972
commit=95c6e28e53b551b6bc484344e55ac12c36772591
[cista]
url=git@github.com:felixguendling/cista.git
branch=master
Expand Down Expand Up @@ -66,3 +66,7 @@
url=git@github.com:motis-project/opentelemetry-cpp.git
branch=main
commit=638d55a1d559cc783fd3ef005d5f48e1cbbb5ea3
[pugixml]
url=git@github.com:motis-project/pugixml.git
branch=master
commit=60175e80e2f5e97e027ac78f7e14c5acc009ce50
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ target_link_libraries(motislib
prometheus-cpp::core
opentelemetry_trace
opentelemetry_exporter_otlp_http
pugixml
)


Expand Down
1 change: 1 addition & 0 deletions exe/generate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "motis/place.h"
#include "motis/point_rtree.h"
#include "motis/tag_lookup.h"
#include "motis/vdvaus/connection.h"

#include "./flags.h"

Expand Down
38 changes: 26 additions & 12 deletions include/motis/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,32 @@

#include "cista/hashing.h"

#include "rfl/TaggedUnion.hpp"
#include "rfl/visit.hpp"

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

namespace motis {
#include "motis/rt_config.h"
#include "motis/types.h"

namespace cista {

template <rfl::internal::StringLiteral _discriminator, class... Ts>
struct hashing<rfl::TaggedUnion<_discriminator, Ts...>> {
constexpr hash_t operator()(rfl::TaggedUnion<_discriminator, Ts...> const& el,
hash_t const seed = BASE_HASH) {
hash_t h = hash_combine(seed, el.variant().index());
rfl::visit(
[&](auto&& arg) { h = hashing<std::decay_t<decltype(arg)>>{}(arg, h); },
el);
return h;
}
};

using headers_t = std::map<std::string, std::string>;
} // namespace cista

namespace motis {

struct config {
friend std::ostream& operator<<(std::ostream&, config const&);
Expand Down Expand Up @@ -60,21 +81,12 @@ struct config {

struct timetable {
struct dataset {
struct rt {
bool operator==(rt const&) const = default;
cista::hash_t hash() const noexcept {
return cista::build_hash(url_, headers_);
}
std::string url_;
std::optional<headers_t> headers_{};
};

bool operator==(dataset const&) const = default;

std::string path_;
bool default_bikes_allowed_{false};
std::optional<std::map<std::string, bool>> clasz_bikes_allowed_{};
std::optional<std::vector<rt>> rt_{};
std::optional<std::vector<rt_config>> rt_{};
std::optional<std::string> default_timezone_{};
};

Expand All @@ -98,6 +110,8 @@ struct config {
std::optional<std::string> default_timezone_{};
std::map<std::string, dataset> datasets_{};
std::optional<std::filesystem::path> assistance_times_{};
unsigned vdvaus_subscription_renewal_{3600U};
unsigned vdvaus_subscription_duration_{25 * 3600U};
};
std::optional<timetable> timetable_{};

Expand Down
5 changes: 4 additions & 1 deletion include/motis/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "date/date.h"

#include "nigiri/rt/vdv/vdv_update.h"
#include "nigiri/types.h"

#include "osr/types.h"
Expand Down Expand Up @@ -59,6 +60,7 @@ struct data {
void load_matches();
void load_reverse_geocoder();
void load_tiles();
void load_rt(std::string_view, config::timetable::dataset const&);

void init_rtt(date::sys_days = std::chrono::time_point_cast<date::days>(
std::chrono::system_clock::now()));
Expand All @@ -67,7 +69,7 @@ struct data {
// !!! Remember to add all new members !!!
return std::tie(config_, t_, r_, tc_, w_, pl_, l_, elevations_, tt_, tags_,
location_rtree_, elevator_nodes_, shapes_, railviz_static_,
matches_, rt_, gbfs_, odm_bounds_, metrics_);
matches_, rt_, gbfs_, odm_bounds_, metrics_, vdvaus_);
}

std::filesystem::path path_;
Expand All @@ -92,6 +94,7 @@ struct data {
std::shared_ptr<gbfs::gbfs_data> gbfs_{};
ptr<odm::bounds> odm_bounds_;
ptr<prometheus::Registry> metrics_{std::make_unique<prometheus::Registry>()};
ptr<std::vector<vdvaus::connection>> vdvaus_;
};

} // namespace motis
4 changes: 4 additions & 0 deletions include/motis/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ struct provider_routing_data;
struct products_routing_data;
} // namespace gbfs

namespace vdvaus {
struct connection;
} // namespace vdvaus

} // namespace motis
47 changes: 47 additions & 0 deletions include/motis/rt_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <string_view>

#include "cista/hashing.h"

#include "motis/types.h"

namespace motis {

struct rt_config {

struct gtfsrt {
std::string_view url_;
headers_t const* headers_;
};

struct vdvaus {
std::string_view url_;
std::string const& server_name_;
std::string const& client_name_;
unsigned hysteresis_;
};

std::variant<gtfsrt, vdvaus> operator()() const;

bool operator==(rt_config const&) const = default;
cista::hash_t hash() const noexcept {
return cista::build_hash(protocol_, url_, headers_, client_name_,
server_name_, hysteresis_);
}

enum struct protocol { gtfsrt, vdvaus };
protocol protocol_{protocol::gtfsrt};

std::string url_;

// GTFS-RT
std::optional<headers_t> headers_{};

// VDV AUS
std::optional<std::string> server_name_{};
std::optional<std::string> client_name_{};
std::optional<unsigned> hysteresis_{};
};

} // namespace motis
2 changes: 2 additions & 0 deletions include/motis/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ struct elevator {

using rtt_ptr_t = std::shared_ptr<nigiri::rt_timetable>;

using headers_t = std::map<std::string, std::string>;

} // namespace motis
17 changes: 17 additions & 0 deletions include/motis/vdvaus/client_status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <string>

#include "boost/url/url_view.hpp"

#include "motis/fwd.h"

namespace motis::vdvaus {

struct client_status {
std::string operator()(std::string_view) const;

connection const& vdvaus_;
};

} // namespace motis::vdvaus
30 changes: 30 additions & 0 deletions include/motis/vdvaus/connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "nigiri/rt/vdv/vdv_update.h"

#include "motis/config.h"
#include "motis/fwd.h"
#include "motis/vdvaus/time.h"

namespace motis::vdvaus {

auto const kHeaders = std::map<std::string, std::string>{
{"Content-Type", "text/xml"}, {"Accept", "text/xml"}};

struct connection {
connection(rt_config::vdvaus, nigiri::timetable const&, nigiri::source_idx_t);
connection(connection&&) noexcept;

std::string make_fetch_req();

rt_config::vdvaus cfg_;
std::string client_status_path_;
std::string data_ready_path_;
std::string server_status_addr_;
std::string subscription_addr_;
std::string fetch_data_addr_;
nigiri::rt::vdv::updater upd_;
std::atomic<vdvaus_time> start_{now()};
};

} // namespace motis::vdvaus
12 changes: 12 additions & 0 deletions include/motis/vdvaus/data_ready.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

#include <string>
#include <string_view>

namespace motis::vdvaus {

struct data_ready {
std::string operator()(std::string_view) const;
};

} // namespace motis::vdvaus
14 changes: 14 additions & 0 deletions include/motis/vdvaus/subscription.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include "boost/asio/awaitable.hpp"
#include "boost/asio/io_context.hpp"

#include "motis/fwd.h"

namespace motis::vdvaus {

void subscription(boost::asio::io_context&, config const&, data&);

void shutdown(boost::asio::io_context&, config const&, data&);

} // namespace motis::vdvaus
15 changes: 15 additions & 0 deletions include/motis/vdvaus/time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <chrono>

namespace motis::vdvaus {

using vdvaus_time = std::chrono::time_point<std::chrono::system_clock>;

vdvaus_time now();

std::string timestamp(vdvaus_time);

vdvaus_time parse_timestamp(std::string const&);

} // namespace motis::vdvaus
15 changes: 15 additions & 0 deletions include/motis/vdvaus/xml.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "pugixml.hpp"

#include "motis/vdvaus/time.h"

namespace motis::vdvaus {

pugi::xml_document make_xml_doc();

std::string xml_to_str(pugi::xml_document const& doc);

pugi::xml_document parse(std::string const&);

} // namespace motis::vdvaus
28 changes: 25 additions & 3 deletions src/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,33 @@ void config::verify() const {
if (timetable_) {
for (auto const& [_, d] : timetable_->datasets_) {
if (d.rt_.has_value()) {
for (auto const& url : *d.rt_) {
for (auto const& rt_entry : *d.rt_) {
try {
boost::urls::url{url.url_};
boost::urls::url{rt_entry.url_};
} catch (std::exception const& e) {
throw utl::fail("{} is not a valid url: {}", url.url_, e.what());
throw utl::fail("{} is not a valid url: {}", rt_entry.url_,
e.what());
}
switch (rt_entry.protocol_) {
case rt_config::protocol::gtfsrt:
utl::verify(!rt_entry.client_name_.has_value(),
"GTFS RT invalid field: client_name");
utl::verify(!rt_entry.server_name_.has_value(),
"GTFS RT invalid field: server_name");
utl::verify(!rt_entry.hysteresis_.has_value(),
"GTFS RT invalid field: hysteresis");
break;
case rt_config::protocol::vdvaus:
utl::verify(!rt_entry.headers_.has_value(),
"VDV RT invalid field: headers");
utl::verify(rt_entry.client_name_.has_value(),
"VDV RT requires field: client_name");
utl::verify(rt_entry.server_name_.has_value(),
"VDV RT requires field: server_name");
utl::verify(
timetable_->incremental_rt_update_,
"VDV RT requires setting: incremental_rt_update = true");
break;
}
}
}
Expand Down
Loading
Loading
0