aboutsummaryrefslogtreecommitdiffstats
path: root/src/querykv1/journeyinfo.cpp
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2024-05-02 20:27:40 +0200
committerLibravatar Rutger Broekhoff2024-05-02 20:27:40 +0200
commit17a3ea880402338420699e03bcb24181e4ff3924 (patch)
treeda666ef91e0b60d20aa0b01529644c136fd1f4ab /src/querykv1/journeyinfo.cpp
downloadoeuf-17a3ea880402338420699e03bcb24181e4ff3924.tar.gz
oeuf-17a3ea880402338420699e03bcb24181e4ff3924.zip
Initial commit
Based on dc4ba6a
Diffstat (limited to 'src/querykv1/journeyinfo.cpp')
-rw-r--r--src/querykv1/journeyinfo.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/querykv1/journeyinfo.cpp b/src/querykv1/journeyinfo.cpp
new file mode 100644
index 0000000..bd29490
--- /dev/null
+++ b/src/querykv1/journeyinfo.cpp
@@ -0,0 +1,64 @@
1// vim:set sw=2 ts=2 sts et:
2
3#include <iostream>
4
5#include "journeyinfo.hpp"
6
7void journeyInfo(const Options &options, Kv1Records &records, Kv1Index &index) {
8 std::cout << "Info for journey " << options.line_planning_number
9 << "/" << options.journey_number << std::endl;
10
11 std::unordered_map<std::string, const Kv1UserStopPoint *> usrstops;
12 for (size_t i = 0; i < records.user_stop_points.size(); i++) {
13 const Kv1UserStopPoint *usrstop = &records.user_stop_points[i];
14 usrstops[usrstop->key.user_stop_code] = usrstop;
15 }
16
17 for (const auto &pujo : records.public_journeys) {
18 if (pujo.key.line_planning_number != options.line_planning_number
19 || std::to_string(pujo.key.journey_number) != options.journey_number)
20 continue;
21
22 std::vector<const Kv1JourneyPatternTimingLink *> timing_links;
23 for (size_t i = 0; i < records.journey_pattern_timing_links.size(); i++) {
24 const Kv1JourneyPatternTimingLink *jopatili = &records.journey_pattern_timing_links[i];
25 if (jopatili->key.line_planning_number != options.line_planning_number
26 || jopatili->key.journey_pattern_code != pujo.journey_pattern_code)
27 continue;
28 timing_links.push_back(jopatili);
29 }
30
31 std::sort(timing_links.begin(), timing_links.end(), [](auto a, auto b) -> bool {
32 return a->key.timing_link_order < b->key.timing_link_order;
33 });
34 auto begin_stop = timing_links.front()->user_stop_code_begin;
35 auto end_stop = timing_links.back()->user_stop_code_end;
36
37 const auto *begin = usrstops[begin_stop];
38 const auto *end = usrstops[end_stop];
39
40 std::cout << " Journey pattern: " << pujo.key.line_planning_number
41 << "/" << pujo.journey_pattern_code << std::endl
42 << " Begin stop: " << begin_stop
43 << "; name: " << std::quoted(begin->name)
44 << "; town: " << std::quoted(begin->town) << std::endl
45 << " End stop: " << end_stop
46 << "; name: " << std::quoted(end->name)
47 << "; town: " << std::quoted(end->town) << std::endl;
48
49 const auto *begin_star = begin->p_user_stop_area;
50 const auto *end_star = end->p_user_stop_area;
51 if (begin_star)
52 std::cout << " Begin stop area: " << begin_star->key.user_stop_area_code
53 << "; name: " << std::quoted(begin_star->name)
54 << ", town: " << std::quoted(begin_star->town)
55 << std::endl;
56 if (end_star)
57 std::cout << " End stop area: " << end_star->key.user_stop_area_code
58 << "; name: " << std::quoted(end_star->name)
59 << ", town: " << std::quoted(end_star->town)
60 << std::endl;
61
62 break;
63 }
64}