Skip to content

Commit

Permalink
editoast: adapt conflicts endpoint to paced trains
Browse files Browse the repository at this point in the history
Signed-off-by: Youness CHRIFI ALAOUI <[email protected]>
  • Loading branch information
younesschrifi committed Feb 13, 2025
1 parent 85e2e06 commit 59e63cb
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 20 deletions.
42 changes: 36 additions & 6 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3826,7 +3826,7 @@ components:
Conflict:
type: object
required:
- train_ids
- train_schedule_ids
- work_schedule_ids
- start_time
- end_time
Expand All @@ -3842,6 +3842,21 @@ components:
type: string
format: date-time
description: Datetime of the end of the conflict
paced_train_occurrence_ids:
type: array
items:
type: object
required:
- paced_train_id
- index
properties:
index:
type: integer
format: int64
paced_train_id:
type: integer
format: int64
description: List of paced train occurence ids involved in the conflict
requirements:
type: array
items:
Expand All @@ -3851,12 +3866,12 @@ components:
type: string
format: date-time
description: Datetime of the start of the conflict
train_ids:
train_schedule_ids:
type: array
items:
type: integer
format: int64
description: List of train ids involved in the conflict
description: List of train schedule ids involved in the conflict
work_schedule_ids:
type: array
items:
Expand All @@ -3873,7 +3888,7 @@ components:
items:
type: object
required:
- train_ids
- train_schedule_ids
- work_schedule_ids
- start_time
- end_time
Expand All @@ -3889,6 +3904,21 @@ components:
type: string
format: date-time
description: Datetime of the end of the conflict
paced_train_occurrence_ids:
type: array
items:
type: object
required:
- paced_train_id
- index
properties:
index:
type: integer
format: int64
paced_train_id:
type: integer
format: int64
description: List of paced train occurence ids involved in the conflict
requirements:
type: array
items:
Expand All @@ -3898,12 +3928,12 @@ components:
type: string
format: date-time
description: Datetime of the start of the conflict
train_ids:
train_schedule_ids:
type: array
items:
type: integer
format: int64
description: List of train ids involved in the conflict
description: List of train schedule ids involved in the conflict
work_schedule_ids:
type: array
items:
Expand Down
14 changes: 12 additions & 2 deletions editoast/src/core/conflict_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,20 @@ pub struct ConflictDetectionResponse {
pub conflicts: Vec<Conflict>,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct PacedTrainOccurrenceId {
paced_train_id: i64,
index: i64,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, ToSchema)]
pub struct Conflict {
/// List of train ids involved in the conflict
pub train_ids: Vec<i64>,
/// List of train schedule ids involved in the conflict
pub train_schedule_ids: Vec<i64>,
/// List of paced train occurence ids involved in the conflict
#[serde(default)]
#[schema(inline)]
pub paced_train_occurrence_ids: Vec<PacedTrainOccurrenceId>,
/// List of work schedule ids involved in the conflict
pub work_schedule_ids: Vec<i64>,
/// Datetime of the start of the conflict
Expand Down
5 changes: 3 additions & 2 deletions editoast/src/views/timetable/stdcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,10 @@ mod tests {
);
}

fn get_conflict_data(train_ids: Vec<i64>, work_schedule_ids: Vec<i64>) -> Conflict {
fn get_conflict_data(train_schedule_ids: Vec<i64>, work_schedule_ids: Vec<i64>) -> Conflict {
Conflict {
train_ids,
train_schedule_ids,
paced_train_occurrence_ids: vec![],
work_schedule_ids,
start_time: DateTime::from_str("2024-01-01T06:00:00Z")
.expect("Failed to parse datetime"),
Expand Down
6 changes: 4 additions & 2 deletions editoast/src/views/timetable/stdcm/failure_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,11 @@ impl SimulationFailureHandler {
let conflicts: Vec<_> = conflict_detection_response
.conflicts
.into_iter()
.filter(|conflict| conflict.train_ids.contains(&virtual_train_id))
.filter(|conflict| conflict.train_schedule_ids.contains(&virtual_train_id))
.map(|mut conflict| {
conflict.train_ids.retain(|id| id != &virtual_train_id);
conflict
.train_schedule_ids
.retain(|id| id != &virtual_train_id);
conflict
})
.collect();
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/stdcm/utils/formatConflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const formatConflicts = (
)?.name ?? null; // Extract only the ID of the operational point after

const formattedConflict = {
trainIds: conflict.train_ids,
trainIds: conflict.train_schedule_ids,
startDate: dayjs(conflict.start_time).format('DD/MM/YYYY'),
endDate: dayjs(conflict.end_time).format('DD/MM/YYYY'),
startTime: dayjs(conflict.start_time).format('HH:mm'),
Expand Down
9 changes: 7 additions & 2 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3577,12 +3577,17 @@ export type Conflict = {
conflict_type: 'Spacing' | 'Routing';
/** Datetime of the end of the conflict */
end_time: string;
/** List of paced train occurence ids involved in the conflict */
paced_train_occurrence_ids?: {
index: number;
paced_train_id: number;
}[];
/** List of requirements causing the conflict */
requirements: ConflictRequirement[];
/** Datetime of the start of the conflict */
start_time: string;
/** List of train ids involved in the conflict */
train_ids: number[];
/** List of train schedule ids involved in the conflict */
train_schedule_ids: number[];
/** List of work schedule ids involved in the conflict */
work_schedule_ids: number[];
};
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/conflict/components/ConflictsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const ConflictsList = ({
<div className={cx('conflicts-container', expanded && 'expanded')}>
{enrichedConflicts.map((conflict, index) => (
<ConflictCard
key={`${conflict.train_ids.join(', ')}-${conflict.conflict_type}-${index}`}
key={`${conflict.train_schedule_ids.join(', ')}-${conflict.conflict_type}-${index}`}
conflict={conflict}
onConflictClick={onConflictClick}
/>
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/conflict/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default function addTrainNamesToConflicts(

return conflicts.map((conflict) => ({
...conflict,
trainNames: conflict.train_ids.map((id) => trainNameMap[id] || ''),
trainNames: conflict.train_schedule_ids.map((id) => trainNameMap[id] || ''),
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ const Timetable = ({
};

const handleConflictClick = (conflict: Conflict) => {
if (conflict.train_ids.length > 0) {
const firstTrainId = conflict.train_ids[0];
if (conflict.train_schedule_ids.length > 0) {
const firstTrainId = conflict.train_schedule_ids[0];
dispatch(updateSelectedTrainId(firstTrainId));
}
};
Expand Down
3 changes: 2 additions & 1 deletion tests/tests/test_stdcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ def test_max_running_time(small_scenario: Scenario, fast_rolling_stock: int):
"conflict_type": "Spacing",
"start_time": "2023-01-01T08:00:00Z",
"end_time": "2024-01-01T16:00:00Z",
"train_ids": [],
"paced_train_occurence_ids": [],
"train_schedule_ids": [],
"work_schedule_ids": [0],
"requirements": [
{
Expand Down

0 comments on commit 59e63cb

Please sign in to comment.