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

[feature] Auto-generate route.destination_id if missing #672

Merged
merged 1 commit into from
Jul 10, 2020
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 = ["Kisio Digital <[email protected]>", "Guillaume Pinot <[email protected]>"]
name = "transit_model"
version = "0.21.0"
version = "0.22.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/CanalTP/transit_model"
Expand Down
2 changes: 1 addition & 1 deletion gtfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../", features = ["proj"] }
transit_model = { version = "0.22", path = "../", features = ["proj"] }
2 changes: 1 addition & 1 deletion gtfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../" }
transit_model = { version = "0.22", path = "../" }
2 changes: 1 addition & 1 deletion ntfs2gtfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../" }
transit_model = { version = "0.22", path = "../" }
2 changes: 1 addition & 1 deletion ntfs2netexfr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../", features = ["proj"] }
transit_model = { version = "0.22", path = "../", features = ["proj"] }
2 changes: 1 addition & 1 deletion ntfs2ntfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../" }
transit_model = { version = "0.22", path = "../" }
2 changes: 1 addition & 1 deletion restrict-validity-period/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ slog-scope = "4.1"
slog-stdlog = "4.0"
slog-term = "2.4"
structopt = "0.3"
transit_model = { version = "0.21", path = "../" }
transit_model = { version = "0.22", path = "../" }
45 changes: 41 additions & 4 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,14 +944,20 @@ impl Collections {
let mut route_names: BTreeMap<Idx<Route>, String> = BTreeMap::new();
let mut route_destination_ids: BTreeMap<Idx<Route>, Option<String>> = BTreeMap::new();
for (route_idx, route) in &self.routes {
if route.name.is_empty() {
let no_route_name = route.name.is_empty();
let no_destination_id = route.destination_id.is_none();
if no_route_name || no_destination_id {
let (origin, destination) = skip_error_and_log!(
find_best_origin_destination(route_idx, &self, routes_to_vehicle_journeys,),
LogLevel::Warn
);
let route_name = format!("{} - {}", origin.name, destination.name);
route_names.insert(route_idx, route_name);
route_destination_ids.insert(route_idx, Some(destination.id.clone()));
if no_route_name {
let route_name = format!("{} - {}", origin.name, destination.name);
route_names.insert(route_idx, route_name);
}
if no_destination_id {
route_destination_ids.insert(route_idx, Some(destination.id.clone()));
}
}
}
for (route_idx, route_name) in route_names {
Expand Down Expand Up @@ -1620,6 +1626,34 @@ mod tests {
collections.enhance_route_names(&routes_to_vehicle_journeys);
let route = collections.routes.get("route_id").unwrap();
assert_eq!("Stop Area 1 - Stop Area 2", route.name);
assert_eq!("stop_area:2", route.destination_id.as_ref().unwrap());
}

#[test]
fn generate_destination_id() {
let mut collections = collections();
collections
.vehicle_journeys
.push(create_vehicle_journey_with(
"trip:1",
vec!["stop_point:1", "stop_point:2"],
&collections,
))
.unwrap();
let route_idx = collections.routes.get_idx("route_id").unwrap();
collections.routes.index_mut(route_idx).name = String::from("Route to Mordor");
collections.routes.index_mut(route_idx).destination_id = None;
let routes_to_vehicle_journeys = OneToMany::new(
&collections.routes,
&collections.vehicle_journeys,
"routes_to_vehicle_journeys",
)
.unwrap();
collections.enhance_route_names(&routes_to_vehicle_journeys);
let route = collections.routes.get("route_id").unwrap();
// Check route name hasn't been changed
assert_eq!("Route to Mordor", route.name);
assert_eq!("stop_area:2", route.destination_id.as_ref().unwrap());
}

#[test]
Expand Down Expand Up @@ -1658,6 +1692,7 @@ mod tests {
collections.enhance_route_names(&routes_to_vehicle_journeys);
let route = collections.routes.get("route_id").unwrap();
assert_eq!("Stop Area 1 - Stop Area 3", route.name);
assert_eq!("stop_area:3", route.destination_id.as_ref().unwrap());
}

#[test]
Expand Down Expand Up @@ -1694,6 +1729,7 @@ mod tests {
collections.enhance_route_names(&routes_to_vehicle_journeys);
let route = collections.routes.get("route_id").unwrap();
assert_eq!("Stop Area 1 - Stop Area 1", route.name);
assert_eq!("stop_area:1", route.destination_id.as_ref().unwrap());
}

#[test]
Expand Down Expand Up @@ -1737,6 +1773,7 @@ mod tests {
let route = collections.routes.get("route_id").unwrap();
// 'Stop Area 1' is before 'Stop Area 3' in alphabetical order
assert_eq!("Stop Area 1 - Stop Area 1", route.name);
assert_eq!("stop_area:1", route.destination_id.as_ref().unwrap());
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/fixtures/restrict-validity-period/output/routes.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
route_id,route_name,direction_type,line_id,geometry_id,destination_id
M1F,Nation - Charles de Gaulle,forward,M1,geo:2:kept,
M1B,Charles de Gaulle - Nation,forward,M1,,
B42F,Gare de Lyon - Montparnasse,forward,B42,,
B42B,Montparnasse - Gare de Lyon,forward,B42,,
M1B_R,Charles de Gaulle - Nation retour,forward,M1,,
B42F_R,Gare de Lyon - Montparnasse retour,forward,B42,,
B42B_R,Montparnasse - Gare de Lyon retour,forward,B42,,
M1F,Nation - Charles de Gaulle,forward,M1,geo:2:kept,GDL
M1B,Charles de Gaulle - Nation,forward,M1,,NAT
B42F,Gare de Lyon - Montparnasse,forward,B42,,MTP
B42B,Montparnasse - Gare de Lyon,forward,B42,,GDL
M1B_R,Charles de Gaulle - Nation retour,forward,M1,,GDL
B42F_R,Gare de Lyon - Montparnasse retour,forward,B42,,GDL
B42B_R,Montparnasse - Gare de Lyon retour,forward,B42,,GDL