diff --git a/documentation/ntfs_to_gtfs_specs.md b/documentation/ntfs_to_gtfs_specs.md index 894b98f99..a9ca94ddc 100644 --- a/documentation/ntfs_to_gtfs_specs.md +++ b/documentation/ntfs_to_gtfs_specs.md @@ -18,7 +18,6 @@ The following additional files are generated only if the corresponding objects a * [transfers](#transferstxt) * [shapes](#shapestxt) -* [stop_extensions](#stop_extensionstxt): additional information providing the complementary stop codes used in external systems. * [object_codes_extension](#object_codes_extensiontxt): additional information providing the complementary codes for various objects (stops, networks, lines, routes, trips, companies) used in external systems. [GTFS]: https://gtfs.org/reference/static @@ -157,17 +156,6 @@ This file is the same as the NTFS calendar_dates.txt file. All dates of service | shape_pt_lon | yes | geometries.txt | geometry_wkt | Longitude of the stop in the shape | | shape_pt_sequence | yes | | | Integer starting at 0 and increase by an increment of one for every point in the shape | -### stop_extensions.txt - -This file contains the complementary stop codes from the NTFS object_codes.txt file. If no additional stop code is specified, this file is not generated. -If N complementary codes are specified for a stop, there will be N separate lines in the file for the different stop_id/system_name pairs. - -| GTFS field | Required | NTFS file | NTFS field | Note | -| ----------- | -------- | ---------------- | ------------- | ----------------------------------------------------------------------------------------------------- | -| stop_id | yes | object_codes.txt | object_id | `stop_id` of the stop having a complementary code specified (link to the [stops.txt](#stopstxt) file) | -| system_name | yes | object_codes.txt | object_system | | -| system_code | yes | object_codes.txt | object_code | | - ### object_codes_extension.txt **Note**: This is a GTFS extension file (not part of the standard GTFS specification). diff --git a/ntfs2gtfs/tests/fixtures/stop_and_object_codes_extension/stop_extensions.txt b/ntfs2gtfs/tests/fixtures/stop_and_object_codes_extension/stop_extensions.txt deleted file mode 100644 index 59dc9fc01..000000000 --- a/ntfs2gtfs/tests/fixtures/stop_and_object_codes_extension/stop_extensions.txt +++ /dev/null @@ -1,40 +0,0 @@ -object_id,object_system,object_code -MFDI:22167,source,FR::Quay:22167:FR1 -MFDI:22173,source,FR::Quay:22173:FR1 -MFDI:22073,source,FR::Quay:22073:FR1 -MFDI:41403,source,FR::Quay:41403:FR1 -MFDI:463194,source,FR::Quay:463194:FR1 -MFDI:463042,source,FR::Quay:463042:FR1 -MFDI:426813,source,FR::Quay:426813:FR1 -MFDI:426214,source,FR::Quay:426214:FR1 -MFDI:477725,source,FR::Quay:477725:FR1 -MFDI:34582,source,FR::Quay:34582:FR1 -MFDI:38175,source,FR::Quay:38175:FR1 -MFDI:461909,source,FR::Quay:461909:FR1 -MFDI:18995,source,FR::Quay:18995:FR1 -MFDI:34605,source,FR::Quay:34605:FR1 -MFDI:34744,source,FR::Quay:34744:FR1 -MFDI:11584,source,FR::Quay:11584:FR1 -MFDI:14081,source,FR::Quay:14081:FR1 -MFDI:20324,source,FR::Quay:20324:FR1 -MFDI:20312,source,FR::Quay:20312:FR1 -MFDI:485179,source,FR::Quay:485179:FR1 -MFDI:461827,source,FR::multimodalStopPlace:461827:FR1 -MFDI:426072,source,FR::multimodalStopPlace:426072:FR1 -MFDI:71639,source,FR::multimodalStopPlace:71639:FR1 -MFDI:71673,source,FR::multimodalStopPlace:71673:FR1 -MFDI:64589,source,FR::multimodalStopPlace:64589:FR1 -MFDI:63880,source,FR::multimodalStopPlace:63880:FR1 -MFDI:71026,source,FR::multimodalStopPlace:71026:FR1 -MFDI:64509,source,FR::multimodalStopPlace:64509:FR1 -MFDI:64485,source,FR::multimodalStopPlace:64485:FR1 -MFDI:63534,source,FR::multimodalStopPlace:63534:FR1 -MFDI:63529,source,FR::multimodalStopPlace:63529:FR1 -MFDI:63438,source,FR::multimodalStopPlace:63438:FR1 -MFDI:73556,source,FR::multimodalStopPlace:73556:FR1 -MFDI:73596,source,FR::multimodalStopPlace:73596:FR1 -MFDI:73591,source,FR::multimodalStopPlace:73591:FR1 -MFDI:71347,source,FR::multimodalStopPlace:71347:FR1 -MFDI:73486,source,FR::multimodalStopPlace:73486:FR1 -MFDI:71199,source,FR::multimodalStopPlace:71199:FR1 -MFDI:480959,source,FR::multimodalStopPlace:480959:FR1 diff --git a/ntfs2gtfs/tests/ntfs2gtfs.rs b/ntfs2gtfs/tests/ntfs2gtfs.rs index bdaaada91..52b67aee9 100644 --- a/ntfs2gtfs/tests/ntfs2gtfs.rs +++ b/ntfs2gtfs/tests/ntfs2gtfs.rs @@ -220,7 +220,7 @@ fn test_ntfs2gtfs_with_pickup_drop_off_windows_stoptimes() { } #[test] -fn test_stop_and_object_codes_extension() { +fn test_object_codes_extension() { let output_dir = TempDir::new().expect("create temp dir failed"); Command::cargo_bin("ntfs2gtfs") .expect("Failed to find binary 'ntfs2gtfs'") @@ -232,7 +232,7 @@ fn test_stop_and_object_codes_extension() { .success(); compare_output_dir_with_expected( output_dir, - Some(vec!["stop_extensions.txt", "object_codes_extension.txt"]), + Some(vec!["object_codes_extension.txt"]), "./tests/fixtures/stop_and_object_codes_extension", ); } diff --git a/src/gtfs/mod.rs b/src/gtfs/mod.rs index 17b66002b..ba17988d1 100644 --- a/src/gtfs/mod.rs +++ b/src/gtfs/mod.rs @@ -828,7 +828,6 @@ pub fn write>(model: Model, path: P, extend_route_type: bool) -> let gtfs_trips = write::write_trips(path, &model)?; write::write_attributions(path, &model.companies, gtfs_trips)?; write::write_routes(path, &model, extend_route_type)?; - write::write_stop_extensions(path, &model.stop_points, &model.stop_areas)?; write::write_stop_times( path, &model.vehicle_journeys, diff --git a/src/gtfs/write.rs b/src/gtfs/write.rs index c40070b7f..eef706d3a 100644 --- a/src/gtfs/write.rs +++ b/src/gtfs/write.rs @@ -25,11 +25,11 @@ use crate::Result; use anyhow::Context; use geo::Geometry as GeoGeometry; use relational_types::IdxSet; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use std::collections::{HashMap, HashSet}; use std::path; use tracing::{info, warn}; -use typed_index_collection::{Collection, CollectionWithId, Id, Idx}; +use typed_index_collection::{Collection, CollectionWithId, Idx}; pub fn write_transfers(path: &path::Path, transfers: &Collection) -> Result<()> { if transfers.is_empty() { @@ -372,59 +372,6 @@ pub fn write_attributions( Ok(()) } -#[derive(Debug, Serialize, Deserialize, PartialEq)] -struct StopExtension { - #[serde(rename = "object_id")] - id: String, - #[serde(rename = "object_system")] - name: String, - #[serde(rename = "object_code")] - code: String, -} - -fn stop_extensions_from_collection_with_id( - collections: &CollectionWithId, -) -> impl Iterator + '_ -where - T: Id + Codes, -{ - collections - .values() - .flat_map(|obj| obj.codes().iter().map(move |c| (obj.id(), c))) - .map(|(id, (name, code))| StopExtension { - id: id.to_string(), - name: name.to_string(), - code: code.to_string(), - }) -} - -pub fn write_stop_extensions( - path: &path::Path, - stop_points: &CollectionWithId, - stop_areas: &CollectionWithId, -) -> Result<()> { - let mut stop_extensions = Vec::new(); - stop_extensions.extend(stop_extensions_from_collection_with_id(stop_points)); - stop_extensions.extend(stop_extensions_from_collection_with_id(stop_areas)); - if stop_extensions.is_empty() { - return Ok(()); - } - let file = "stop_extensions.txt"; - info!(file_name = %file, "Writing"); - - let path = path.join(file); - let mut wtr = - csv::Writer::from_path(&path).with_context(|| format!("Error reading {path:?}"))?; - for se in stop_extensions { - wtr.serialize(se) - .with_context(|| format!("Error reading {path:?}"))?; - } - wtr.flush() - .with_context(|| format!("Error reading {path:?}"))?; - - Ok(()) -} - #[derive(Serialize, Debug, Clone, Eq, Hash, PartialEq)] #[serde(rename_all = "snake_case")] pub enum GTFSObjectType { @@ -1282,75 +1229,6 @@ mod tests { assert_eq!(expected, make_gtfs_trip_from_ntfs_vj(&vj_coach, &model)); } - #[test] - fn ntfs_object_code_to_stop_extensions() { - let mut sa_codes: BTreeSet<(String, String)> = BTreeSet::new(); - sa_codes.insert(("sa name 1".to_string(), "sa_code_1".to_string())); - sa_codes.insert(("sa name 2".to_string(), "sa_code_2".to_string())); - let stop_areas = CollectionWithId::from(StopArea { - id: "sa:01".to_string(), - name: "sa:01".to_string(), - codes: sa_codes, - object_properties: PropertiesMap::default(), - comment_links: LinksT::default(), - visible: true, - coord: Coord { - lon: 2.073, - lat: 48.799, - }, - timezone: None, - geometry_id: None, - level_id: Some("level0".to_string()), - equipment_id: None, - address_id: None, - }); - let mut sp_codes: BTreeSet<(String, String)> = BTreeSet::new(); - sp_codes.insert(("sp name 1".to_string(), "sp_code_1".to_string())); - sp_codes.insert(("sp name 2".to_string(), "sp_code_2".to_string())); - sp_codes.insert(("sp name 3".to_string(), "sp_code_3".to_string())); - let stop_points = CollectionWithId::from(StopPoint { - id: "sp:01".to_string(), - name: "sp:01".to_string(), - codes: sp_codes, - visible: true, - coord: Coord { - lon: 2.073, - lat: 48.799, - }, - stop_area_id: "sa:01".to_string(), - stop_type: StopType::Point, - ..Default::default() - }); - let tmp_dir = tempdir().expect("create temp dir"); - write_stop_extensions(tmp_dir.path(), &stop_points, &stop_areas).unwrap(); - let output_file_path = tmp_dir.path().join("stop_extensions.txt"); - let mut output_file = File::open(output_file_path.clone()) - .unwrap_or_else(|_| panic!("file {:?} not found", output_file_path)); - let mut output_contents = String::new(); - output_file.read_to_string(&mut output_contents).unwrap(); - assert_eq!( - "object_id,object_system,object_code\n\ - sp:01,sp name 1,sp_code_1\n\ - sp:01,sp name 2,sp_code_2\n\ - sp:01,sp name 3,sp_code_3\n\ - sa:01,sa name 1,sa_code_1\n\ - sa:01,sa name 2,sa_code_2\n", - output_contents - ); - tmp_dir.close().expect("delete temp dir"); - } - - #[test] - fn ntfs_object_code_to_stop_extensions_nothing_generated() { - let stop_areas = CollectionWithId::default(); - let stop_points = CollectionWithId::default(); - let tmp_dir = tempdir().expect("create temp dir"); - write_stop_extensions(tmp_dir.path(), &stop_points, &stop_areas).unwrap(); - let output_file_path = tmp_dir.path().join("stop_extensions.txt"); - assert!(!output_file_path.exists()); - tmp_dir.close().expect("delete temp dir"); - } - #[test] fn ntfs_geometry_linestring_exported() { let geo = objects::Geometry {