Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 28 additions & 5 deletions include/nigiri/fares.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ using timeframe_group_idx_t =
using leg_group_idx_t = cista::strong<std::uint32_t, struct _leg_group_idx_t>;

struct area {
string_idx_t id_;
string_idx_t name_;
};

struct fare_props {
bool matches(fare_props) const;

rider_category_idx_t rider_category_;
fare_media_idx_t media_;
};

struct fares {
struct fare_media {
enum class fare_media_type : std::uint8_t {
Expand All @@ -39,6 +47,7 @@ struct fares {

struct fare_product {
float amount_;
string_idx_t id_;
string_idx_t name_;
fare_media_idx_t media_;
string_idx_t currency_code_;
Expand All @@ -51,6 +60,8 @@ struct fares {

friend std::ostream& operator<<(std::ostream&, fare_leg_rule const&);

fare_props props(fares const&) const;

std::int32_t rule_priority_{0};
network_idx_t network_;
area_idx_t from_area_;
Expand Down Expand Up @@ -89,12 +100,18 @@ struct fares {
kAB // fare_transfer_rules.fare_product_id
};

friend std::ostream& operator<<(
std::ostream& out, fares::fare_transfer_rule::fare_transfer_type);
friend std::ostream& operator<<(std::ostream&, fare_transfer_rule const&);
friend std::ostream& operator<<(std::ostream&, fare_transfer_type);
friend std::ostream& operator<<(std::ostream&, duration_limit_type);
friend bool operator==(fare_transfer_rule const&,
fare_transfer_rule const&);
friend bool operator<(fare_transfer_rule const&, fare_transfer_rule const&);

fare_props props(fares const&) const;

leg_group_idx_t from_leg_group_{leg_group_idx_t::invalid()};
leg_group_idx_t to_leg_group_{leg_group_idx_t::invalid()};
std::int8_t transfer_count_{-1};
std::int16_t transfer_count_{-1};
duration_t duration_limit_{kNoDurationLimit};
duration_limit_type duration_limit_type_{
duration_limit_type::kCurrDepNextArr};
Expand All @@ -115,16 +132,19 @@ struct fares {
};

struct network {
string_idx_t id_;
string_idx_t name_;
};

vector_map<leg_group_idx_t, string_idx_t> leg_group_name_;
vector_map<fare_media_idx_t, fare_media> fare_media_;
vector_map<fare_product_idx_t, fare_product> fare_products_;
vector<fare_leg_rule> fare_leg_rules_;
vector<fare_leg_join_rule> fare_leg_join_rules_;
vector<fare_transfer_rule> fare_transfer_rules_;
vector_map<rider_category_idx_t, rider_category> rider_categories_;
vecvec<timeframe_group_idx_t, timeframe> timeframes_;
vector_map<timeframe_group_idx_t, string_idx_t> timeframe_id_;
hash_map<route_id_idx_t, network_idx_t> route_networks_;
vector_map<network_idx_t, network> networks_;
};
Expand All @@ -136,14 +156,17 @@ using effective_fare_leg_t = std::vector<routing::journey::leg const*>;
struct fare_leg {
source_idx_t src_;
effective_fare_leg_t joined_leg_;
std::vector<fares::fare_leg_rule> rule_;
std::vector<fares::fare_leg_rule> rules_;
};

struct fare_transfer {
std::optional<fares::fare_transfer_rule> rule_;
std::vector<fare_leg> legs_;
};

std::vector<fare_transfer> get_fares(timetable const&, routing::journey const&);
std::string to_string(timetable const&, std::vector<fare_transfer> const&);

std::vector<std::vector<fare_transfer>> get_fares(timetable const&,
routing::journey const&);

} // namespace nigiri
Loading