From a4d8d6aa32c13e8bc49410027e85994607e44147 Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 5 Sep 2024 15:07:41 -0600 Subject: [PATCH 1/5] doc typo --- rust/routee-compass/src/app/search/search_app_ops.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/routee-compass/src/app/search/search_app_ops.rs b/rust/routee-compass/src/app/search/search_app_ops.rs index d92821f1..7a2ac161 100644 --- a/rust/routee-compass/src/app/search/search_app_ops.rs +++ b/rust/routee-compass/src/app/search/search_app_ops.rs @@ -14,6 +14,7 @@ use crate::app::compass::config::config_json_extension::ConfigJsonExtensions; /// 1. from the traversal model /// 2. from the access model /// 3. optionally from the query itself +/// /// using the order above, each new source optionally overwrites any existing feature /// by name (tuple index 0) as long as they match in StateFeature::get_feature_name and /// StateFeature::get_feature_unit_name. From 9f762ee54ee207ee08152ddcb690491c188e1d46 Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 5 Sep 2024 15:07:57 -0600 Subject: [PATCH 2/5] cleanup while exploring causes of soc bug --- .../src/routee/energy_traversal_model.rs | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/rust/routee-compass-powertrain/src/routee/energy_traversal_model.rs b/rust/routee-compass-powertrain/src/routee/energy_traversal_model.rs index 9d4a1608..61743a58 100644 --- a/rust/routee-compass-powertrain/src/routee/energy_traversal_model.rs +++ b/rust/routee-compass-powertrain/src/routee/energy_traversal_model.rs @@ -131,21 +131,18 @@ impl EnergyTraversalModel { })? .to_string(); - let vehicle = match energy_model_service + let vehicle_lookup = energy_model_service .vehicle_library - .get(&prediction_model_name) - { - None => { - let model_names: Vec<&String> = - energy_model_service.vehicle_library.keys().collect(); - Err(TraversalModelError::BuildError(format!( - "No vehicle found with model_name = '{}', try one of: {:?}", - prediction_model_name, model_names - ))) - } - Some(mr) => Ok(mr.clone()), - }? - .update_from_query(conf)?; + .get(&prediction_model_name); + let vehicle_initial = vehicle_lookup.cloned().ok_or_else(|| { + let model_names: Vec<&String> = energy_model_service.vehicle_library.keys().collect(); + TraversalModelError::BuildError(format!( + "No vehicle found with model_name = '{}', try one of: {:?}", + prediction_model_name, model_names + )) + })?; + // allow user to customize this vehicle instance if applicable + let vehicle = vehicle_initial.update_from_query(conf)?; Ok(EnergyTraversalModel { energy_model_service, From ac2e1e6e9bdaa9a8effca50b84017b0ceed2a114 Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 5 Sep 2024 15:08:17 -0600 Subject: [PATCH 3/5] numeric (units) bug, pct vs ratio --- .../routee-compass-powertrain/src/routee/vehicle/default/bev.rs | 2 +- .../src/routee/vehicle/default/phev.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/routee-compass-powertrain/src/routee/vehicle/default/bev.rs b/rust/routee-compass-powertrain/src/routee/vehicle/default/bev.rs index 781c6d15..03548651 100644 --- a/rust/routee-compass-powertrain/src/routee/vehicle/default/bev.rs +++ b/rust/routee-compass-powertrain/src/routee/vehicle/default/bev.rs @@ -160,7 +160,7 @@ impl VehicleType for BEV { } let starting_battery_energy = - Energy::new(starting_soc_percent * self.battery_capacity.as_f64()); + Energy::new(0.01 * starting_soc_percent * self.battery_capacity.as_f64()); let new_bev = BEV { name: self.name.clone(), diff --git a/rust/routee-compass-powertrain/src/routee/vehicle/default/phev.rs b/rust/routee-compass-powertrain/src/routee/vehicle/default/phev.rs index 5c877c9c..0d37f967 100644 --- a/rust/routee-compass-powertrain/src/routee/vehicle/default/phev.rs +++ b/rust/routee-compass-powertrain/src/routee/vehicle/default/phev.rs @@ -189,7 +189,7 @@ impl VehicleType for PHEV { )); } let starting_battery_energy = - Energy::new(starting_soc_percent * self.battery_capacity.as_f64()); + Energy::new(0.01 * starting_soc_percent * self.battery_capacity.as_f64()); let new_phev = PHEV { name: self.name.clone(), From e89d2254855455eab42b628f89c54bc05fba1f86 Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 5 Sep 2024 15:14:34 -0600 Subject: [PATCH 4/5] clippy --- .../src/model/access/default/turn_delays/turn.rs | 8 +++++--- .../src/model/cost/vehicle/vehicle_cost_rate.rs | 2 +- .../src/model/state/unit_codec_name.rs | 11 +++++++---- rust/routee-compass-core/src/util/fs/read_utils.rs | 2 +- .../src/routee/vehicle/vehicle_ops.rs | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/rust/routee-compass-core/src/model/access/default/turn_delays/turn.rs b/rust/routee-compass-core/src/model/access/default/turn_delays/turn.rs index 41bc7c35..38d499c4 100644 --- a/rust/routee-compass-core/src/model/access/default/turn_delays/turn.rs +++ b/rust/routee-compass-core/src/model/access/default/turn_delays/turn.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use crate::model::access::access_model_error::AccessModelError; use serde::{Deserialize, Serialize}; @@ -14,9 +16,9 @@ pub enum Turn { UTurn, } -impl ToString for Turn { - fn to_string(&self) -> String { - serde_json::to_string(self).unwrap_or_else(|_| String::from("")) +impl Display for Turn { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", serde_json::to_string(self).unwrap_or_default()) } } diff --git a/rust/routee-compass-core/src/model/cost/vehicle/vehicle_cost_rate.rs b/rust/routee-compass-core/src/model/cost/vehicle/vehicle_cost_rate.rs index 0e9b66b0..4f744c72 100644 --- a/rust/routee-compass-core/src/model/cost/vehicle/vehicle_cost_rate.rs +++ b/rust/routee-compass-core/src/model/cost/vehicle/vehicle_cost_rate.rs @@ -17,7 +17,7 @@ pub enum VehicleCostRate { Factor { factor: f64, }, - /// + /// shift a value by some amount Offset { offset: f64, }, diff --git a/rust/routee-compass-core/src/model/state/unit_codec_name.rs b/rust/routee-compass-core/src/model/state/unit_codec_name.rs index 64634acf..ab5e66bb 100644 --- a/rust/routee-compass-core/src/model/state/unit_codec_name.rs +++ b/rust/routee-compass-core/src/model/state/unit_codec_name.rs @@ -1,3 +1,5 @@ +use std::fmt::Display; + use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize)] @@ -9,13 +11,14 @@ pub enum UnitCodecType { Boolean, } -impl ToString for UnitCodecType { - fn to_string(&self) -> String { - match self { +impl Display for UnitCodecType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let msg = match self { UnitCodecType::FloatingPoint => String::from("floating_point"), UnitCodecType::SignedInteger => String::from("signed_integer"), UnitCodecType::UnsignedInteger => String::from("unsigned_integer"), UnitCodecType::Boolean => String::from("boolean"), - } + }; + write!(f, "{}", msg) } } diff --git a/rust/routee-compass-core/src/util/fs/read_utils.rs b/rust/routee-compass-core/src/util/fs/read_utils.rs index 699f76bc..9a039eeb 100644 --- a/rust/routee-compass-core/src/util/fs/read_utils.rs +++ b/rust/routee-compass-core/src/util/fs/read_utils.rs @@ -70,7 +70,7 @@ where /// inspects the file to determine if it should read as a raw or gzip stream. /// the row index (starting from zero) is passed to the deserialization op /// as in most cases, the row number is an id. -pub fn read_raw_file<'a, F: AsRef, T>( +pub fn read_raw_file<'a, F, T>( filepath: F, op: impl Fn(usize, String) -> Result, row_callback: Option>, diff --git a/rust/routee-compass-powertrain/src/routee/vehicle/vehicle_ops.rs b/rust/routee-compass-powertrain/src/routee/vehicle/vehicle_ops.rs index 86273098..5c005683 100644 --- a/rust/routee-compass-powertrain/src/routee/vehicle/vehicle_ops.rs +++ b/rust/routee-compass-powertrain/src/routee/vehicle/vehicle_ops.rs @@ -45,7 +45,7 @@ pub fn update_soc_percent( /// the remaining battery as a percentage [0, 100] % pub fn as_soc_percent(remaining_battery: &Energy, max_battery: &Energy) -> f64 { let percent_remaining = (remaining_battery.as_f64() / max_battery.as_f64()) * 100.0; - percent_remaining.max(0.0).min(100.0) + percent_remaining.clamp(0.0, 100.0) } /// a capacitated vehicle's state of charge (SOC) is the inverse of the @@ -70,5 +70,5 @@ pub fn soc_from_battery_and_delta( ) -> f64 { let current_energy = *start_battery - *energy_used; let percent_remaining = (current_energy.as_f64() / max_battery.as_f64()) * 100.0; - percent_remaining.max(0.0).min(100.0) + percent_remaining.clamp(0.0, 100.0) } From 52df10eb1ac314dad32528889e85320915923d76 Mon Sep 17 00:00:00 2001 From: rfitzger Date: Thu, 5 Sep 2024 15:15:15 -0600 Subject: [PATCH 5/5] clippy --- .../default/turn_delays/turn_delay_access_model_engine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/routee-compass-core/src/model/access/default/turn_delays/turn_delay_access_model_engine.rs b/rust/routee-compass-core/src/model/access/default/turn_delays/turn_delay_access_model_engine.rs index 5f2fadf5..7fe963fa 100644 --- a/rust/routee-compass-core/src/model/access/default/turn_delays/turn_delay_access_model_engine.rs +++ b/rust/routee-compass-core/src/model/access/default/turn_delays/turn_delay_access_model_engine.rs @@ -28,7 +28,7 @@ impl TurnDelayAccessModelEngine { let turn = Turn::from_angle(angle)?; let delay = table.get(&turn).ok_or_else(|| { let name = String::from("tabular discrete turn delay model"); - let error = format!("table missing entry for turn {}", turn.to_string()); + let error = format!("table missing entry for turn {}", turn); AccessModelError::RuntimeError { name, error } })?; Ok((*delay, time_unit))