Skip to content

Commit

Permalink
Merge pull request #861 from hove-io/add_missing_object_code
Browse files Browse the repository at this point in the history
Add missing object code
  • Loading branch information
patochectp committed Sep 20, 2022
2 parents 5b38d78 + 05bd780 commit 37e2b49
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
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 <team.coretools@kisio.com>", "Guillaume Pinot <texitoi@texitoi.eu>"]
name = "transit_model"
version = "0.51.1"
version = "0.51.2"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down
16 changes: 11 additions & 5 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ impl From<Agency> for objects::Network {
}
impl From<Agency> for objects::Company {
fn from(agency: Agency) -> objects::Company {
let id = agency.id.unwrap_or_else(default_agency_id);
let mut codes = KeysValues::default();
codes.insert(("source".to_string(), id.clone()));
objects::Company {
id: agency.id.unwrap_or_else(default_agency_id),
id,
name: agency.name,
address: None,
url: Some(agency.url),
mail: agency.email,
phone: agency.phone,
codes: BTreeSet::new(),
codes,
}
}
}
Expand Down Expand Up @@ -1003,11 +1006,12 @@ fn make_lines(

for routes in map_line_routes.values() {
let r = get_route_with_smallest_name(routes);

let mut codes = KeysValues::default();
codes.insert(("source".to_string(), r.id.clone()));
lines.push(objects::Line {
id: r.id.clone(),
code: line_code(r),
codes: KeysValues::default(),
codes,
object_properties: PropertiesMap::default(),
comment_links: CommentLinksT::default(),
name: r.long_name.to_string(),
Expand Down Expand Up @@ -1045,6 +1049,8 @@ 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()));
routes.push(objects::Route {
id: r.get_id_by_direction(d),
// When only one direction, keep the route name. When
Expand All @@ -1061,7 +1067,7 @@ fn make_routes(gtfs_trips: &[Trip], map_line_routes: &MapLineRoutes<'_>) -> Vec<
String::new()
},
direction_type: Some(get_direction_name(d)),
codes: KeysValues::default(),
codes,
object_properties: PropertiesMap::default(),
comment_links: CommentLinksT::default(),
line_id: sr.id.clone(),
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/gtfs2ntfs/full_output/object_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ trip,ME:WINTER:trip:5-0,source,trip:5
trip,ME:WINTER:trip:5-1,source,trip:5
trip,ME:WINTER:trip:5-2,source,trip:5
trip,ME:WINTER:trip:6,source,trip:6
company,ME:1,source,1
company,ME:2,source,2
route,ME:route:2,source,route:2
route,ME:route:3,source,route:3
line,ME:route:2,source,route:2
line,ME:route:3,source,route:3
6 changes: 6 additions & 0 deletions tests/fixtures/gtfs2ntfs/minimal/output/object_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ trip,trip:4,source,trip:4
trip,trip:5,source,trip:5
trip,trip:3,source,trip:3
trip,trip:6,source,trip:6
company,1,source,1
company,2,source,2
route,route:2,source,route:2
route,route:3,source,route:3
line,route:2,source,route:2
line,route:3,source,route:3
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ trip,trip:4,source,trip:4
trip,trip:5,source,trip:5
trip,trip:3,source,trip:3
trip,trip:6,source,trip:6
company,1,source,1
company,2,source,2
route,route:2,source,route:2
route,route:3,source,route:3
line,route:2,source,route:2
line,route:3,source,route:3
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ trip,trip:4,source,trip:4
trip,trip:5,source,trip:5
trip,trip:3,source,trip:3
trip,trip:6,source,trip:6
company,1,source,1
company,2,source,2
route,route:2,source,route:2
route,route:3,source,route:3
line,route:2,source,route:2
line,route:3,source,route:3

0 comments on commit 37e2b49

Please sign in to comment.