Skip to content

Commit

Permalink
fixup! editoast: improve performance of batch_pathfinding function
Browse files Browse the repository at this point in the history
  • Loading branch information
flomonster committed Jul 12, 2024
1 parent 84821ac commit 976272c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
27 changes: 15 additions & 12 deletions editoast/src/views/v2/path/path_item_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,22 @@ impl PathItemCache {
}

/// Get the operational points associated with an identifier
pub fn get_id(&self, id: &String) -> Option<&OperationalPointModel> {
pub fn get_from_id(&self, id: &str) -> Option<&OperationalPointModel> {
self.ids_to_ops.get(id)
}

/// Get the operational points associated with a trigram
pub fn get_trigram(&self, trigram: &String) -> Option<&Vec<OperationalPointModel>> {
pub fn get_from_trigram(&self, trigram: &str) -> Option<&Vec<OperationalPointModel>> {
self.trigram_to_ops.get(trigram)
}

/// Get the operational points associated with a UIC code
pub fn get_uic(&self, uic: i64) -> Option<&Vec<OperationalPointModel>> {
pub fn get_from_uic(&self, uic: i64) -> Option<&Vec<OperationalPointModel>> {
self.uic_to_ops.get(&uic)
}

/// Check if a track exists
pub fn track_exists(&self, track: &String) -> bool {
pub fn track_exists(&self, track: &str) -> bool {
self.existing_track_ids.contains(track)
}

Expand All @@ -90,13 +90,10 @@ impl PathItemCache {
for (index, &path_item) in path_items.iter().enumerate() {
let track_offsets = match path_item {
PathItemLocation::TrackOffset(track_offset) => {
vec![TrackOffset {
track: track_offset.track.clone(),
offset: track_offset.offset,
}]
vec![track_offset.clone()]
}
PathItemLocation::OperationalPointId { operational_point } => {
match self.get_id(&operational_point.0) {
match self.get_from_id(&operational_point.0) {
Some(op) => op.track_offset(),
None => {
return Err(TrackOffsetExtractionError {
Expand All @@ -110,7 +107,10 @@ impl PathItemCache {
trigram,
secondary_code,
} => {
let ops = self.get_trigram(&trigram.0).cloned().unwrap_or_default();
let ops = self
.get_from_trigram(&trigram.0)
.cloned()
.unwrap_or_default();
let ops = secondary_code_filter(secondary_code, ops);
if ops.is_empty() {
return Err(TrackOffsetExtractionError {
Expand All @@ -124,7 +124,10 @@ impl PathItemCache {
uic,
secondary_code,
} => {
let ops = self.get_uic(*uic as i64).cloned().unwrap_or_default();
let ops = self
.get_from_uic(i64::from(*uic))
.cloned()
.unwrap_or_default();
let ops = secondary_code_filter(secondary_code, ops);
if ops.is_empty() {
return Err(TrackOffsetExtractionError {
Expand Down Expand Up @@ -153,7 +156,7 @@ fn collect_path_item_ids(path_items: &[&PathItemLocation]) -> (Vec<String>, Vec<
trigrams.push(trigram.clone().0);
}
PathItemLocation::OperationalPointUic { uic, .. } => {
ops_uic.push(*uic as i64);
ops_uic.push(i64::from(*uic));
}
PathItemLocation::OperationalPointId {
operational_point, ..
Expand Down
4 changes: 2 additions & 2 deletions editoast/src/views/v2/path/pathfinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ editoast_common::schemas! {
/// and a list of path waypoints
#[derive(Deserialize, Clone, Debug, Hash, ToSchema)]
#[schema(as = PathfindingInputV2)]
pub struct PathfindingInput {
struct PathfindingInput {
/// The loading gauge of the rolling stock
rolling_stock_loading_gauge: LoadingGaugeType,
/// Can the rolling stock run on non-electrified tracks
Expand All @@ -57,7 +57,7 @@ pub struct PathfindingInput {
rolling_stock_supported_signaling_systems: Vec<String>,
/// List of waypoints given to the pathfinding
#[schema(inline)]
pub path_items: Vec<PathItemLocation>,
path_items: Vec<PathItemLocation>,
}

/// Compute a pathfinding
Expand Down

0 comments on commit 976272c

Please sign in to comment.