Skip to content

Commit

Permalink
editoast: return conflicts list when STDCM request fails
Browse files Browse the repository at this point in the history
Signed-off-by: hamz2a <atrari.hamza@gmail.com>
  • Loading branch information
hamz2a committed Oct 17, 2024
1 parent eda1e60 commit 97bb368
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 80 deletions.
16 changes: 16 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,22 @@ paths:
type: string
enum:
- path_not_found
- type: object
required:
- pathfinding_result
- conflicts
- status
properties:
conflicts:
type: array
items:
$ref: '#/components/schemas/Conflict'
pathfinding_result:
$ref: '#/components/schemas/PathfindingResult'
status:
type: string
enum:
- conflicts
- type: object
required:
- error
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/core/conflict_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ConflictDetectionRequest {
pub work_schedules: Option<WorkSchedulesRequest>,
}

#[derive(Debug, Serialize)]
#[derive(Debug, Clone, Serialize)]
pub struct TrainRequirements {
pub start_time: DateTime<Utc>,
pub spacing_requirements: Vec<SpacingRequirement>,
Expand All @@ -49,7 +49,7 @@ pub struct ConflictDetectionResponse {
pub conflicts: Vec<Conflict>,
}

#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
Expand All @@ -70,7 +70,7 @@ pub struct Conflict {
///
/// The start and end time describe the conflicting time span (not the full
/// requirement's time span).
#[derive(Debug, Clone, Deserialize, Serialize, ToSchema)]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct ConflictRequirement {
pub zone: String,
pub start_time: DateTime<Utc>,
Expand Down
6 changes: 3 additions & 3 deletions editoast/src/core/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub struct SimulationPath {
pub path_item_positions: Vec<u64>,
}

#[derive(Deserialize, Default, Serialize, Clone, Debug, ToSchema)]
#[derive(Deserialize, Default, PartialEq, Serialize, Clone, Debug, ToSchema)]
pub struct ReportTrain {
/// List of positions of a train
/// Both positions (in mm) and times (in ms) must have the same length
Expand All @@ -153,7 +153,7 @@ pub struct ReportTrain {
pub path_item_times: Vec<u64>,
}

#[derive(Deserialize, Default, Serialize, Clone, Debug, ToSchema)]
#[derive(Deserialize, Default, PartialEq, Serialize, Clone, Debug, ToSchema)]
pub struct CompleteReportTrain {
#[serde(flatten)]
pub report_train: ReportTrain,
Expand Down Expand Up @@ -279,7 +279,7 @@ pub struct SimulationRequest {
pub electrical_profile_set_id: Option<i64>,
}

#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
#[derive(Serialize, Deserialize, PartialEq, Clone, Debug, ToSchema)]
#[serde(tag = "status", rename_all = "snake_case")]
// We accepted the difference of memory size taken by variants
// Since there is only on success and others are error cases
Expand Down
8 changes: 7 additions & 1 deletion editoast/src/core/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use serde::Deserialize;
use serde::Serialize;
use utoipa::ToSchema;

use super::conflict_detection::Conflict;
use super::conflict_detection::TrainRequirements;
use super::pathfinding::PathfindingResult;
use super::pathfinding::PathfindingResultSuccess;
use super::pathfinding::TrackRange;
use super::simulation::PhysicsRollingStock;
Expand Down Expand Up @@ -113,7 +115,7 @@ pub struct UndirectedTrackRange {
pub end: u64,
}

#[derive(Serialize, Deserialize, Clone, Debug, ToSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, ToSchema)]
#[serde(tag = "status", rename_all = "snake_case")]
// We accepted the difference of memory size taken by variants
// Since there is only on success and others are error cases
Expand All @@ -125,6 +127,10 @@ pub enum STDCMResponse {
departure_time: DateTime<Utc>,
},
PathNotFound,
Conflicts {
pathfinding_result: PathfindingResult,
conflicts: Vec<Conflict>,
},
PreprocessingSimulationError {
error: SimulationResponse,
},
Expand Down
Loading

0 comments on commit 97bb368

Please sign in to comment.