aboutsummaryrefslogtreecommitdiffstats
path: root/src/querykv1/journeyroute.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/journeyroute.cpp
downloadoeuf-17a3ea880402338420699e03bcb24181e4ff3924.tar.gz
oeuf-17a3ea880402338420699e03bcb24181e4ff3924.zip
Initial commit
Based on dc4ba6a
Diffstat (limited to 'src/querykv1/journeyroute.cpp')
-rw-r--r--src/querykv1/journeyroute.cpp96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/querykv1/journeyroute.cpp b/src/querykv1/journeyroute.cpp
new file mode 100644
index 0000000..013ea1c
--- /dev/null
+++ b/src/querykv1/journeyroute.cpp
@@ -0,0 +1,96 @@
1// vim:set sw=2 ts=2 sts et:
2
3#include <iostream>
4#include <string_view>
5
6#include "journeyroute.hpp"
7
8using namespace std::string_view_literals;
9
10void journeyRoute(const Options &options, Kv1Records &records, Kv1Index &index) {
11 FILE *out = stdout;
12 if (options.output_file_path != "-"sv)
13 out = fopen(options.output_file_path, "wb");
14 if (!out) {
15 fprintf(stderr, "Open %s: %s\n", options.output_file_path, strerrordesc_np(errno));
16 exit(EXIT_FAILURE);
17 }
18
19 for (auto &pujo : records.public_journeys) {
20 if (pujo.key.line_planning_number == options.line_planning_number && std::to_string(pujo.key.journey_number) == options.journey_number) {
21 fprintf(stderr, "Got PUJO %s/%s:\n", options.line_planning_number, options.journey_number);
22 fprintf(stderr, " Day type: %s\n", pujo.key.day_type.c_str());
23 auto &pegr = *pujo.p_period_group;
24 fprintf(stderr, " PEGR Code: %s\n", pegr.key.period_group_code.c_str());
25 fprintf(stderr, " PEGR Description: %s\n", pegr.description.c_str());
26 fprintf(stderr, " SPECDAY Code: %s\n", pujo.key.specific_day_code.c_str());
27 auto &timdemgrp = *pujo.p_time_demand_group;
28
29 for (auto &pegrval : records.period_group_validities) {
30 if (pegrval.key.period_group_code == pegr.key.period_group_code) {
31 fprintf(stderr, "Got PEGRVAL for PEGR %s\n", pegr.key.period_group_code.c_str());
32 std::cerr << " Valid from: " << pegrval.key.valid_from << std::endl;
33 std::cerr << " Valid thru: " << pegrval.valid_thru << std::endl;
34 }
35 }
36
37 struct Point {
38 Kv1JourneyPatternTimingLink *jopatili = nullptr;
39 Kv1TimeDemandGroupRunTime *timdemrnt = nullptr;
40 double distance_since_start_of_link = 0;
41 double rd_x = 0;
42 double rd_y = 0;
43 double total_time_s = 0;
44 };
45 std::vector<Point> points;
46
47 for (size_t i = 0; i < records.time_demand_group_run_times.size(); i++) {
48 Kv1TimeDemandGroupRunTime *timdemrnt = &records.time_demand_group_run_times[i];
49 if (timdemrnt->key.line_planning_number == timdemgrp.key.line_planning_number
50 && timdemrnt->key.journey_pattern_code == timdemgrp.key.journey_pattern_code
51 && timdemrnt->key.time_demand_group_code == timdemgrp.key.time_demand_group_code) {
52 Kv1JourneyPatternTimingLink *jopatili = timdemrnt->p_journey_pattern_timing_link;
53 for (auto &pool : records.point_on_links) {
54 if (pool.key.user_stop_code_begin == timdemrnt->user_stop_code_begin
55 && pool.key.user_stop_code_end == timdemrnt->user_stop_code_end
56 && pool.key.transport_type == jopatili->p_line->transport_type) {
57 points.emplace_back(
58 jopatili,
59 timdemrnt,
60 pool.distance_since_start_of_link,
61 pool.p_point->location_x_ew,
62 pool.p_point->location_y_ns
63 );
64 }
65 }
66 }
67 }
68
69 std::sort(points.begin(), points.end(), [](Point &a, Point &b) {
70 if (a.jopatili->key.timing_link_order != b.jopatili->key.timing_link_order)
71 return a.jopatili->key.timing_link_order < b.jopatili->key.timing_link_order;
72 return a.distance_since_start_of_link < b.distance_since_start_of_link;
73 });
74
75 double total_time_s = 0;
76 for (size_t i = 0; i < points.size(); i++) {
77 Point *p = &points[i];
78 p->total_time_s = total_time_s;
79 if (i > 0) {
80 Point *prev = &points[i - 1];
81 if (p->timdemrnt != prev->timdemrnt) {
82 total_time_s += prev->timdemrnt->total_drive_time_s;
83 prev->total_time_s = total_time_s;
84 }
85 }
86 }
87
88 fputs("rd_x,rd_y,total_time_s,is_timing_stop\n", out);
89 for (const auto &point : points) {
90 fprintf(out, "%f,%f,%f,%d\n", point.rd_x, point.rd_y, point.total_time_s, point.jopatili->is_timing_stop);
91 }
92 }
93 }
94
95 if (options.output_file_path != "-"sv) fclose(out);
96}