-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time-travel-robustness at beginning of trips (#162)
- Loading branch information
1 parent
255e31e
commit 973f636
Showing
3 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include "google/protobuf/util/json_util.h" | ||
|
||
#include "nigiri/loader/gtfs/files.h" | ||
#include "nigiri/loader/gtfs/load_timetable.h" | ||
#include "nigiri/loader/init_finish.h" | ||
#include "nigiri/rt/create_rt_timetable.h" | ||
#include "nigiri/rt/frun.h" | ||
#include "nigiri/rt/gtfsrt_resolve_run.h" | ||
#include "nigiri/rt/gtfsrt_update.h" | ||
#include "nigiri/rt/util.h" | ||
#include "nigiri/timetable.h" | ||
|
||
#include "./util.h" | ||
|
||
using namespace nigiri; | ||
using namespace nigiri::loader; | ||
using namespace nigiri::loader::gtfs; | ||
using namespace nigiri::rt; | ||
using namespace date; | ||
using namespace std::chrono_literals; | ||
using namespace std::string_literals; | ||
using namespace std::string_view_literals; | ||
|
||
namespace { | ||
|
||
mem_dir test_files() { | ||
return mem_dir::read(R"( | ||
"( | ||
# agency.txt | ||
agency_name,agency_url,agency_timezone,agency_lang,agency_phone,agency_id | ||
test,https://test.com,Europe/Berlin,DE,0800123456,AGENCY_1 | ||
# stops.txt | ||
stop_id,stop_name,stop_lat,stop_lon | ||
A,A,1.0,1.0 | ||
B,B,2.0,2.0 | ||
C,C,3.0,3.0 | ||
D,D,4.0,4.0 | ||
E,E,5.0,5.0 | ||
F,F,6.0,6.0 | ||
# calendar_dates.txt | ||
service_id,date,exception_type | ||
SERVICE_1,20231126,1 | ||
# routes.txt | ||
route_id,agency_id,route_short_name,route_long_name,route_type | ||
ROUTE_1,AGENCY_1,Route 1,,3 | ||
# trips.txt | ||
route_id,service_id,trip_id,trip_headsign,block_id, | ||
ROUTE_1,SERVICE_1,TRIP_1,E,, | ||
# stop_times.txt | ||
trip_id,arrival_time,departure_time,stop_id,stop_sequence,pickup_type,drop_off_type | ||
TRIP_1,10:00:00,10:00:00,A,1,0,0 | ||
TRIP_1,11:00:00,11:00:00,B,2,0,0 | ||
TRIP_1,12:00:00,12:00:00,C,3,0,0 | ||
TRIP_1,13:00:00,13:00:00,D,4,0,0 | ||
TRIP_1,14:00:00,14:00:00,E,5,0,0 | ||
TRIP_1,15:00:00,15:00:00,F,6,0,0 | ||
)"); | ||
} | ||
|
||
auto const kTripUpdate = | ||
R"({ | ||
"header": { | ||
"gtfsRealtimeVersion": "2.0", | ||
"incrementality": "FULL_DATASET", | ||
"timestamp": "1691660324" | ||
}, | ||
"entity": [ | ||
{ | ||
"id": "3248651", | ||
"isDeleted": false, | ||
"tripUpdate": { | ||
"trip": { | ||
"tripId": "TRIP_1", | ||
"startTime": "10:00:00", | ||
"startDate": "20231126" | ||
}, | ||
"stopTimeUpdate": [ | ||
{ | ||
"stop_sequence":3, | ||
"arrival":{"delay":-5400}, | ||
"departure":{"delay":-5400}, | ||
"schedule_relationship":"SCHEDULED" | ||
}, | ||
{ | ||
"stop_sequence":5, | ||
"arrival":{"delay":-5460}, | ||
"departure":{"delay":-5520}, | ||
"schedule_relationship":"SCHEDULED" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
})"s; | ||
|
||
constexpr auto const expected = R"( | ||
0: A A............................................... d: 26.11 09:00 [26.11 10:00] RT 26.11 09:00 [26.11 10:00] [{name=Bus Route 1, day=2023-11-26, id=TRIP_1, src=0}] | ||
1: B B............................................... a: 26.11 10:00 [26.11 11:00] RT 26.11 10:00 [26.11 11:00] d: 26.11 10:00 [26.11 11:00] RT 26.11 10:00 [26.11 11:00] [{name=Bus Route 1, day=2023-11-26, id=TRIP_1, src=0}] | ||
2: C C............................................... a: 26.11 11:00 [26.11 12:00] RT 26.11 10:00 [26.11 11:00] d: 26.11 11:00 [26.11 12:00] RT 26.11 10:00 [26.11 11:00] [{name=Bus Route 1, day=2023-11-26, id=TRIP_1, src=0}] | ||
3: D D............................................... a: 26.11 12:00 [26.11 13:00] RT 26.11 10:30 [26.11 11:30] d: 26.11 12:00 [26.11 13:00] RT 26.11 10:30 [26.11 11:30] [{name=Bus Route 1, day=2023-11-26, id=TRIP_1, src=0}] | ||
4: E E............................................... a: 26.11 13:00 [26.11 14:00] RT 26.11 11:29 [26.11 12:29] d: 26.11 13:00 [26.11 14:00] RT 26.11 11:29 [26.11 12:29] [{name=Bus Route 1, day=2023-11-26, id=TRIP_1, src=0}] | ||
5: F F............................................... a: 26.11 14:00 [26.11 15:00] RT 26.11 12:28 [26.11 13:28] | ||
)"sv; | ||
|
||
} // namespace | ||
|
||
TEST(rt, gtfs_rt_relative) { | ||
// Load static timetable. | ||
timetable tt; | ||
register_special_stations(tt); | ||
tt.date_range_ = {date::sys_days{2023_y / November / 25}, | ||
date::sys_days{2023_y / November / 27}}; | ||
load_timetable({}, source_idx_t{0}, test_files(), tt); | ||
finalize(tt); | ||
|
||
// Create empty RT timetable. | ||
auto rtt = | ||
rt::create_rt_timetable(tt, date::sys_days{2023_y / November / 26}); | ||
|
||
// Update. | ||
auto const msg = rt::json_to_protobuf(kTripUpdate); | ||
gtfsrt_update_buf(tt, rtt, source_idx_t{0}, "", msg); | ||
|
||
// Print trip. | ||
transit_realtime::TripDescriptor td; | ||
td.set_start_date("20231126"); | ||
td.set_trip_id("TRIP_1"); | ||
td.set_start_time("10:00:00"); | ||
auto const [r, t] = rt::gtfsrt_resolve_run( | ||
date::sys_days{2023_y / November / 26}, tt, &rtt, source_idx_t{0}, td); | ||
ASSERT_TRUE(r.valid()); | ||
|
||
auto ss = std::stringstream{}; | ||
ss << "\n" << rt::frun{tt, &rtt, r}; | ||
EXPECT_EQ(expected, ss.str()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters