diff --git a/rust/routee-compass-core/src/model/cost/network/network_cost_rate_builder.rs b/rust/routee-compass-core/src/model/cost/network/network_cost_rate_builder.rs index f5b7a811..fe17a7ce 100644 --- a/rust/routee-compass-core/src/model/cost/network/network_cost_rate_builder.rs +++ b/rust/routee-compass-core/src/model/cost/network/network_cost_rate_builder.rs @@ -7,6 +7,7 @@ use crate::{ }, util::fs::read_utils, }; +use kdam::Bar; use serde::{Deserialize, Serialize}; use std::collections::HashMap; @@ -30,8 +31,7 @@ impl NetworkCostRateBuilder { let lookup = read_utils::from_csv::( cost_input_file, true, - Some("network edge cost lookup"), - None, + Some(Bar::builder().desc("network edge cost lookup")), None, ) .map_err(|source| { @@ -49,8 +49,7 @@ impl NetworkCostRateBuilder { let lookup = read_utils::from_csv::( cost_input_file, true, - Some("network edge->edge cost lookup"), - None, + Some(Bar::builder().desc("network edge->edge cost lookup")), None, ) .map_err(|source| { diff --git a/rust/routee-compass-core/src/model/map/geometry_model.rs b/rust/routee-compass-core/src/model/map/geometry_model.rs index 55b6de04..94a8f7f5 100644 --- a/rust/routee-compass-core/src/model/map/geometry_model.rs +++ b/rust/routee-compass-core/src/model/map/geometry_model.rs @@ -6,7 +6,7 @@ use crate::{ util::{fs::read_utils, geo::geo_io_utils}, }; use geo::LineString; -use kdam::BarExt; +use kdam::{Bar, BarExt}; /// model for link geometries by edge id. can be constructed either /// from edge geometry dataset ([`GeometryModel::new_from_edges`]) or @@ -50,8 +50,7 @@ fn read_linestrings( let geoms = read_utils::read_raw_file( geometry_input_file, geo_io_utils::parse_wkt_linestring, - Some("link geometries"), - Some(n_edges), + Some(Bar::builder().desc("link geometries").total(n_edges)), None, ) .map_err(|e: std::io::Error| { @@ -179,8 +178,7 @@ mod tests { #[test] fn test_geometry_deserialization() { - let result = - read_raw_file(mock_geometry_file(), parse_wkt_linestring, None, None, None).unwrap(); + let result = read_raw_file(mock_geometry_file(), parse_wkt_linestring, None, None).unwrap(); assert_eq!(result.len(), 3); } diff --git a/rust/routee-compass-core/src/model/network/graph.rs b/rust/routee-compass-core/src/model/network/graph.rs index 3560f0ce..6ad52274 100644 --- a/rust/routee-compass-core/src/model/network/graph.rs +++ b/rust/routee-compass-core/src/model/network/graph.rs @@ -4,6 +4,7 @@ use crate::util::compact_ordered_hash_map::CompactOrderedHashMap; use crate::util::fs::read_utils; use allocative::Allocative; use itertools::Itertools; +use kdam::Bar; use std::collections::HashSet; use std::path::Path; @@ -50,9 +51,13 @@ impl Graph { edge_list_csv: &P, vertex_list_csv: &P, ) -> Result { - let vertices: Box<[Vertex]> = - read_utils::from_csv(&vertex_list_csv, true, Some("graph vertices"), None, None) - .map_err(|e| NetworkError::CsvError { source: e })?; + let vertices: Box<[Vertex]> = read_utils::from_csv( + &vertex_list_csv, + true, + Some(Bar::builder().desc("graph vertices")), + None, + ) + .map_err(|e| NetworkError::CsvError { source: e })?; let mut adj: Vec> = vec![CompactOrderedHashMap::empty(); vertices.len()]; @@ -79,8 +84,13 @@ impl Graph { } }); - let edges = read_utils::from_csv(&edge_list_csv, true, Some("graph edges"), None, Some(cb)) - .map_err(|e| NetworkError::CsvError { source: e })?; + let edges = read_utils::from_csv( + &edge_list_csv, + true, + Some(Bar::builder().desc("graph edges")), + Some(cb), + ) + .map_err(|e| NetworkError::CsvError { source: e })?; let graph = Graph { adj: adj.into_boxed_slice(), diff --git a/rust/routee-compass-core/src/model/traversal/default/speed_traversal_engine.rs b/rust/routee-compass-core/src/model/traversal/default/speed_traversal_engine.rs index eedf248f..689f2e3f 100644 --- a/rust/routee-compass-core/src/model/traversal/default/speed_traversal_engine.rs +++ b/rust/routee-compass-core/src/model/traversal/default/speed_traversal_engine.rs @@ -1,3 +1,5 @@ +use kdam::Bar; + use crate::model::unit::DistanceUnit; use crate::model::unit::{SpeedUnit, TimeUnit, BASE_DISTANCE_UNIT, BASE_TIME_UNIT}; use crate::util::fs::read_decoders; @@ -25,8 +27,7 @@ impl SpeedTraversalEngine { let speed_table: Box<[Speed]> = read_utils::read_raw_file( speed_table_path, read_decoders::default, - Some("link speeds"), - None, + Some(Bar::builder().desc("link speeds")), None, ) .map_err(|e| { 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 87bdbfcc..2cc57cdf 100644 --- a/rust/routee-compass-core/src/util/fs/read_utils.rs +++ b/rust/routee-compass-core/src/util/fs/read_utils.rs @@ -1,7 +1,7 @@ use super::fs_utils; use csv::ReaderBuilder; use flate2::read::GzDecoder; -use kdam::{Bar, BarExt}; +use kdam::{BarBuilder, BarExt}; use std::{ fs::File, @@ -52,19 +52,13 @@ where pub fn from_csv<'a, T>( filepath: &dyn AsRef, has_headers: bool, - progress_message: Option<&str>, - progress_size: Option, + progress: Option, callback: CsvCallback<'a, T>, ) -> Result, csv::Error> where T: serde::de::DeserializeOwned + 'a, { - let bar_opt = match (progress_message, progress_size) { - (Some(desc), Some(total)) => Bar::builder().desc(desc).total(total).build().ok(), - (Some(desc), None) => Bar::builder().desc(desc).build().ok(), - (None, Some(total)) => Bar::builder().total(total).build().ok(), - _ => None, - }; + let bar_opt = progress.and_then(|b| b.build().ok()); let row_callback: CsvCallback<'a, T> = match (callback, bar_opt) { (None, None) => None, @@ -95,19 +89,13 @@ where pub fn read_raw_file( filepath: F, op: impl Fn(usize, String) -> Result, - progress_message: Option<&str>, - progress_size: Option, + progress: Option, callback: Option>, ) -> Result, io::Error> where F: AsRef, { - let bar_opt = match (progress_message, progress_size) { - (Some(desc), Some(total)) => Bar::builder().desc(desc).total(total).build().ok(), - (Some(desc), None) => Bar::builder().desc(desc).build().ok(), - (None, Some(total)) => Bar::builder().total(total).build().ok(), - _ => None, - }; + let bar_opt = progress.and_then(|b| b.build().ok()); let row_callback: RawCallback = match (callback, bar_opt) { (None, None) => None, @@ -192,7 +180,7 @@ mod tests { println!("loading file {:?}", filepath); let bonus_word = " yay"; let op = |_idx: usize, row: String| Ok(row + bonus_word); - let result = read_raw_file(&filepath, op, None, None, None).unwrap(); + let result = read_raw_file(&filepath, op, None, None).unwrap(); let expected = vec![ String::from("RouteE yay"), String::from("FASTSim yay"), @@ -217,7 +205,7 @@ mod tests { println!("loading file {:?}", filepath); let bonus_word = " yay"; let op = |_idx: usize, row: String| Ok(row + bonus_word); - let result = read_raw_file(&filepath, op, None, None, None).unwrap(); + let result = read_raw_file(&filepath, op, None, None).unwrap(); let expected = vec![ String::from("RouteE yay"), String::from("FASTSim yay"), diff --git a/rust/routee-compass-powertrain/Cargo.toml b/rust/routee-compass-powertrain/Cargo.toml index 70e9a20f..a37e45d8 100644 --- a/rust/routee-compass-powertrain/Cargo.toml +++ b/rust/routee-compass-powertrain/Cargo.toml @@ -16,6 +16,7 @@ smartcore = { version = "0.3.1", features = ["serde"] } # r thiserror = { workspace = true } log = { workspace = true } geo = { workspace = true } +kdam = { workspace = true } bincode = "1.3.3" env_logger = { workspace = true } serde = { workspace = true, features = ["derive"] } diff --git a/rust/routee-compass-powertrain/src/routee/energy_model_service.rs b/rust/routee-compass-powertrain/src/routee/energy_model_service.rs index 8d5586db..44736e79 100644 --- a/rust/routee-compass-powertrain/src/routee/energy_model_service.rs +++ b/rust/routee-compass-powertrain/src/routee/energy_model_service.rs @@ -1,5 +1,6 @@ use super::energy_traversal_model::EnergyTraversalModel; use super::vehicle::VehicleType; +use kdam::Bar; use routee_compass_core::model::traversal::traversal_model::TraversalModel; use routee_compass_core::model::traversal::traversal_model_error::TraversalModelError; use routee_compass_core::model::traversal::traversal_model_service::TraversalModelService; @@ -40,8 +41,7 @@ impl EnergyModelService { read_utils::read_raw_file( gtp, read_decoders::default, - Some("link grades"), - None, + Some(Bar::builder().desc("link grades")), None, ) .map_err(|e| { diff --git a/rust/routee-compass/src/app/compass/config/access_model/turn_delay_access_model_builder.rs b/rust/routee-compass/src/app/compass/config/access_model/turn_delay_access_model_builder.rs index 95f36628..8f9c636b 100644 --- a/rust/routee-compass/src/app/compass/config/access_model/turn_delay_access_model_builder.rs +++ b/rust/routee-compass/src/app/compass/config/access_model/turn_delay_access_model_builder.rs @@ -1,4 +1,5 @@ use crate::app::compass::config::config_json_extension::ConfigJsonExtensions; +use kdam::Bar; use routee_compass_core::{ model::access::{ access_model_builder::AccessModelBuilder, @@ -32,8 +33,7 @@ impl AccessModelBuilder for TurnDelayAccessModelBuilder { let edge_headings = read_utils::from_csv::( &file_path.as_path(), true, - Some("edge headings"), - None, + Some(Bar::builder().desc("edge headings")), None, ) .map_err(|e| { diff --git a/rust/routee-compass/src/app/compass/config/frontier_model/road_class/road_class_builder.rs b/rust/routee-compass/src/app/compass/config/frontier_model/road_class/road_class_builder.rs index 15e9286f..df4e3d63 100644 --- a/rust/routee-compass/src/app/compass/config/frontier_model/road_class/road_class_builder.rs +++ b/rust/routee-compass/src/app/compass/config/frontier_model/road_class/road_class_builder.rs @@ -3,6 +3,7 @@ use crate::app::compass::config::{ compass_configuration_field::CompassConfigurationField, config_json_extension::ConfigJsonExtensions, }; +use kdam::Bar; use routee_compass_core::{ model::frontier::{ frontier_model_builder::FrontierModelBuilder, frontier_model_error::FrontierModelError, @@ -35,8 +36,7 @@ impl FrontierModelBuilder for RoadClassBuilder { let road_class_lookup: Box<[u8]> = read_utils::read_raw_file( &road_class_file, read_decoders::u8, - Some("road class"), - None, + Some(Bar::builder().desc("road class")), None, ) .map_err(|e| { diff --git a/rust/routee-compass/src/app/compass/config/frontier_model/turn_restrictions/turn_restriction_builder.rs b/rust/routee-compass/src/app/compass/config/frontier_model/turn_restrictions/turn_restriction_builder.rs index ff6456f8..f302cf03 100644 --- a/rust/routee-compass/src/app/compass/config/frontier_model/turn_restrictions/turn_restriction_builder.rs +++ b/rust/routee-compass/src/app/compass/config/frontier_model/turn_restrictions/turn_restriction_builder.rs @@ -2,6 +2,7 @@ use crate::app::compass::config::{ compass_configuration_field::CompassConfigurationField, config_json_extension::ConfigJsonExtensions, }; +use kdam::Bar; use routee_compass_core::{ model::frontier::{ frontier_model_builder::FrontierModelBuilder, frontier_model_error::FrontierModelError, @@ -36,8 +37,7 @@ impl FrontierModelBuilder for TurnRestrictionBuilder { let restricted_edges: HashSet = read_utils::from_csv( &turn_restriction_file, true, - Some("turn restrictions"), - None, + Some(Bar::builder().desc("turn restrictions")), None, ) .map_err(|e| { diff --git a/rust/routee-compass/src/app/compass/config/frontier_model/vehicle_restrictions/vehicle_restriction_builder.rs b/rust/routee-compass/src/app/compass/config/frontier_model/vehicle_restrictions/vehicle_restriction_builder.rs index 555c0ed3..f8b581ff 100644 --- a/rust/routee-compass/src/app/compass/config/frontier_model/vehicle_restrictions/vehicle_restriction_builder.rs +++ b/rust/routee-compass/src/app/compass/config/frontier_model/vehicle_restrictions/vehicle_restriction_builder.rs @@ -2,6 +2,7 @@ use crate::app::compass::config::{ compass_configuration_field::CompassConfigurationField, config_json_extension::ConfigJsonExtensions, }; +use kdam::Bar; use routee_compass_core::{ model::{ frontier::{ @@ -56,8 +57,7 @@ pub fn vehicle_restriction_lookup_from_file( let rows: Vec = read_utils::from_csv( &vehicle_restriction_input_file, true, - Some("vehicle restrictions"), - None, + Some(Bar::builder().desc("vehicle restrictions")), None, ) .map_err(|e| { diff --git a/rust/routee-compass/src/app/geom/geom_app.rs b/rust/routee-compass/src/app/geom/geom_app.rs index 478b7ded..a3c70f16 100644 --- a/rust/routee-compass/src/app/geom/geom_app.rs +++ b/rust/routee-compass/src/app/geom/geom_app.rs @@ -1,5 +1,6 @@ use crate::app::compass::compass_app_error::CompassAppError; use geo::LineString; +use kdam::Bar; use routee_compass_core::util::fs::read_utils; use routee_compass_core::util::geo::geo_io_utils::parse_wkt_linestring; use std::io::ErrorKind; @@ -25,14 +26,18 @@ impl TryFrom<&GeomAppConfig> for GeomApp { Ok(result) }; - let geoms = - read_utils::read_raw_file(&conf.edge_file, op, Some("link geometries"), None, None) - .map_err(|e| { - CompassAppError::BuildFailure(format!( - "failure reading edge file {}: {}", - conf.edge_file, e - )) - })?; + let geoms = read_utils::read_raw_file( + &conf.edge_file, + op, + Some(Bar::builder().desc("link geometries")), + None, + ) + .map_err(|e| { + CompassAppError::BuildFailure(format!( + "failure reading edge file {}: {}", + conf.edge_file, e + )) + })?; eprintln!(); let app = GeomApp { geoms }; Ok(app) @@ -56,15 +61,18 @@ impl GeomApp { result }; - let result: Box<[LineString]> = - read_utils::read_raw_file(&file, op, Some("link geometries"), None, None).map_err( - |e| { - CompassAppError::BuildFailure(format!( - "failure reading linestring file {}: {}", - file, e - )) - }, - )?; + let result: Box<[LineString]> = read_utils::read_raw_file( + &file, + op, + Some(Bar::builder().desc("link geometries")), + None, + ) + .map_err(|e| { + CompassAppError::BuildFailure(format!( + "failure reading linestring file {}: {}", + file, e + )) + })?; eprintln!(); Ok(result) } diff --git a/rust/routee-compass/src/plugin/output/default/uuid/plugin.rs b/rust/routee-compass/src/plugin/output/default/uuid/plugin.rs index 47b41645..d89e9698 100644 --- a/rust/routee-compass/src/plugin/output/default/uuid/plugin.rs +++ b/rust/routee-compass/src/plugin/output/default/uuid/plugin.rs @@ -3,6 +3,7 @@ use crate::app::compass::compass_app_error::CompassAppError; use crate::app::search::search_app_result::SearchAppResult; use crate::plugin::output::default::uuid::output_json_extensions::UUIDJsonField; use crate::plugin::output::{OutputPlugin, OutputPluginError}; +use kdam::Bar; use routee_compass_core::algorithm::search::search_instance::SearchInstance; use routee_compass_core::util::fs::read_utils::read_raw_file; use std::path::Path; @@ -15,14 +16,19 @@ pub struct UUIDOutputPlugin { impl UUIDOutputPlugin { pub fn from_file>(filename: &P) -> Result { - let uuids = read_raw_file(filename, |_idx, row| Ok(row), Some("uuids"), None, None) - .map_err(|e| { - OutputPluginError::BuildFailed(format!( - "failure reading UUID file {}: {}", - filename.as_ref().to_str().unwrap_or_default(), - e - )) - })?; + let uuids = read_raw_file( + filename, + |_idx, row| Ok(row), + Some(Bar::builder().desc("uuids")), + None, + ) + .map_err(|e| { + OutputPluginError::BuildFailed(format!( + "failure reading UUID file {}: {}", + filename.as_ref().to_str().unwrap_or_default(), + e + )) + })?; eprintln!(); let o_key = UUIDJsonField::OriginVertexUUID.to_string();