From 9089c91f5513f1491cedf552a09c58c6fc6ef738 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Tue, 23 Jul 2024 15:12:09 +0200 Subject: [PATCH 1/7] Add ODT reservations for Line and Vehicle journey --- src/add_prefix.rs | 1 + src/file_handler/mod.rs | 1 + src/gtfs/read.rs | 2 + src/gtfs/write.rs | 7 ++- src/model.rs | 2 + src/netex_france/route_points.rs | 1 + src/ntfs/mod.rs | 79 +++++++++++++++++++++++++++++++- src/ntfs/read.rs | 78 ++++++++++++++++++++++++++++++- src/ntfs/write.rs | 67 ++++++++++++++++++++++++++- src/objects.rs | 51 +++++++++++++++++++++ 10 files changed, 283 insertions(+), 6 deletions(-) diff --git a/src/add_prefix.rs b/src/add_prefix.rs index bea7f985c..0f8e3768f 100644 --- a/src/add_prefix.rs +++ b/src/add_prefix.rs @@ -185,6 +185,7 @@ impl AddPrefix for Collections { self.calendars.prefix(prefix_conf); self.companies.prefix(prefix_conf); self.comments.prefix(prefix_conf); + self.odt_reservations.prefix(prefix_conf); self.equipments.prefix(prefix_conf); self.transfers.prefix(prefix_conf); self.trip_properties.prefix(prefix_conf); diff --git a/src/file_handler/mod.rs b/src/file_handler/mod.rs index b63521825..0c825f165 100644 --- a/src/file_handler/mod.rs +++ b/src/file_handler/mod.rs @@ -19,6 +19,7 @@ where /// Return a file if exist fn get_file_if_exists(self, name: &str) -> Result<(Option, PathBuf)>; + #[allow(dead_code)] /// Return a file or an error if not exist fn get_file(self, name: &str) -> Result<(Self::Reader, PathBuf)> { let (reader, path) = self.get_file_if_exists(name)?; diff --git a/src/gtfs/read.rs b/src/gtfs/read.rs index 6321ec5c2..af7d37ccf 100644 --- a/src/gtfs/read.rs +++ b/src/gtfs/read.rs @@ -334,6 +334,7 @@ impl Trip { codes, object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: route.get_id_by_direction(self.direction), physical_mode_id: physical_mode.id, dataset_id: dataset.id.clone(), @@ -1029,6 +1030,7 @@ fn make_lines( codes, object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), name: r.long_name.to_string(), forward_name: None, backward_name: None, diff --git a/src/gtfs/write.rs b/src/gtfs/write.rs index 4784a3a2f..303011caa 100644 --- a/src/gtfs/write.rs +++ b/src/gtfs/write.rs @@ -1251,6 +1251,7 @@ mod tests { codes: BTreeSet::new(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: "r:01".to_string(), physical_mode_id: "pm:01".to_string(), dataset_id: "ds:01".to_string(), @@ -1324,7 +1325,8 @@ mod tests { code: None, codes: BTreeSet::default(), object_properties: PropertiesMap::default(), - comment_links: BTreeSet::default(), + comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), forward_name: None, backward_name: None, color: None, @@ -1370,7 +1372,8 @@ mod tests { code: Some("DEF".to_string()), codes: BTreeSet::default(), object_properties: PropertiesMap::default(), - comment_links: BTreeSet::default(), + comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), forward_name: Some("Hôtels - Hôtels".to_string()), backward_name: Some("Hôtels - Hôtels".to_string()), color: Some(objects::Rgb { diff --git a/src/model.rs b/src/model.rs index 571b66297..2c2356641 100644 --- a/src/model.rs +++ b/src/model.rs @@ -87,6 +87,7 @@ pub struct Collections { pub calendars: CollectionWithId, pub companies: CollectionWithId, pub comments: CollectionWithId, + pub odt_reservations: CollectionWithId, pub equipments: CollectionWithId, pub transfers: Collection, pub trip_properties: CollectionWithId, @@ -2073,6 +2074,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: String::from("route_id"), physical_mode_id: String::new(), dataset_id: String::new(), diff --git a/src/netex_france/route_points.rs b/src/netex_france/route_points.rs index cc3c9cdcb..09bb37c64 100644 --- a/src/netex_france/route_points.rs +++ b/src/netex_france/route_points.rs @@ -127,6 +127,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: String::from("route_id"), physical_mode_id: String::from("Bus"), dataset_id: String::from("dataset_id"), diff --git a/src/ntfs/mod.rs b/src/ntfs/mod.rs index 0cbfb1f4c..b3be01374 100644 --- a/src/ntfs/mod.rs +++ b/src/ntfs/mod.rs @@ -141,6 +141,13 @@ struct CommentLink { comment_id: String, } +#[derive(Serialize, Deserialize, Debug, Clone)] +struct ODTReservationLink { + object_id: String, + object_type: ObjectType, + odt_reservation_id: String, +} + #[derive(Serialize, Deserialize, Debug, Clone)] struct Code { object_type: ObjectType, @@ -331,6 +338,7 @@ where read::manage_stop_times(&mut collections, file_handler)?; read::manage_codes(&mut collections, file_handler)?; read::manage_comments(&mut collections, file_handler)?; + read::manage_odt_reservations(&mut collections, file_handler)?; read::manage_object_properties(&mut collections, file_handler)?; read::manage_fares_v1(&mut collections, file_handler)?; read::manage_companies_on_vj(&mut collections)?; @@ -405,6 +413,7 @@ pub fn write>( &model.stop_locations, )?; write::write_comments(path, model)?; + write::write_odt_reservations(path, model)?; write::write_codes(path, model)?; write::write_object_properties(path, model)?; write::write_fares_v1(path, model)?; @@ -613,6 +622,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), forward_name: Some("Hôtels - Hôtels".to_string()), backward_name: Some("Hôtels - Hôtels".to_string()), color: Some(Rgb { @@ -639,6 +649,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), forward_name: None, backward_name: None, color: None, @@ -740,6 +751,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: "OIF:078078001:1".to_string(), physical_mode_id: "Bus".to_string(), dataset_id: "OIF:0".to_string(), @@ -783,6 +795,7 @@ mod tests { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: "OIF:800:TER".to_string(), physical_mode_id: "Bus".to_string(), dataset_id: "OIF:0".to_string(), @@ -1086,6 +1099,34 @@ mod tests { ]) .unwrap(); + let odt_reservations = CollectionWithId::new(vec![ + ODTReservation { + id: "odt:1".to_string(), + name: "name:1".to_string(), + url: Some("https://reservation1".to_string()), + phone: Some("01 02 03 04 01".to_string()), + conditions: Some("lundi au vendredi de 9h à 18h".to_string()), + deeplink: Some("https://deeplink1".to_string()), + }, + ODTReservation { + id: "odt:2".to_string(), + name: "name:2".to_string(), + url: Some("https://reservation2".to_string()), + phone: Some("01 02 03 04 02".to_string()), + conditions: Some("lundi au samedi de 8h à 15h".to_string()), + deeplink: Some("https://deeplink2".to_string()), + }, + ODTReservation { + id: "odt:3".to_string(), + name: "name:3".to_string(), + url: Some("https://reservation3".to_string()), + phone: Some("01 02 03 04 03".to_string()), + conditions: Some("lundi au mardi de 9h à 10h".to_string()), + deeplink: Some("https://deeplink3".to_string()), + }, + ]) + .unwrap(); + let stop_points = CollectionWithId::from(StopPoint { id: "sp_1".to_string(), name: "sp_name_1".to_string(), @@ -1146,7 +1187,8 @@ mod tests { "prop_name:3".to_string(), "prop_value:3".to_string() )], - comment_links: btree_set_from_vec(vec!["c:1".to_string(), "c:2".to_string()]), + comment_links: btree_set_from_vec(vec!["c:1".to_string()]), + odt_reservation_links: btree_set_from_vec(vec!["odt:1".to_string()]), forward_name: None, backward_name: None, color: None, @@ -1188,6 +1230,7 @@ mod tests { "prop_value:6".to_string() )], comment_links: CommentLinksT::default(), + odt_reservation_links: btree_set_from_vec(vec!["odt:2".to_string()]), route_id: "OIF:800:TER".to_string(), physical_mode_id: "Bus".to_string(), dataset_id: "OIF:0".to_string(), @@ -1232,6 +1275,7 @@ mod tests { stop_time_comments.insert(("VJ:1".to_string(), 0), "c:2".to_string()); ser_collections.comments = comments; + ser_collections.odt_reservations = odt_reservations; ser_collections.stop_areas = stop_areas; ser_collections.stop_points = stop_points; ser_collections.stop_locations = stop_locations; @@ -1262,6 +1306,7 @@ mod tests { ) .unwrap(); write::write_comments(path, &ser_collections).unwrap(); + write::write_odt_reservations(path, &ser_collections).unwrap(); write::write_codes(path, &ser_collections).unwrap(); write::write_object_properties(path, &ser_collections).unwrap(); let mut handler = PathFileHandler::new(path.to_path_buf()); @@ -1276,10 +1321,15 @@ mod tests { read::manage_stops(&mut des_collections, &mut handler).unwrap(); read::manage_stop_times(&mut des_collections, &mut handler).unwrap(); read::manage_comments(&mut des_collections, &mut handler).unwrap(); + read::manage_odt_reservations(&mut des_collections, &mut handler).unwrap(); read::manage_codes(&mut des_collections, &mut handler).unwrap(); read::manage_object_properties(&mut des_collections, &mut handler).unwrap(); assert_eq!(ser_collections.comments, des_collections.comments); + assert_eq!( + ser_collections.odt_reservations, + des_collections.odt_reservations + ); // test comment links assert_eq!( @@ -1365,6 +1415,33 @@ mod tests { des_collections.stop_time_comments ); + // test odt reservation links + assert_eq!( + ser_collections + .lines + .get("OIF:002002003:3OIF829") + .unwrap() + .odt_reservation_links, + des_collections + .lines + .get("OIF:002002003:3OIF829") + .unwrap() + .odt_reservation_links + ); + + assert_eq!( + ser_collections + .vehicle_journeys + .get("VJ:1") + .unwrap() + .odt_reservation_links, + des_collections + .vehicle_journeys + .get("VJ:1") + .unwrap() + .odt_reservation_links + ); + // test codes assert_eq!( ser_collections diff --git a/src/ntfs/read.rs b/src/ntfs/read.rs index 5446f35da..41ba1d848 100644 --- a/src/ntfs/read.rs +++ b/src/ntfs/read.rs @@ -12,7 +12,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see -use super::{Code, CommentLink, ObjectProperty, Stop, StopLocationType, StopTime}; +use super::{ + Code, CommentLink, ODTReservationLink, ObjectProperty, Stop, StopLocationType, StopTime, +}; use crate::file_handler::FileHandler; use crate::model::Collections; use crate::ntfs::has_fares_v2; @@ -473,6 +475,38 @@ fn insert_stop_time_comment_link( Ok(()) } +fn insert_odt_reservation_link( + collection: &mut CollectionWithId, + odt_reservations: &CollectionWithId, + link: &ODTReservationLink, +) -> Result<()> +where + T: ODTReservationLinks + Id, +{ + let idx = match collection.get_idx(&link.object_id) { + Some(idx) => idx, + None => { + error!( + "odt_reservation_links.txt: object_type={} object_id={} not found", + link.object_type.as_str(), + link.object_id + ); + return Ok(()); + } + }; + if !odt_reservations.contains_id(&link.odt_reservation_id) { + bail!( + "odt_reservations.txt: odt_reservation_id={} not found", + link.odt_reservation_id + ); + } + collection + .index_mut(idx) + .odt_reservation_links_mut() + .insert(link.odt_reservation_id.clone()); + Ok(()) +} + pub(crate) fn manage_comments(collections: &mut Collections, file_handler: &mut H) -> Result<()> where for<'a> &'a mut H: FileHandler, @@ -485,7 +519,7 @@ where } let comment_links = read_objects::<_, CommentLink>(file_handler, "comment_links.txt", false)?; - // invert the stop_time_ids map to search a stop_time by it's id + // invert the stop_time_ids map to search a stop_time by its id let stop_time_ids = collections .stop_time_ids .iter() @@ -537,6 +571,46 @@ where Ok(()) } +pub(crate) fn manage_odt_reservations( + collections: &mut Collections, + file_handler: &mut H, +) -> Result<()> +where + for<'a> &'a mut H: FileHandler, +{ + collections.odt_reservations = + make_opt_collection_with_id(file_handler, "odt_reservations.txt")?; + + if collections.odt_reservations.is_empty() { + return Ok(()); + } + let odt_reservations_links = + read_objects::<_, ODTReservationLink>(file_handler, "odt_reservation_links.txt", false)?; + + info!("Reading odt_reservations_links.txt"); + for link in odt_reservations_links { + match link.object_type { + ObjectType::Line => { + skip_error_and_warn!(insert_odt_reservation_link( + &mut collections.lines, + &collections.odt_reservations, + &link + )) + } + ObjectType::VehicleJourney => skip_error_and_warn!(insert_odt_reservation_link( + &mut collections.vehicle_journeys, + &collections.odt_reservations, + &link, + )), + _ => warn!( + "odt_reservation does not support {}", + link.object_type.as_str() + ), + } + } + Ok(()) +} + fn insert_object_property(collection: &mut CollectionWithId, obj_prop: ObjectProperty) where T: Properties + Id, diff --git a/src/ntfs/write.rs b/src/ntfs/write.rs index b00998e8c..df13fc420 100644 --- a/src/ntfs/write.rs +++ b/src/ntfs/write.rs @@ -12,7 +12,9 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see -use super::{Code, CommentLink, ObjectProperty, Result, Stop, StopLocationType, StopTime}; +use super::{ + Code, CommentLink, ODTReservationLink, ObjectProperty, Result, Stop, StopLocationType, StopTime, +}; use crate::model::Collections; use crate::ntfs::{has_fares_v1, has_fares_v2}; use crate::objects::*; @@ -630,6 +632,29 @@ where Ok(()) } +fn write_odt_reservation_links_from_collection_with_id( + wtr: &mut csv::Writer, + collection: &CollectionWithId, + path: &path::Path, +) -> Result<()> +where + T: Id + ODTReservationLinks + GetObjectType, + W: ::std::io::Write, +{ + for obj in collection.values() { + for id in obj.odt_reservation_links().iter() { + wtr.serialize(ODTReservationLink { + object_id: obj.id().to_string(), + object_type: T::get_object_type(), + odt_reservation_id: id.to_string(), + }) + .with_context(|| format!("Error reading {:?}", path))?; + } + } + + Ok(()) +} + fn write_stop_time_comment_links( wtr: &mut csv::Writer, stop_time_ids: &HashMap<(String, u32), String>, @@ -717,6 +742,46 @@ pub fn write_comments(path: &path::Path, collections: &Collections) -> Result<() Ok(()) } +pub fn write_odt_reservations(path: &path::Path, collections: &Collections) -> Result<()> { + if collections.odt_reservations.is_empty() { + return Ok(()); + } + info!("Writing odt_reservations.txt and odt_reservation_links.txt"); + + let odt_reservations_path = path.join("odt_reservations.txt"); + let odt_reservations_links_path = path.join("odt_reservation_links.txt"); + + let mut c_wtr = csv::Writer::from_path(&odt_reservations_path) + .with_context(|| format!("Error reading {:?}", odt_reservations_path))?; + let mut cl_wtr = csv::Writer::from_path(&odt_reservations_links_path) + .with_context(|| format!("Error reading {:?}", odt_reservations_links_path))?; + for c in collections.odt_reservations.values() { + c_wtr + .serialize(c) + .with_context(|| format!("Error reading {:?}", odt_reservations_path))?; + } + + write_odt_reservation_links_from_collection_with_id( + &mut cl_wtr, + &collections.lines, + &odt_reservations_links_path, + )?; + write_odt_reservation_links_from_collection_with_id( + &mut cl_wtr, + &collections.vehicle_journeys, + &odt_reservations_links_path, + )?; + + cl_wtr + .flush() + .with_context(|| format!("Error reading {:?}", odt_reservations_links_path))?; + c_wtr + .flush() + .with_context(|| format!("Error reading {:?}", odt_reservations_path))?; + + Ok(()) +} + fn write_codes_from_collection_with_id( wtr: &mut csv::Writer, collections: &CollectionWithId, diff --git a/src/objects.rs b/src/objects.rs index 5c93ac6c8..c2ef78f8d 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -147,6 +147,24 @@ macro_rules! impl_comment_links { }; } +pub trait ODTReservationLinks { + fn odt_reservation_links(&self) -> &CommentLinksT; + fn odt_reservation_links_mut(&mut self) -> &mut CommentLinksT; +} + +macro_rules! impl_odt_reservation_links { + ($ty:ty) => { + impl ODTReservationLinks for $ty { + fn odt_reservation_links(&self) -> &CommentLinksT { + &self.odt_reservation_links + } + fn odt_reservation_links_mut(&mut self) -> &mut CommentLinksT { + &mut self.odt_reservation_links + } + } + }; +} + #[derive(Serialize, Deserialize, Debug, Eq, PartialEq)] pub struct Contributor { #[serde(rename = "contributor_id")] @@ -472,6 +490,8 @@ pub struct Line { pub object_properties: PropertiesMap, #[serde(skip)] pub comment_links: CommentLinksT, + #[serde(skip)] + pub odt_reservation_links: CommentLinksT, #[serde(rename = "line_name")] pub name: String, #[serde(rename = "forward_line_name")] @@ -515,6 +535,7 @@ impl AddPrefix for Line { .take() .map(|id| prefix_conf.schedule_prefix(id.as_str())); self.comment_links.prefix(prefix_conf); + self.odt_reservation_links.prefix(prefix_conf); } } @@ -522,6 +543,7 @@ impl_codes!(Line); impl_properties!(Line); impl_comment_links!(Line); impl_with_id!(Line); +impl_odt_reservation_links!(Line); impl GetObjectType for Line { fn get_object_type() -> ObjectType { @@ -589,6 +611,8 @@ pub struct VehicleJourney { pub object_properties: PropertiesMap, #[serde(skip)] pub comment_links: CommentLinksT, + #[serde(skip)] + pub odt_reservation_links: CommentLinksT, pub route_id: String, pub physical_mode_id: String, pub dataset_id: String, @@ -616,6 +640,7 @@ impl Default for VehicleJourney { codes: KeysValues::default(), object_properties: PropertiesMap::default(), comment_links: CommentLinksT::default(), + odt_reservation_links: CommentLinksT::default(), route_id: "default_route".to_string(), physical_mode_id: "default_physical_mode".to_string(), dataset_id: "default_dataset".to_string(), @@ -654,11 +679,13 @@ impl AddPrefix for VehicleJourney { .take() .map(|id| prefix_conf.schedule_prefix(id.as_str())); self.comment_links.prefix(prefix_conf); + self.odt_reservation_links.prefix(prefix_conf); } } impl_codes!(VehicleJourney); impl_properties!(VehicleJourney); impl_comment_links!(VehicleJourney); +impl_odt_reservation_links!(VehicleJourney); impl WithId for VehicleJourney { fn with_id(id: &str) -> Self { @@ -1449,6 +1476,30 @@ impl AddPrefix for Comment { } } +#[derive(Default, Serialize, Deserialize, Debug, Eq, PartialEq)] +pub struct ODTReservation { + #[serde(rename = "odt_reservation_id")] + pub id: String, + #[serde(rename = "odt_reservation_name")] + pub name: String, + #[serde(rename = "odt_reservation_url")] + pub url: Option, + #[serde(rename = "odt_reservation_phone")] + pub phone: Option, + #[serde(rename = "odt_reservation_conditions")] + pub conditions: Option, + #[serde(rename = "odt_reservation_deeplink")] + pub deeplink: Option, +} + +impl_id!(ODTReservation); + +impl AddPrefix for ODTReservation { + fn prefix(&mut self, prefix_conf: &PrefixConfiguration) { + self.id = prefix_conf.schedule_prefix(self.id.as_str()); + } +} + #[derive( Serialize, Deserialize, Debug, Derivative, PartialOrd, Ord, PartialEq, Eq, Hash, Clone, Copy, )] From 042754a2e242d1373c88f01bb5bfdce80f468552 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Tue, 23 Jul 2024 18:20:46 +0200 Subject: [PATCH 2/7] sanitize --- src/model.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/model.rs b/src/model.rs index 2c2356641..b63ee22c6 100644 --- a/src/model.rs +++ b/src/model.rs @@ -218,6 +218,7 @@ impl Collections { let mut data_sets_used = HashSet::::new(); let mut physical_modes_used = HashSet::::new(); let mut comments_used = HashSet::::new(); + let mut odt_reservations_used = HashSet::::new(); let mut level_id_used = HashSet::::new(); let mut calendars_used = HashSet::::new(); let mut vjs_used = HashSet::::new(); @@ -253,6 +254,8 @@ impl Collections { data_sets_used.insert(vj.dataset_id.clone()); physical_modes_used.insert(vj.physical_mode_id.clone()); comments_used.extend(&mut vj.comment_links.iter().map(|cl| cl.to_string())); + odt_reservations_used + .extend(&mut vj.odt_reservation_links.iter().map(|id| id.to_string())); vjs_used.insert(vj.id.clone()); true } else { @@ -384,6 +387,8 @@ impl Collections { networks_used.insert(l.network_id.clone()); commercial_modes_used.insert(l.commercial_mode_id.clone()); comments_used.extend(&mut l.comment_links.iter().map(|cl| cl.to_string())); + odt_reservations_used + .extend(&mut l.odt_reservation_links.iter().map(|id| id.to_string())); true } else { log_object_removed("Line", &l.id); @@ -476,6 +481,11 @@ impl Collections { comments_used.contains(&comment.id) })); + self.odt_reservations.retain(log_predicate( + "ODTReservation", + |odt_reservation: &ODTReservation| odt_reservations_used.contains(&odt_reservation.id), + )); + self.lines = CollectionWithId::new(lines)?; self.stop_points = CollectionWithId::new(stop_points)?; let stop_point_old_idx_to_new_idx: HashMap, Idx> = self From 07a985b7b32399082c371ff5fa6ebbc256e827e1 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Wed, 24 Jul 2024 10:58:58 +0200 Subject: [PATCH 3/7] rename CommentLinksT to LinksT --- src/gtfs/read.rs | 18 ++++++------- src/gtfs/write.rs | 16 ++++++------ src/model.rs | 6 ++--- src/netex_france/route_points.rs | 6 ++--- src/ntfs/mod.rs | 26 +++++++++--------- src/ntfs/read.rs | 4 +-- src/objects.rs | 45 ++++++++++++++++---------------- 7 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/gtfs/read.rs b/src/gtfs/read.rs index af7d37ccf..56c0c501f 100644 --- a/src/gtfs/read.rs +++ b/src/gtfs/read.rs @@ -20,7 +20,7 @@ use crate::{ file_handler::FileHandler, model::Collections, objects::{ - self, Availability, CommentLinksT, Coord, KeysValues, Pathway, PropertiesMap, StopLocation, + self, Availability, Coord, KeysValues, LinksT, Pathway, PropertiesMap, StopLocation, StopPoint, StopTimePrecision, StopType, Time, TransportType, }, parser::{read_collection, read_objects, read_objects_loose}, @@ -113,7 +113,7 @@ impl TryFrom for objects::StopArea { name: stop.name, codes, object_properties: PropertiesMap::default(), - comment_links: objects::CommentLinksT::default(), + comment_links: objects::LinksT::default(), coord, timezone: stop.timezone, visible: true, @@ -207,7 +207,7 @@ impl TryFrom for objects::StopLocation { id: stop.id, name: stop.name, code: stop.code, - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: false, // disable for autocomplete coord, parent_id: stop.parent_station, @@ -333,8 +333,8 @@ impl Trip { id: self.id.clone(), codes, object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: route.get_id_by_direction(self.direction), physical_mode_id: physical_mode.id, dataset_id: dataset.id.clone(), @@ -776,7 +776,7 @@ where let mut stop_points = vec![]; let mut stop_locations = vec![]; for stop in gtfs_stops { - let mut comment_links = CommentLinksT::default(); + let mut comment_links = LinksT::default(); if let Some(comment) = generate_stop_comment(&stop) { comment_links.insert(comment.id.to_string()); comments @@ -1029,8 +1029,8 @@ fn make_lines( code: line_code(r), codes, object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), name: r.long_name.to_string(), forward_name: None, backward_name: None, @@ -1086,7 +1086,7 @@ fn make_routes(gtfs_trips: &[Trip], map_line_routes: &MapLineRoutes<'_>) -> Vec< direction_type: Some(get_direction_name(d)), codes, object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), line_id: sr.id.clone(), geometry_id: None, destination_id: None, diff --git a/src/gtfs/write.rs b/src/gtfs/write.rs index 303011caa..17a4f1100 100644 --- a/src/gtfs/write.rs +++ b/src/gtfs/write.rs @@ -550,7 +550,7 @@ mod tests { calendars::write_calendar_dates, gtfs::{Route, RouteType, StopLocationType, Transfer, TransferType}, model::Collections, - objects::{Calendar, CommentLinksT, Coord, StopPoint, StopTime, Transfer as NtfsTransfer}, + objects::{Calendar, Coord, LinksT, StopPoint, StopTime, Transfer as NtfsTransfer}, }; use geo::{line_string, point}; use pretty_assertions::assert_eq; @@ -1053,7 +1053,7 @@ mod tests { name: "sa:01".to_string(), codes: sa_codes, object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: true, coord: Coord { lon: 2.073, @@ -1250,8 +1250,8 @@ mod tests { id: "vj:01".to_string(), codes: BTreeSet::new(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: "r:01".to_string(), physical_mode_id: "pm:01".to_string(), dataset_id: "ds:01".to_string(), @@ -1325,8 +1325,8 @@ mod tests { code: None, codes: BTreeSet::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), forward_name: None, backward_name: None, color: None, @@ -1372,8 +1372,8 @@ mod tests { code: Some("DEF".to_string()), codes: BTreeSet::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), forward_name: Some("Hôtels - Hôtels".to_string()), backward_name: Some("Hôtels - Hôtels".to_string()), color: Some(objects::Rgb { diff --git a/src/model.rs b/src/model.rs index b63ee22c6..80eb6aeda 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1904,7 +1904,7 @@ mod tests { name: String::new(), ..Default::default() }; - let mut comment_links = CommentLinksT::default(); + let mut comment_links = LinksT::default(); comment_links.insert(comment.id.clone()); comment_links.insert(empty_comment.id.clone()); collections.comments.push(comment).unwrap(); @@ -2083,8 +2083,8 @@ mod tests { id: String::from(trip_id), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: String::from("route_id"), physical_mode_id: String::new(), dataset_id: String::new(), diff --git a/src/netex_france/route_points.rs b/src/netex_france/route_points.rs index 09bb37c64..d9f24b3a2 100644 --- a/src/netex_france/route_points.rs +++ b/src/netex_france/route_points.rs @@ -99,7 +99,7 @@ mod tests { mod build_route_points { use super::*; - use crate::objects::{CommentLinksT, KeysValues, PropertiesMap, StopTime, Time}; + use crate::objects::{KeysValues, LinksT, PropertiesMap, StopTime, Time}; use pretty_assertions::assert_eq; fn stop_time( @@ -126,8 +126,8 @@ mod tests { id, codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: String::from("route_id"), physical_mode_id: String::from("Bus"), dataset_id: String::from("dataset_id"), diff --git a/src/ntfs/mod.rs b/src/ntfs/mod.rs index b3be01374..53212f774 100644 --- a/src/ntfs/mod.rs +++ b/src/ntfs/mod.rs @@ -621,8 +621,8 @@ mod tests { code: Some("DEF".to_string()), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), forward_name: Some("Hôtels - Hôtels".to_string()), backward_name: Some("Hôtels - Hôtels".to_string()), color: Some(Rgb { @@ -648,8 +648,8 @@ mod tests { code: None, codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), forward_name: None, backward_name: None, color: None, @@ -694,7 +694,7 @@ mod tests { direction_type: Some("forward".to_string()), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), line_id: "OIF:002002002:BDEOIF829".to_string(), geometry_id: Some("Geometry:Line:Relation:6883353".to_string()), destination_id: Some("OIF,OIF:SA:4:126".to_string()), @@ -705,7 +705,7 @@ mod tests { direction_type: None, codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), line_id: "OIF:002002002:BDEOIF829".to_string(), geometry_id: None, destination_id: None, @@ -750,8 +750,8 @@ mod tests { id: "OIF:87604986-1_11595-1".to_string(), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: "OIF:078078001:1".to_string(), physical_mode_id: "Bus".to_string(), dataset_id: "OIF:0".to_string(), @@ -794,8 +794,8 @@ mod tests { id: "OIF:90014407-1_425283-1".to_string(), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: "OIF:800:TER".to_string(), physical_mode_id: "Bus".to_string(), dataset_id: "OIF:0".to_string(), @@ -1025,7 +1025,7 @@ mod tests { name: "sa_name_2".to_string(), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: true, coord: Coord { lon: 2.173_034, @@ -1042,7 +1042,7 @@ mod tests { name: "sa_name_1".to_string(), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: true, coord: Coord { lon: 2.073_034, @@ -1229,7 +1229,7 @@ mod tests { "prop_name:6".to_string(), "prop_value:6".to_string() )], - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), odt_reservation_links: btree_set_from_vec(vec!["odt:2".to_string()]), route_id: "OIF:800:TER".to_string(), physical_mode_id: "Bus".to_string(), diff --git a/src/ntfs/read.rs b/src/ntfs/read.rs index 41ba1d848..854f719a2 100644 --- a/src/ntfs/read.rs +++ b/src/ntfs/read.rs @@ -49,7 +49,7 @@ impl TryFrom for StopArea { name: stop.name, codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: stop.visible, coord, timezone: stop.timezone, @@ -142,7 +142,7 @@ impl TryFrom for StopLocation { id: stop.id, name: stop.name, code: stop.code, - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: false, // disable for autocomplete coord, parent_id: stop.parent_station, diff --git a/src/objects.rs b/src/objects.rs index c2ef78f8d..4ce9763a6 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -117,30 +117,31 @@ macro_rules! impl_properties { }; } -pub type CommentLinksT = BTreeSet; +/// Contains ids (comment or odt_reservation) linked with objects +pub type LinksT = BTreeSet; -impl AddPrefix for CommentLinksT { +impl AddPrefix for LinksT { fn prefix(&mut self, prefix_conf: &PrefixConfiguration) { let updated_ids = std::mem::take(self); *self = updated_ids .into_iter() - .map(|comment_id| prefix_conf.schedule_prefix(comment_id.as_str())) + .map(|id| prefix_conf.schedule_prefix(id.as_str())) .collect(); } } pub trait CommentLinks { - fn comment_links(&self) -> &CommentLinksT; - fn comment_links_mut(&mut self) -> &mut CommentLinksT; + fn comment_links(&self) -> &LinksT; + fn comment_links_mut(&mut self) -> &mut LinksT; } macro_rules! impl_comment_links { ($ty:ty) => { impl CommentLinks for $ty { - fn comment_links(&self) -> &CommentLinksT { + fn comment_links(&self) -> &LinksT { &self.comment_links } - fn comment_links_mut(&mut self) -> &mut CommentLinksT { + fn comment_links_mut(&mut self) -> &mut LinksT { &mut self.comment_links } } @@ -148,17 +149,17 @@ macro_rules! impl_comment_links { } pub trait ODTReservationLinks { - fn odt_reservation_links(&self) -> &CommentLinksT; - fn odt_reservation_links_mut(&mut self) -> &mut CommentLinksT; + fn odt_reservation_links(&self) -> &LinksT; + fn odt_reservation_links_mut(&mut self) -> &mut LinksT; } macro_rules! impl_odt_reservation_links { ($ty:ty) => { impl ODTReservationLinks for $ty { - fn odt_reservation_links(&self) -> &CommentLinksT { + fn odt_reservation_links(&self) -> &LinksT { &self.odt_reservation_links } - fn odt_reservation_links_mut(&mut self) -> &mut CommentLinksT { + fn odt_reservation_links_mut(&mut self) -> &mut LinksT { &mut self.odt_reservation_links } } @@ -489,9 +490,9 @@ pub struct Line { #[serde(skip)] pub object_properties: PropertiesMap, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, #[serde(skip)] - pub odt_reservation_links: CommentLinksT, + pub odt_reservation_links: LinksT, #[serde(rename = "line_name")] pub name: String, #[serde(rename = "forward_line_name")] @@ -566,7 +567,7 @@ pub struct Route { #[serde(skip)] pub object_properties: PropertiesMap, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, #[derivative(Default(value = "\"default_line\".into()"))] pub line_id: String, pub geometry_id: Option, @@ -610,9 +611,9 @@ pub struct VehicleJourney { #[serde(skip)] pub object_properties: PropertiesMap, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, #[serde(skip)] - pub odt_reservation_links: CommentLinksT, + pub odt_reservation_links: LinksT, pub route_id: String, pub physical_mode_id: String, pub dataset_id: String, @@ -639,8 +640,8 @@ impl Default for VehicleJourney { id: "default_vehiclejourney".to_string(), codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), - odt_reservation_links: CommentLinksT::default(), + comment_links: LinksT::default(), + odt_reservation_links: LinksT::default(), route_id: "default_route".to_string(), physical_mode_id: "default_physical_mode".to_string(), dataset_id: "default_dataset".to_string(), @@ -1092,7 +1093,7 @@ pub struct StopArea { #[serde(skip)] pub object_properties: PropertiesMap, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, pub visible: bool, pub coord: Coord, pub timezone: Option, @@ -1110,7 +1111,7 @@ impl From for StopArea { name: stop_point.name, codes: KeysValues::default(), object_properties: PropertiesMap::default(), - comment_links: CommentLinksT::default(), + comment_links: LinksT::default(), visible: stop_point.visible, coord: stop_point.coord, timezone: stop_point.timezone, @@ -1171,7 +1172,7 @@ pub struct StopPoint { #[serde(skip)] pub object_properties: PropertiesMap, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, pub visible: bool, pub coord: Coord, pub stop_area_id: String, @@ -1229,7 +1230,7 @@ pub struct StopLocation { pub name: String, pub code: Option, #[serde(skip)] - pub comment_links: CommentLinksT, + pub comment_links: LinksT, pub visible: bool, pub coord: Coord, pub parent_id: Option, From a5e382f125cf91eeb804259fba39fa8c31c2b5a5 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Wed, 24 Jul 2024 12:10:13 +0200 Subject: [PATCH 4/7] Same trait for Comment and ODTReservation --- src/gtfs/read.rs | 8 +++---- src/gtfs/write.rs | 4 ++-- src/model.rs | 16 ++++++-------- src/ntfs/read.rs | 8 +++---- src/ntfs/write.rs | 8 +++---- src/objects.rs | 54 ++++++++++++++++------------------------------- 6 files changed, 39 insertions(+), 59 deletions(-) diff --git a/src/gtfs/read.rs b/src/gtfs/read.rs index 56c0c501f..3d6d0c57c 100644 --- a/src/gtfs/read.rs +++ b/src/gtfs/read.rs @@ -20,8 +20,8 @@ use crate::{ file_handler::FileHandler, model::Collections, objects::{ - self, Availability, Coord, KeysValues, LinksT, Pathway, PropertiesMap, StopLocation, - StopPoint, StopTimePrecision, StopType, Time, TransportType, + self, Availability, Comment, Coord, KeysValues, LinksT, Pathway, PropertiesMap, + StopLocation, StopPoint, StopTimePrecision, StopType, Time, TransportType, }, parser::{read_collection, read_objects, read_objects_loose}, serde_utils::de_with_empty_default, @@ -635,7 +635,7 @@ fn generate_stop_comment(stop: &Stop) -> Option { }) } -fn insert_comment + objects::CommentLinks>( +fn insert_comment + objects::Links>( collection: &mut CollectionWithId, comments: &mut CollectionWithId, prefix: &str, @@ -651,7 +651,7 @@ fn insert_comment + objects::CommentLinks>( if let Some(comment) = opt_comment { if let Some(mut object) = collection.get_mut(>fs_route.id) { - object.comment_links_mut().insert(comment.id.to_string()); + object.links_mut().insert(comment.id.to_string()); comments .push(comment) .expect("Duplicated comment id that shouldn’t be possible"); diff --git a/src/gtfs/write.rs b/src/gtfs/write.rs index 17a4f1100..409dbfadb 100644 --- a/src/gtfs/write.rs +++ b/src/gtfs/write.rs @@ -108,11 +108,11 @@ pub fn write_ticketing_deep_links( } /// get the first comment ordered by name -fn get_first_comment_name( +fn get_first_comment_name>( obj: &T, comments: &CollectionWithId, ) -> Option { - obj.comment_links() + obj.links() .iter() .filter_map(|comment_id| comments.get(comment_id)) .map(|cmt| &cmt.name) diff --git a/src/model.rs b/src/model.rs index 80eb6aeda..7b5cedecf 100644 --- a/src/model.rs +++ b/src/model.rs @@ -954,13 +954,13 @@ impl Collections { collection: &mut CollectionWithId, duplicate2ref: &BTreeMap, ) where - T: Id + CommentLinks, + T: Id + Links, { let map_pt_object_duplicates: BTreeMap, Vec<&str>> = collection .iter() .filter_map(|(idx, pt_object)| { let intersection: Vec<&str> = pt_object - .comment_links() + .links() .iter() .filter_map(|comment_id| { duplicate2ref @@ -979,10 +979,8 @@ impl Collections { for (idx, intersection) in map_pt_object_duplicates { for i in intersection { let mut pt_object = collection.index_mut(idx); - pt_object.comment_links_mut().remove(i); - pt_object - .comment_links_mut() - .insert(duplicate2ref[i].clone()); + pt_object.links_mut().remove(i); + pt_object.links_mut().insert(duplicate2ref[i].clone()); } } } @@ -990,14 +988,14 @@ impl Collections { /// Remove comments with empty message from the model pub fn clean_comments(&mut self) { - fn remove_comment + CommentLinks>( + fn remove_comment + Links>( collection: &mut CollectionWithId, comment_id: &str, ) { let object_idxs: Vec> = collection .iter() .filter_map(|(idx, object)| { - if object.comment_links().contains(comment_id) { + if object.links().contains(comment_id) { Some(idx) } else { None @@ -1007,7 +1005,7 @@ impl Collections { for object_idx in object_idxs { collection .index_mut(object_idx) - .comment_links_mut() + .links_mut() .remove(comment_id); } } diff --git a/src/ntfs/read.rs b/src/ntfs/read.rs index 854f719a2..8bbd8e79f 100644 --- a/src/ntfs/read.rs +++ b/src/ntfs/read.rs @@ -424,7 +424,7 @@ fn insert_comment_link( comment_link: &CommentLink, ) -> Result<()> where - T: CommentLinks + Id, + T: Links + Id, { let idx = match collection.get_idx(&comment_link.object_id) { Some(idx) => idx, @@ -445,7 +445,7 @@ where } collection .index_mut(idx) - .comment_links_mut() + .links_mut() .insert(comment_link.comment_id.clone()); Ok(()) } @@ -481,7 +481,7 @@ fn insert_odt_reservation_link( link: &ODTReservationLink, ) -> Result<()> where - T: ODTReservationLinks + Id, + T: Links + Id, { let idx = match collection.get_idx(&link.object_id) { Some(idx) => idx, @@ -502,7 +502,7 @@ where } collection .index_mut(idx) - .odt_reservation_links_mut() + .links_mut() .insert(link.odt_reservation_id.clone()); Ok(()) } diff --git a/src/ntfs/write.rs b/src/ntfs/write.rs index df13fc420..176f290e4 100644 --- a/src/ntfs/write.rs +++ b/src/ntfs/write.rs @@ -615,11 +615,11 @@ fn write_comment_links_from_collection_with_id( path: &path::Path, ) -> Result<()> where - T: Id + CommentLinks + GetObjectType, + T: Id + Links + GetObjectType, W: ::std::io::Write, { for obj in collection.values() { - for comment_id in obj.comment_links().iter() { + for comment_id in obj.links().iter() { wtr.serialize(CommentLink { object_id: obj.id().to_string(), object_type: T::get_object_type(), @@ -638,11 +638,11 @@ fn write_odt_reservation_links_from_collection_with_id( path: &path::Path, ) -> Result<()> where - T: Id + ODTReservationLinks + GetObjectType, + T: Id + Links + GetObjectType, W: ::std::io::Write, { for obj in collection.values() { - for id in obj.odt_reservation_links().iter() { + for id in obj.links().iter() { wtr.serialize(ODTReservationLink { object_id: obj.id().to_string(), object_type: T::get_object_type(), diff --git a/src/objects.rs b/src/objects.rs index 4ce9763a6..1581693b2 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -130,37 +130,19 @@ impl AddPrefix for LinksT { } } -pub trait CommentLinks { - fn comment_links(&self) -> &LinksT; - fn comment_links_mut(&mut self) -> &mut LinksT; +pub trait Links { + fn links(&self) -> &LinksT; + fn links_mut(&mut self) -> &mut LinksT; } -macro_rules! impl_comment_links { - ($ty:ty) => { - impl CommentLinks for $ty { - fn comment_links(&self) -> &LinksT { - &self.comment_links - } - fn comment_links_mut(&mut self) -> &mut LinksT { - &mut self.comment_links - } - } - }; -} - -pub trait ODTReservationLinks { - fn odt_reservation_links(&self) -> &LinksT; - fn odt_reservation_links_mut(&mut self) -> &mut LinksT; -} - -macro_rules! impl_odt_reservation_links { - ($ty:ty) => { - impl ODTReservationLinks for $ty { - fn odt_reservation_links(&self) -> &LinksT { - &self.odt_reservation_links +macro_rules! impl_links { + ($ty:ty, $gen:ty, $field: ident) => { + impl Links<$gen> for $ty { + fn links(&self) -> &LinksT { + &self.$field } - fn odt_reservation_links_mut(&mut self) -> &mut LinksT { - &mut self.odt_reservation_links + fn links_mut(&mut self) -> &mut LinksT { + &mut self.$field } } }; @@ -542,9 +524,9 @@ impl AddPrefix for Line { impl_codes!(Line); impl_properties!(Line); -impl_comment_links!(Line); +impl_links!(Line, Comment, comment_links); +impl_links!(Line, ODTReservation, odt_reservation_links); impl_with_id!(Line); -impl_odt_reservation_links!(Line); impl GetObjectType for Line { fn get_object_type() -> ObjectType { @@ -593,7 +575,7 @@ impl AddPrefix for Route { } impl_codes!(Route); impl_properties!(Route); -impl_comment_links!(Route); +impl_links!(Route, Comment, comment_links); impl_with_id!(Route); impl GetObjectType for Route { @@ -685,8 +667,8 @@ impl AddPrefix for VehicleJourney { } impl_codes!(VehicleJourney); impl_properties!(VehicleJourney); -impl_comment_links!(VehicleJourney); -impl_odt_reservation_links!(VehicleJourney); +impl_links!(VehicleJourney, Comment, comment_links); +impl_links!(VehicleJourney, ODTReservation, odt_reservation_links); impl WithId for VehicleJourney { fn with_id(id: &str) -> Self { @@ -1143,7 +1125,7 @@ impl AddPrefix for StopArea { } impl_codes!(StopArea); impl_properties!(StopArea); -impl_comment_links!(StopArea); +impl_links!(StopArea, Comment, comment_links); impl_with_id!(StopArea); impl GetObjectType for StopArea { @@ -1215,7 +1197,7 @@ impl AddPrefix for StopPoint { } impl_codes!(StopPoint); impl_properties!(StopPoint); -impl_comment_links!(StopPoint); +impl_links!(StopPoint, Comment, comment_links); impl_with_id!(StopPoint); impl GetObjectType for StopPoint { @@ -1243,7 +1225,7 @@ pub struct StopLocation { pub address_id: Option, } impl_id!(StopLocation); -impl_comment_links!(StopLocation); +impl_links!(StopLocation, Comment, comment_links); impl AddPrefix for StopLocation { fn prefix(&mut self, prefix_conf: &PrefixConfiguration) { From f598c0007507b4ba8e1c2c0795beda911db11c79 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Tue, 23 Jul 2024 18:35:26 +0200 Subject: [PATCH 5/7] use NTFS v0.16.0 --- .../tests/fixtures/input_ntfs_with_fare_urls/feed_infos.txt | 2 +- src/lib.rs | 2 +- src/ntfs/mod.rs | 2 +- tests/fixtures/gtfs2ntfs/full_output/feed_infos.txt | 2 +- tests/fixtures/gtfs2ntfs/minimal/output/feed_infos.txt | 2 +- tests/fixtures/gtfs2ntfs/routes_comments/output/feed_infos.txt | 2 +- .../gtfs2ntfs/routes_comments/output_as_lines/feed_infos.txt | 2 +- tests/fixtures/restrict-validity-period/output/feed_infos.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ntfs2gtfs/tests/fixtures/input_ntfs_with_fare_urls/feed_infos.txt b/ntfs2gtfs/tests/fixtures/input_ntfs_with_fare_urls/feed_infos.txt index cdeb33458..2774a09fc 100644 --- a/ntfs2gtfs/tests/fixtures/input_ntfs_with_fare_urls/feed_infos.txt +++ b/ntfs2gtfs/tests/fixtures/input_ntfs_with_fare_urls/feed_infos.txt @@ -4,4 +4,4 @@ feed_creation_datetime,2024-07-03T12:49:20+00:00 feed_creation_time,12:49:20 feed_end_date,20181231 feed_start_date,20180101 -ntfs_version,0.15.0 +ntfs_version,0.16.0 diff --git a/src/lib.rs b/src/lib.rs index b46d8ef48..c1e29296c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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.15.0"; +pub const NTFS_VERSION: &str = "0.16.0"; /// The max distance in meters to compute the transfer pub const TRANSFER_MAX_DISTANCE: &str = "300"; diff --git a/src/ntfs/mod.rs b/src/ntfs/mod.rs index 53212f774..bdf51dac5 100644 --- a/src/ntfs/mod.rs +++ b/src/ntfs/mod.rs @@ -533,7 +533,7 @@ mod tests { ("feed_end_date".to_string(), "20180131".to_string()), ("feed_publisher_name".to_string(), "Nicaragua".to_string()), ("feed_start_date".to_string(), "20180130".to_string()), - ("ntfs_version".to_string(), "0.15.0".to_string()), + ("ntfs_version".to_string(), "0.16.0".to_string()), ("tartare_platform".to_string(), "dev".to_string()), ], collections diff --git a/tests/fixtures/gtfs2ntfs/full_output/feed_infos.txt b/tests/fixtures/gtfs2ntfs/full_output/feed_infos.txt index 3b8d94655..d014923c7 100644 --- a/tests/fixtures/gtfs2ntfs/full_output/feed_infos.txt +++ b/tests/fixtures/gtfs2ntfs/full_output/feed_infos.txt @@ -7,6 +7,6 @@ feed_license,DefaultDatasourceLicense feed_license_url,http://www.default-datasource-website.com feed_publisher_name,DefaultContributorName feed_start_date,20180101 -ntfs_version,0.15.0 +ntfs_version,0.16.0 tartare_contributor_id,DefaultContributorId tartare_platform,dev diff --git a/tests/fixtures/gtfs2ntfs/minimal/output/feed_infos.txt b/tests/fixtures/gtfs2ntfs/minimal/output/feed_infos.txt index 477c679f9..80a307091 100644 --- a/tests/fixtures/gtfs2ntfs/minimal/output/feed_infos.txt +++ b/tests/fixtures/gtfs2ntfs/minimal/output/feed_infos.txt @@ -4,4 +4,4 @@ feed_creation_time,17:19:00 feed_creation_datetime,2019-04-03T17:19:00+00:00 feed_end_date,20180106 feed_start_date,20180101 -ntfs_version,0.15.0 +ntfs_version,0.16.0 diff --git a/tests/fixtures/gtfs2ntfs/routes_comments/output/feed_infos.txt b/tests/fixtures/gtfs2ntfs/routes_comments/output/feed_infos.txt index 477c679f9..80a307091 100644 --- a/tests/fixtures/gtfs2ntfs/routes_comments/output/feed_infos.txt +++ b/tests/fixtures/gtfs2ntfs/routes_comments/output/feed_infos.txt @@ -4,4 +4,4 @@ feed_creation_time,17:19:00 feed_creation_datetime,2019-04-03T17:19:00+00:00 feed_end_date,20180106 feed_start_date,20180101 -ntfs_version,0.15.0 +ntfs_version,0.16.0 diff --git a/tests/fixtures/gtfs2ntfs/routes_comments/output_as_lines/feed_infos.txt b/tests/fixtures/gtfs2ntfs/routes_comments/output_as_lines/feed_infos.txt index 477c679f9..80a307091 100644 --- a/tests/fixtures/gtfs2ntfs/routes_comments/output_as_lines/feed_infos.txt +++ b/tests/fixtures/gtfs2ntfs/routes_comments/output_as_lines/feed_infos.txt @@ -4,4 +4,4 @@ feed_creation_time,17:19:00 feed_creation_datetime,2019-04-03T17:19:00+00:00 feed_end_date,20180106 feed_start_date,20180101 -ntfs_version,0.15.0 +ntfs_version,0.16.0 diff --git a/tests/fixtures/restrict-validity-period/output/feed_infos.txt b/tests/fixtures/restrict-validity-period/output/feed_infos.txt index 06d9e4e15..ba6f4a074 100644 --- a/tests/fixtures/restrict-validity-period/output/feed_infos.txt +++ b/tests/fixtures/restrict-validity-period/output/feed_infos.txt @@ -4,4 +4,4 @@ feed_creation_time,17:19:00 feed_creation_datetime,2019-04-03T17:19:00+00:00 feed_end_date,20180805 feed_start_date,20180501 -ntfs_version,0.15.0 +ntfs_version,0.16.0 From caa08f18e80d77d5d6e6de979853fd919764f4f8 Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Tue, 23 Jul 2024 18:31:01 +0200 Subject: [PATCH 6/7] bump 0.63.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 20059a7bc..39b2de27a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Hove ", "Guillaume Pinot "] name = "transit_model" -version = "0.62.3" +version = "0.63.0" license = "AGPL-3.0-only" description = "Transit data management" repository = "https://github.com/hove-io/transit_model" From 5b1eb73f0f35a3041fb1ad8cb0a7b60e1145eb5e Mon Sep 17 00:00:00 2001 From: David Quintanel Date: Mon, 29 Jul 2024 18:47:23 +0200 Subject: [PATCH 7/7] add ODTReservation::is_similar --- src/configuration.rs | 1 + src/objects.rs | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/configuration.rs b/src/configuration.rs index 46a0f04c9..03a721c42 100644 --- a/src/configuration.rs +++ b/src/configuration.rs @@ -39,6 +39,7 @@ struct Config { /// - a Contributor /// - a Dataset /// - a list of key/value which will be used in 'feed_infos.txt' +/// /// Below is an example of this file /// ```text /// { diff --git a/src/objects.rs b/src/objects.rs index 1581693b2..fe5258177 100644 --- a/src/objects.rs +++ b/src/objects.rs @@ -1475,6 +1475,15 @@ pub struct ODTReservation { pub deeplink: Option, } +impl ODTReservation { + pub fn is_similar(&self, other: &Self) -> bool { + self.url == other.url + && self.phone == other.phone + && self.conditions == other.conditions + && self.deeplink == other.deeplink + } +} + impl_id!(ODTReservation); impl AddPrefix for ODTReservation {