Skip to content

Commit

Permalink
editoast: magic wand revamp
Browse files Browse the repository at this point in the history
If we want to keep opportunities to parallelize this code,
all the errors related to the same object should be addressed together.
It will become important when some `Operation::Update` will happen and need to
be ordered correctly.
  • Loading branch information
woshilapin committed Jan 3, 2024
1 parent 84d57c2 commit 24faeea
Show file tree
Hide file tree
Showing 10 changed files with 490 additions and 185 deletions.
28 changes: 28 additions & 0 deletions editoast/src/views/infra/auto_fixes/buffer_stop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use super::{new_ref_fix_delete_pair, Fix};
use crate::schema::{
BufferStopCache, InfraError, InfraErrorType, OSRDObject as _, ObjectRef, ObjectType,
};
use log::debug;
use std::collections::HashMap;

pub fn fix_buffer_stop(
buffer_stop: &BufferStopCache,
errors: impl Iterator<Item = InfraError>,
) -> HashMap<ObjectRef, Fix> {
errors
.filter_map(|infra_error| match infra_error.get_sub_type() {
InfraErrorType::OddBufferStopLocation | InfraErrorType::OutOfRange { .. } => {
Some(new_ref_fix_delete_pair(buffer_stop))
}
InfraErrorType::InvalidReference { reference }
if reference.obj_type == ObjectType::TrackSection =>
{
Some(new_ref_fix_delete_pair(buffer_stop))
}
_ => {
debug!("error not (yet) fixable for '{}'", infra_error.get_type());
None
}
})
.collect()
}
19 changes: 19 additions & 0 deletions editoast/src/views/infra/auto_fixes/catenary.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use super::{new_ref_fix_delete_pair, Fix};
use crate::schema::{Catenary, InfraError, InfraErrorType, OSRDObject as _, ObjectRef};
use log::debug;
use std::collections::HashMap;

pub fn fix_catenary(
catenary: &Catenary,
errors: impl Iterator<Item = InfraError>,
) -> HashMap<ObjectRef, Fix> {
errors
.filter_map(|infra_error| match infra_error.get_sub_type() {
InfraErrorType::EmptyObject => Some(new_ref_fix_delete_pair(catenary)),
_ => {
debug!("error not (yet) fixable for '{}'", infra_error.get_type());
None
}
})
.collect()
}
26 changes: 26 additions & 0 deletions editoast/src/views/infra/auto_fixes/detector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use super::{new_ref_fix_delete_pair, Fix};
use crate::schema::{
DetectorCache, InfraError, InfraErrorType, OSRDObject as _, ObjectRef, ObjectType,
};
use log::debug;
use std::collections::HashMap;

pub fn fix_detector(
detector: &DetectorCache,
errors: impl Iterator<Item = InfraError>,
) -> HashMap<ObjectRef, Fix> {
errors
.filter_map(|infra_error| match infra_error.get_sub_type() {
InfraErrorType::OutOfRange { .. } => Some(new_ref_fix_delete_pair(detector)),
InfraErrorType::InvalidReference { reference }
if reference.obj_type == ObjectType::TrackSection =>
{
Some(new_ref_fix_delete_pair(detector))
}
_ => {
debug!("error not (yet) fixable for '{}'", infra_error.get_type());
None
}
})
.collect()
}
Loading

0 comments on commit 24faeea

Please sign in to comment.