Skip to content
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

RSL: Status page improvements #411

Merged
merged 12 commits into from
Nov 30, 2023
Merged
11 changes: 11 additions & 0 deletions docs/api/paths.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,17 @@
type: motis.paxmon.PaxMonReviseCompactJourneyResponse
description: Connections with real-time information

/paxmon/dataset_info:
summary: Dataset information
description: >
Returns information about the loaded datasets (schedule, journeys and
capacity files).
tags:
- rsl
output:
type: motis.paxmon.PaxMonDatasetInfoResponse
description: Information about the loaded datasets

/ppr/profiles:
summary: List available pedestrian routing profiles
tags:
Expand Down
99 changes: 91 additions & 8 deletions docs/api/schemas/motis/paxmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,16 @@ PaxMonStatusResponse:
ribasis_fahrt_status:
description: Status of the RiBasisFahrt stream.
ribasis_formation_status:
description: STatus of the RiBasisFormation stream.
description: Status of the RiBasisFormation stream.
motis_start_time:
description: >
The time when MOTIS was started as a unix timestamp.
active_pax:
description: >
The number of passengers currently being tracked in this universe.
universe_count:
description: >
The current number of universes.
PaxMonPdfEntry:
description: TODO
fields:
Expand Down Expand Up @@ -558,15 +567,15 @@ PaxMonFilterGroupsRequest:

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_destination:
description: |
A list of station IDs. If non-empty, only groups arriving at one
of the listed stations are included in the response.

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_via:
description: |
A list of station IDs. If non-empty, only groups with a transfer at one
Expand All @@ -578,31 +587,31 @@ PaxMonFilterGroupsRequest:

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_group_id:
description: |
A list of group IDs. If non-empty, only these groups are included
in the response.

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_data_source:
description: |
A list of group data sources. If non-empty, only groups with these
data sources are included in the response.

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_train_nr:
description: |
A list of train numbers. If non-empty, only groups using a train
with one of the given train numbers are included in the response.

Set to an empty array to disable this filter.
examples:
- [ ]
- []
filter_by_time:
description: |
Filter groups by time.
Expand All @@ -629,7 +638,7 @@ PaxMonFilterGroupsRequest:

Set to an empty array to disable this filter.
examples:
- [ ]
- []
PaxMonGroupWithStats:
description: TODO
fields:
Expand Down Expand Up @@ -1875,6 +1884,8 @@ PaxMonFeedStatus:
description: >
The creation time of the latest real-time updated received from this
real-time feed (unix timestamp).
update_interval:
description: Interval between scheduled updates in seconds.
PaxMonTransfersAtStationRequest:
description: TODO
fields:
Expand Down Expand Up @@ -2030,3 +2041,75 @@ PaxMonReviseCompactJourneyResponse:
fields:
connections:
description: TODO
PaxMonJourneyFileInfo:
description: TODO
fields:
name:
description: TODO
last_modified:
description: TODO
matched_journeys:
description: TODO
unmatched_journeys:
description: TODO
unmatched_journeys_rerouted:
description: TODO
matched_pax:
description: TODO
unmatched_pax:
description: TODO
unmatched_pax_rerouted:
description: TODO
matched_groups:
description: TODO
unmatched_groups:
description: TODO
unmatched_groups_rerouted:
description: TODO
PaxMonCapacityFileFormat:
description: TODO
PaxMonCapacityFileInfo:
description: TODO
fields:
name:
description: TODO
last_modified:
description: TODO
format:
description: TODO
loaded_entry_count:
description: TODO
skipped_entry_count:
description: TODO
station_not_found_count:
description: TODO
PaxMonScheduleInfo:
description: TODO
fields:
names:
description: TODO
begin:
description: TODO
end:
description: TODO
station_count:
description: TODO
trip_count:
description: TODO
expanded_trip_count:
description: TODO
internal_begin:
description: TODO
internal_end:
description: TODO
PaxMonDatasetInfoResponse:
description: TODO
fields:
journey_files:
description: TODO
capacity_files:
description: TODO
schedule:
description: TODO
motis_start_time:
description: TODO
8 changes: 7 additions & 1 deletion modules/paxforecast/src/revert_forecast.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "motis/core/common/dynamic_fws_multimap.h"
#include "motis/core/common/fws_graph.h"
#include "motis/core/common/logging.h"

