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

StopTimes - Move arrival_time/departure_time to Option<Time> #959

Merged
merged 5 commits into from
Sep 23, 2024
Merged
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
authors = ["Hove <core@hove.com>", "Guillaume Pinot <texitoi@texitoi.eu>"]
name = "transit_model"
version = "0.66.0"
version = "0.67.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down
12 changes: 8 additions & 4 deletions src/enhancers/check_stop_times_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ mod tests {
StopTime {
stop_point_idx,
sequence: 0,
arrival_time: Time::from_str(a_arrival).unwrap(),
departure_time: Time::from_str(a_departure).unwrap(),
arrival_time: Time::from_str(a_arrival).ok(),
departure_time: Time::from_str(a_departure).ok(),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -47,8 +49,10 @@ mod tests {
StopTime {
stop_point_idx,
sequence: 1,
arrival_time: FromStr::from_str(b_arrival).unwrap(),
departure_time: FromStr::from_str(b_departure).unwrap(),
arrival_time: FromStr::from_str(b_arrival).ok(),
departure_time: FromStr::from_str(b_departure).ok(),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand Down
30 changes: 20 additions & 10 deletions src/enhancers/enhance_pickup_dropoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ mod tests {
let stop_time_1 = StopTime {
stop_point_idx: sp_idxs[0],
sequence: 0,
arrival_time: prev_vj_config.2 - Time::new(1, 0, 0),
departure_time: prev_vj_config.3 - Time::new(1, 0, 0),
arrival_time: Some(prev_vj_config.2 - Time::new(1, 0, 0)),
departure_time: Some(prev_vj_config.3 - Time::new(1, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -214,8 +216,10 @@ mod tests {
let stop_time_2 = StopTime {
stop_point_idx: sp_idxs[prev_vj_config.1],
sequence: 0,
arrival_time: prev_vj_config.2,
departure_time: prev_vj_config.3,
arrival_time: Some(prev_vj_config.2),
departure_time: Some(prev_vj_config.3),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -227,8 +231,10 @@ mod tests {
let next_vj_config_time_1 = StopTime {
stop_point_idx: sp_idxs[next_vj_config.1],
sequence: 1,
arrival_time: next_vj_config.2,
departure_time: next_vj_config.3,
arrival_time: Some(next_vj_config.2),
departure_time: Some(next_vj_config.3),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -240,8 +246,10 @@ mod tests {
let next_vj_config_time_2 = StopTime {
stop_point_idx: sp_idxs[3],
sequence: 1,
arrival_time: next_vj_config.2 + Time::new(1, 0, 0),
departure_time: next_vj_config.3 + Time::new(1, 0, 0),
arrival_time: Some(next_vj_config.2 + Time::new(1, 0, 0)),
departure_time: Some(next_vj_config.3 + Time::new(1, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand Down Expand Up @@ -451,8 +459,10 @@ mod tests {
vj_mut.stop_times.push(StopTime {
stop_point_idx: sp4_idx,
sequence: 2,
arrival_time: Time::new(11, 30, 0),
departure_time: Time::new(11, 30, 0),
arrival_time: Some(Time::new(11, 30, 0)),
departure_time: Some(Time::new(11, 30, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 3,
Expand Down
75 changes: 50 additions & 25 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,10 @@ where
.push(objects::StopTime {
stop_point_idx,
sequence: stop_time.stop_sequence,
arrival_time: st_values.arrival_time,
departure_time: st_values.departure_time,
arrival_time: Some(st_values.arrival_time),
departure_time: Some(st_values.departure_time),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type,
Expand Down Expand Up @@ -1065,6 +1067,7 @@ fn make_routes(gtfs_trips: &[Trip], map_line_routes: &MapLineRoutes<'_>) -> Vec<
}

let has_one_direction = route_directions.len() <= 1;

for d in route_directions {
let mut codes = KeysValues::default();
codes.insert(("source".to_string(), r.id.clone()));
Expand Down Expand Up @@ -2415,8 +2418,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:01").unwrap(),
sequence: 1,
arrival_time: Time::new(6, 0, 0),
departure_time: Time::new(6, 0, 0),
arrival_time: Some(Time::new(6, 0, 0)),
departure_time: Some(Time::new(6, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -2427,8 +2432,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:02").unwrap(),
sequence: 2,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand All @@ -2439,8 +2446,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:03").unwrap(),
sequence: 3,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand Down Expand Up @@ -2507,8 +2516,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:01").unwrap(),
sequence: 1,
arrival_time: Time::new(6, 0, 0),
departure_time: Time::new(6, 0, 0),
arrival_time: Some(Time::new(6, 0, 0)),
departure_time: Some(Time::new(6, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -2519,8 +2530,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:02").unwrap(),
sequence: 2,
arrival_time: Time::new(6, 11, 0),
departure_time: Time::new(6, 11, 0),
arrival_time: Some(Time::new(6, 11, 0)),
departure_time: Some(Time::new(6, 11, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -2531,8 +2544,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:03").unwrap(),
sequence: 3,
arrival_time: Time::new(6, 22, 0),
departure_time: Time::new(6, 22, 0),
arrival_time: Some(Time::new(6, 22, 0)),
departure_time: Some(Time::new(6, 22, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand Down Expand Up @@ -2590,8 +2605,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:01").unwrap(),
sequence: 1,
arrival_time: Time::new(6, 0, 0),
departure_time: Time::new(6, 0, 0),
arrival_time: Some(Time::new(6, 0, 0)),
departure_time: Some(Time::new(6, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -2602,8 +2619,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:02").unwrap(),
sequence: 2,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand Down Expand Up @@ -3021,7 +3040,7 @@ mod tests {
collections.vehicle_journeys.into_vec()[0]
.stop_times
.iter()
.map(|st| (st.arrival_time, st.departure_time))
.map(|st| (st.arrival_time.unwrap(), st.departure_time.unwrap()))
.collect::<Vec<_>>()
);
});
Expand Down Expand Up @@ -3213,8 +3232,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:01").unwrap(),
sequence: 1,
arrival_time: Time::new(6, 0, 0),
departure_time: Time::new(6, 0, 0),
arrival_time: Some(Time::new(6, 0, 0)),
departure_time: Some(Time::new(6, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -3225,8 +3246,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:02").unwrap(),
sequence: 2,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand All @@ -3237,8 +3260,10 @@ mod tests {
StopTime {
stop_point_idx: collections.stop_points.get_idx("sp:03").unwrap(),
sequence: 3,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand Down
40 changes: 26 additions & 14 deletions src/gtfs/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ pub fn write_stop_times(
stop_id: stop_points[st.stop_point_idx].id.clone(),
trip_id: vj.id.clone(),
stop_sequence: st.sequence,
arrival_time: Some(st.arrival_time),
departure_time: Some(st.departure_time),
arrival_time: st.arrival_time,
departure_time: st.departure_time,
pickup_type: st.pickup_type,
drop_off_type: st.drop_off_type,
local_zone_id: st.local_zone_id,
Expand Down Expand Up @@ -953,8 +953,10 @@ mod tests {
objects::StopTime {
stop_point_idx: collections.stop_points.get_idx("OIF:SP:36:2085").unwrap(),
sequence: 0,
arrival_time: objects::Time::new(14, 40, 0),
departure_time: objects::Time::new(14, 40, 0),
arrival_time: Some(objects::Time::new(14, 40, 0)),
departure_time: Some(objects::Time::new(14, 40, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -965,8 +967,10 @@ mod tests {
objects::StopTime {
stop_point_idx: collections.stop_points.get_idx("OIF:SP:36:2127").unwrap(),
sequence: 1,
arrival_time: objects::Time::new(14, 42, 0),
departure_time: objects::Time::new(14, 42, 0),
arrival_time: Some(objects::Time::new(14, 42, 0)),
departure_time: Some(objects::Time::new(14, 42, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand Down Expand Up @@ -996,8 +1000,10 @@ mod tests {
objects::StopTime {
stop_point_idx: collections.stop_points.get_idx("OIF:SP:36:2085").unwrap(),
sequence: 0,
arrival_time: objects::Time::new(14, 40, 0),
departure_time: objects::Time::new(14, 40, 0),
arrival_time: Some(objects::Time::new(14, 40, 0)),
departure_time: Some(objects::Time::new(14, 40, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -1008,8 +1014,10 @@ mod tests {
objects::StopTime {
stop_point_idx: collections.stop_points.get_idx("OIF:SP:36:2127").unwrap(),
sequence: 1,
arrival_time: objects::Time::new(14, 42, 0),
departure_time: objects::Time::new(14, 42, 0),
arrival_time: Some(objects::Time::new(14, 42, 0)),
departure_time: Some(objects::Time::new(14, 42, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand Down Expand Up @@ -1224,8 +1232,10 @@ mod tests {
StopTime {
stop_point_idx: stop_points.get_idx("sp:01").unwrap(),
sequence: 1,
arrival_time: Time::new(6, 0, 0),
departure_time: Time::new(6, 0, 0),
arrival_time: Some(Time::new(6, 0, 0)),
departure_time: Some(Time::new(6, 0, 0)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 0,
Expand All @@ -1236,8 +1246,10 @@ mod tests {
StopTime {
stop_point_idx: stop_points.get_idx("sp:01").unwrap(),
sequence: 2,
arrival_time: Time::new(6, 6, 27),
departure_time: Time::new(6, 6, 27),
arrival_time: Some(Time::new(6, 6, 27)),
departure_time: Some(Time::new(6, 6, 27)),
start_pickup_drop_off_window: None,
end_pickup_drop_off_window: None,
boarding_duration: 0,
alighting_duration: 0,
pickup_type: 2,
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub mod vptranslator;
pub(crate) const STOP_TIMES_INIT_CAPACITY: usize = 50;

/// Current version of the NTFS format
pub const NTFS_VERSION: &str = "0.17.0";
pub const NTFS_VERSION: &str = "0.18.0";

/// The max distance in meters to compute the transfer
pub const TRANSFER_MAX_DISTANCE: &str = "300";
Expand Down
Loading