Skip to content

Commit

Permalink
Merge pull request #958 from hove-io/tech/adapt_to_ntfs_v0.17.0_booki…
Browse files Browse the repository at this point in the history
…ng_rules

[tech] Adapt to ntfs v0.17.0 - Migrate ODTReservation to BookingRule
  • Loading branch information
ArnaudOggy authored Sep 3, 2024
2 parents 9cf5c47 + be58411 commit 4a580a2
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 159 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 <[email protected]>", "Guillaume Pinot <[email protected]>"]
name = "transit_model"
version = "0.65.0"
version = "0.66.0"
license = "AGPL-3.0-only"
description = "Transit data management"
repository = "https://github.com/hove-io/transit_model"
Expand Down
2 changes: 1 addition & 1 deletion src/add_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +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.booking_rules.prefix(prefix_conf);
self.equipments.prefix(prefix_conf);
self.transfers.prefix(prefix_conf);
self.trip_properties.prefix(prefix_conf);
Expand Down
4 changes: 2 additions & 2 deletions src/gtfs/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl Trip {
codes,
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: route.get_id_by_direction(self.direction),
physical_mode_id: physical_mode.id,
dataset_id: dataset.id.clone(),
Expand Down Expand Up @@ -1030,7 +1030,7 @@ fn make_lines(
codes,
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
name: r.long_name.to_string(),
forward_name: None,
backward_name: None,
Expand Down
6 changes: 3 additions & 3 deletions src/gtfs/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ mod tests {
codes: BTreeSet::new(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: "r:01".to_string(),
physical_mode_id: "pm:01".to_string(),
dataset_id: "ds:01".to_string(),
Expand Down Expand Up @@ -1326,7 +1326,7 @@ mod tests {
codes: BTreeSet::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
forward_name: None,
backward_name: None,
color: None,
Expand Down Expand Up @@ -1373,7 +1373,7 @@ mod tests {
codes: BTreeSet::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_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 {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.16.1";
pub const NTFS_VERSION: &str = "0.17.0";

/// The max distance in meters to compute the transfer
pub const TRANSFER_MAX_DISTANCE: &str = "300";
Expand Down
20 changes: 10 additions & 10 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct Collections {
pub calendars: CollectionWithId<Calendar>,
pub companies: CollectionWithId<Company>,
pub comments: CollectionWithId<Comment>,
pub odt_reservations: CollectionWithId<ODTReservation>,
pub booking_rules: CollectionWithId<BookingRule>,
pub equipments: CollectionWithId<Equipment>,
pub transfers: Collection<Transfer>,
pub trip_properties: CollectionWithId<TripProperty>,
Expand Down Expand Up @@ -218,7 +218,7 @@ impl Collections {
let mut data_sets_used = HashSet::<String>::new();
let mut physical_modes_used = HashSet::<String>::new();
let mut comments_used = HashSet::<String>::new();
let mut odt_reservations_used = HashSet::<String>::new();
let mut booking_rules_used = HashSet::<String>::new();
let mut level_id_used = HashSet::<String>::new();
let mut calendars_used = HashSet::<String>::new();
let mut vjs_used = HashSet::<String>::new();
Expand Down Expand Up @@ -254,8 +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()));
booking_rules_used
.extend(&mut vj.booking_rule_links.iter().map(|id| id.to_string()));
vjs_used.insert(vj.id.clone());
true
} else {
Expand Down Expand Up @@ -387,8 +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()));
booking_rules_used
.extend(&mut l.booking_rule_links.iter().map(|id| id.to_string()));
true
} else {
log_object_removed("Line", &l.id);
Expand Down Expand Up @@ -481,9 +481,9 @@ 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.booking_rules.retain(log_predicate(
"BookingRule",
|booking_rule: &BookingRule| booking_rules_used.contains(&booking_rule.id),
));

self.lines = CollectionWithId::new(lines)?;
Expand Down Expand Up @@ -2082,7 +2082,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: String::from("route_id"),
physical_mode_id: String::new(),
dataset_id: String::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/netex_france/route_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: String::from("route_id"),
physical_mode_id: String::from("Bus"),
dataset_id: String::from("dataset_id"),
Expand Down
69 changes: 33 additions & 36 deletions src/ntfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ struct CommentLink {
}

#[derive(Serialize, Deserialize, Debug, Clone)]
struct ODTReservationLink {
struct BookingRuleLink {
object_id: String,
object_type: ObjectType,
odt_reservation_id: String,
booking_rule_id: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -338,7 +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_booking_rules(&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)?;
Expand Down Expand Up @@ -413,7 +413,7 @@ pub fn write<P: AsRef<path::Path>>(
&model.stop_locations,
)?;
write::write_comments(path, model)?;
write::write_odt_reservations(path, model)?;
write::write_booking_rules(path, model)?;
write::write_codes(path, model)?;
write::write_object_properties(path, model)?;
write::write_fares_v1(path, model)?;
Expand Down Expand Up @@ -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.16.1".to_string()),
("ntfs_version".to_string(), "0.17.0".to_string()),
("tartare_platform".to_string(), "dev".to_string()),
],
collections
Expand Down Expand Up @@ -622,7 +622,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
forward_name: Some("Hôtels - Hôtels".to_string()),
backward_name: Some("Hôtels - Hôtels".to_string()),
color: Some(Rgb {
Expand All @@ -649,7 +649,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
forward_name: None,
backward_name: None,
color: None,
Expand Down Expand Up @@ -751,7 +751,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: "OIF:078078001:1".to_string(),
physical_mode_id: "Bus".to_string(),
dataset_id: "OIF:0".to_string(),
Expand Down Expand Up @@ -795,7 +795,7 @@ mod tests {
codes: KeysValues::default(),
object_properties: PropertiesMap::default(),
comment_links: LinksT::default(),
odt_reservation_links: LinksT::default(),
booking_rule_links: LinksT::default(),
route_id: "OIF:800:TER".to_string(),
physical_mode_id: "Bus".to_string(),
dataset_id: "OIF:0".to_string(),
Expand Down Expand Up @@ -1099,30 +1099,30 @@ mod tests {
])
.unwrap();

let odt_reservations = CollectionWithId::new(vec![
ODTReservation {
let booking_rules = CollectionWithId::new(vec![
BookingRule {
id: "odt:1".to_string(),
name: Some("name:1".to_string()),
url: Some("https://reservation1".to_string()),
info_url: Some("https://reservation1".to_string()),
phone: Some("01 02 03 04 01".to_string()),
condition: Some("lundi au vendredi de 9h à 18h".to_string()),
deeplink: Some("https://deeplink1".to_string()),
message: Some("lundi au vendredi de 9h à 18h".to_string()),
booking_url: Some("https://deeplink1".to_string()),
},
ODTReservation {
BookingRule {
id: "odt:2".to_string(),
name: None,
url: Some("https://reservation2".to_string()),
info_url: Some("https://reservation2".to_string()),
phone: Some("01 02 03 04 02".to_string()),
condition: Some("lundi au samedi de 8h à 15h".to_string()),
deeplink: Some("https://deeplink2".to_string()),
message: Some("lundi au samedi de 8h à 15h".to_string()),
booking_url: Some("https://deeplink2".to_string()),
},
ODTReservation {
BookingRule {
id: "odt:3".to_string(),
name: Some("name:3".to_string()),
url: Some("https://reservation3".to_string()),
info_url: Some("https://reservation3".to_string()),
phone: Some("01 02 03 04 03".to_string()),
condition: Some("lundi au mardi de 9h à 10h".to_string()),
deeplink: Some("https://deeplink3".to_string()),
message: Some("lundi au mardi de 9h à 10h".to_string()),
booking_url: Some("https://deeplink3".to_string()),
},
])
.unwrap();
Expand Down Expand Up @@ -1188,7 +1188,7 @@ mod tests {
"prop_value:3".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()]),
booking_rule_links: btree_set_from_vec(vec!["odt:1".to_string()]),
forward_name: None,
backward_name: None,
color: None,
Expand Down Expand Up @@ -1230,7 +1230,7 @@ mod tests {
"prop_value:6".to_string()
)],
comment_links: LinksT::default(),
odt_reservation_links: btree_set_from_vec(vec!["odt:2".to_string()]),
booking_rule_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(),
Expand Down Expand Up @@ -1275,7 +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.booking_rules = booking_rules;
ser_collections.stop_areas = stop_areas;
ser_collections.stop_points = stop_points;
ser_collections.stop_locations = stop_locations;
Expand Down Expand Up @@ -1306,7 +1306,7 @@ mod tests {
)
.unwrap();
write::write_comments(path, &ser_collections).unwrap();
write::write_odt_reservations(path, &ser_collections).unwrap();
write::write_booking_rules(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());
Expand All @@ -1321,15 +1321,12 @@ 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_booking_rules(&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
);
assert_eq!(ser_collections.booking_rules, des_collections.booking_rules);

// test comment links
assert_eq!(
Expand Down Expand Up @@ -1415,31 +1412,31 @@ mod tests {
des_collections.stop_time_comments
);

// test odt reservation links
// test booking rule links
assert_eq!(
ser_collections
.lines
.get("OIF:002002003:3OIF829")
.unwrap()
.odt_reservation_links,
.booking_rule_links,
des_collections
.lines
.get("OIF:002002003:3OIF829")
.unwrap()
.odt_reservation_links
.booking_rule_links
);

assert_eq!(
ser_collections
.vehicle_journeys
.get("VJ:1")
.unwrap()
.odt_reservation_links,
.booking_rule_links,
des_collections
.vehicle_journeys
.get("VJ:1")
.unwrap()
.odt_reservation_links
.booking_rule_links
);

// test codes
Expand Down
Loading

0 comments on commit 4a580a2

Please sign in to comment.