#include "motis/module/context/motis_call.h"
#include "motis/module/message.h"
Expand Down Expand Up @@ -349,7 +350,12 @@ void revert_forecasts(universe& uv, schedule const& sched,
if (current_pgi == std::numeric_limits<passenger_group_index>::max()) {
return;
}
revert_forecast(uv, sched, mc, reroutes, current_pgi, unbroken_routes);
try {
revert_forecast(uv, sched, mc, reroutes, current_pgi, unbroken_routes);
} catch (std::runtime_error const& ex) {
LOG(motis::logging::error) << "revert forecast for group " << current_pgi
<< " failed: " << ex.what();
}
if (reroutes.size() >= BATCH_SIZE) {
send_reroutes();
}
Expand Down
13 changes: 13 additions & 0 deletions modules/paxmon/include/motis/paxmon/api/dataset_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include "motis/core/schedule/schedule.h"

#include "motis/module/message.h"

#include "motis/paxmon/paxmon_data.h"

namespace motis::paxmon::api {

motis::module::msg_ptr dataset_info(paxmon_data& data, schedule const& sched);

} // namespace motis::paxmon::api
29 changes: 29 additions & 0 deletions modules/paxmon/include/motis/paxmon/file_time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <chrono>
#include <filesystem>

#include "motis/core/common/unixtime.h"

namespace motis::paxmon {

inline unixtime get_last_modified_time(std::filesystem::path const& path) {
auto const file_time = std::filesystem::last_write_time(path);

#ifdef _MSC_VER
auto const sys_time =
std::chrono::clock_cast<std::chrono::system_clock>(file_time);
#else
auto const sys_time =
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
file_time - std::chrono::file_clock::now() +
std::chrono::system_clock::now());
#endif

return static_cast<unixtime>(
std::chrono::time_point_cast<std::chrono::seconds>(sys_time)
.time_since_epoch()
.count());
}

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

#include <cstddef>
#include <filesystem>

#include "motis/core/common/unixtime.h"

#include "motis/paxmon/loader/capacities/load_capacities.h"

namespace motis::paxmon {

struct loaded_journey_file {
std::filesystem::path path_;
unixtime last_modified_{};

std::size_t matched_journeys_{};
std::size_t unmatched_journeys_{};
std::size_t unmatched_journeys_rerouted_{};

std::size_t matched_groups_{};
std::size_t unmatched_groups_{};
std::size_t unmatched_groups_rerouted_{};

std::size_t matched_pax_{};
std::size_t unmatched_pax_{};
std::size_t unmatched_pax_rerouted_{};
};

struct loaded_capacity_file {
std::filesystem::path path_;
unixtime last_modified_{};

loader::capacities::csv_format format_{};
std::size_t loaded_entry_count_{};
std::size_t skipped_entry_count_{};
std::size_t station_not_found_count_{};
};

} // namespace motis::paxmon
10 changes: 9 additions & 1 deletion modules/paxmon/include/motis/paxmon/loader/loader_result.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#pragma once

#include <cstddef>
#include <vector>

#include "motis/paxmon/loader/unmatched_journey.h"

namespace motis::paxmon::loader {

struct loader_result {
std::size_t loaded_journeys_{};
std::vector<unmatched_journey> unmatched_journeys_;

std::size_t loaded_journey_count_{};
std::size_t loaded_group_count_{};
std::size_t loaded_pax_count_{};

std::size_t unmatched_journey_count_{};
std::size_t unmatched_group_count_{};
std::size_t unmatched_pax_count_{};
};

} // namespace motis::paxmon::loader
2 changes: 2 additions & 0 deletions modules/paxmon/include/motis/paxmon/multiverse.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ struct multiverse : std::enable_shared_from_this<multiverse> {

std::vector<current_universe_info> get_current_universe_infos();

std::size_t get_current_universe_count();

friend universe_info;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ struct passenger_group_container {
"passenger_group_container: reroute_log_entries out of sync");

++active_groups_;
active_pax_ += m_ptr->passengers_;
return m_ptr;
}

Expand All @@ -183,9 +184,11 @@ struct passenger_group_container {
}
reroute_log_entries_.at(pgi).clear();

--active_groups_;
active_pax_ -= m_ptr->passengers_;

allocator_.release(ptr);
groups_[pgi] = {};
--active_groups_;
}
}

Expand Down Expand Up @@ -227,6 +230,7 @@ struct passenger_group_container {

std::size_t size() const { return groups_.size(); }
std::size_t active_groups() const { return active_groups_; }
std::size_t active_pax() const { return active_pax_; }

void reserve(std::size_t size) { groups_.reserve(size); }

Expand Down Expand Up @@ -278,6 +282,7 @@ struct passenger_group_container {
mcd::hash_map<data_source, mcd::vector<passenger_group_index>>
groups_by_source_;
std::size_t active_groups_{};
std::size_t active_pax_{};

// index: passenger_group_index
dynamic_fws_multimap<group_route> group_routes_;
Expand Down
9 changes: 9 additions & 0 deletions modules/paxmon/include/motis/paxmon/paxmon_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include <chrono>
#include <memory>
#include <vector>

#include "motis/core/common/unixtime.h"

#include "motis/paxmon/loaded_files.h"
#include "motis/paxmon/multiverse.h"

namespace motis::paxmon {
Expand All @@ -15,6 +19,11 @@ struct paxmon_data {

std::chrono::seconds max_universe_ttl_{std::chrono::minutes{30}};
bool allow_infinite_universe_ttl_{true};

std::vector<loaded_journey_file> loaded_journey_files_;
std::vector<loaded_capacity_file> loaded_capacity_files_;

unixtime motis_start_time_{};
};

} // namespace motis::paxmon
Loading
Loading