Skip to content

Commit

Permalink
Add 'source' object code for 'stop_point'
Browse files Browse the repository at this point in the history
  • Loading branch information
woshilapin committed Oct 8, 2019
1 parent 143ca3a commit e843e2c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
30 changes: 20 additions & 10 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ impl From<Agency> for objects::Company {

impl From<Stop> for objects::StopArea {
fn from(stop: Stop) -> objects::StopArea {
let mut stop_codes: KeysValues = BTreeSet::new();
let mut codes = KeysValues::default();
codes.insert(("source".to_string(), stop.id.clone()));
if let Some(c) = stop.code {
stop_codes.insert(("gtfs_stop_code".to_string(), c));
codes.insert(("gtfs_stop_code".to_string(), c));
}
objects::StopArea {
id: stop.id,
name: stop.name,
codes: stop_codes,
codes,
object_properties: KeysValues::default(),
comment_links: objects::CommentLinksT::default(),
coord: Coord {
Expand All @@ -109,14 +110,15 @@ impl From<Stop> for objects::StopArea {
}
impl From<Stop> for objects::StopPoint {
fn from(stop: Stop) -> objects::StopPoint {
let mut stop_codes: KeysValues = BTreeSet::new();
let mut codes = KeysValues::default();
codes.insert(("source".to_string(), stop.id.clone()));
if let Some(c) = stop.code {
stop_codes.insert(("gtfs_stop_code".to_string(), c));
codes.insert(("gtfs_stop_code".to_string(), c));
}
objects::StopPoint {
id: stop.id,
name: stop.name,
codes: stop_codes,
codes,
coord: Coord {
lon: stop.lon,
lat: stop.lat,
Expand Down Expand Up @@ -1224,18 +1226,26 @@ mod tests {
//validate stop_point code
assert_eq!(1, stop_points.len());
let stop_point = stop_points.iter().next().unwrap().1;
assert_eq!(1, stop_point.codes.len());
let code = stop_point.codes.iter().next().unwrap();
assert_eq!(2, stop_point.codes.len());
let mut codes_iterator = stop_point.codes.iter();
let code = codes_iterator.next().unwrap();
assert_eq!("gtfs_stop_code", code.0);
assert_eq!("1234", code.1);
let code = codes_iterator.next().unwrap();
assert_eq!("source", code.0);
assert_eq!("stoppoint_id", code.1);

//validate stop_area code
assert_eq!(1, stop_areas.len());
let stop_area = stop_areas.iter().next().unwrap().1;
assert_eq!(1, stop_area.codes.len());
let code = stop_area.codes.iter().next().unwrap();
assert_eq!(2, stop_area.codes.len());
let mut codes_iterator = stop_area.codes.iter();
let code = codes_iterator.next().unwrap();
assert_eq!("gtfs_stop_code", code.0);
assert_eq!("5678", code.1);
let code = codes_iterator.next().unwrap();
assert_eq!("source", code.0);
assert_eq!("stoparea_id", code.1);
});
}

Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/gtfs2ntfs/frequencies/output/object_codes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
object_type,object_id,object_system,object_code
network,1,source,1
stop_area,stoparea:1,source,stoparea:1
stop_point,stop:11,source,stop:11
stop_point,stop:12,source,stop:12
stop_point,stop:13,source,stop:13
stop_point,stop:14,source,stop:14
stop_point,stop:21,source,stop:21
stop_point,stop:22,source,stop:22
stop_point,stop:31,source,stop:31
stop_point,stop:32,source,stop:32
stop_point,stop:33,source,stop:33
stop_point,stop:51,source,stop:51
stop_point,stop:52,source,stop:52
stop_point,stop:53,source,stop:53
stop_point,stop:71,source,stop:71
stop_point,stop:72,source,stop:72
trip,trip:1-0,source,trip:1
trip,trip:1-1,source,trip:1
trip,trip:1-2,source,trip:1
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/gtfs2ntfs/minimal/output/object_codes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
object_type,object_id,object_system,object_code
network,1,source,1
stop_point,stop:11,source,stop:11
stop_point,stop:22,source,stop:22
stop_point,stop:31,source,stop:31
stop_point,stop:32,source,stop:32
stop_point,stop:33,source,stop:33
stop_point,stop:51,source,stop:51
stop_point,stop:52,source,stop:52
stop_point,stop:53,source,stop:53
stop_point,stop:61,source,stop:61
stop_area,stoparea:1,source,stoparea:1
trip,trip:3,source,trip:3
trip,trip:4,source,trip:4
trip,trip:5,source,trip:5
Expand Down

0 comments on commit e843e2c

Please sign in to comment.