Skip to content

Commit ca988aa

Browse files
authored
editoast: add occurrences utilities functions (#15741)
Add `iter_occurrences_v2` and `get_created_occurrences_exceptions_v2` functions that use the new exceptions It used in endpoints, like conflicts, requirements and others Signed-off-by: Egor <egor@berezify.fr>
1 parent 85ffd09 commit ca988aa

File tree

6 files changed

+323
-132
lines changed

6 files changed

+323
-132
lines changed

editoast/openapi.yaml

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

editoast/schemas/src/train_schedule_exception.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,122 @@ pub struct TrainScheduleExceptionChangeGroups {
5555
#[schema(nullable = false)]
5656
pub path_and_schedule: Option<PathAndScheduleChangeGroup>,
5757
}
58+
59+
#[cfg(any(test, feature = "testing"))]
60+
impl TrainScheduleExceptionChangeGroups {
61+
pub fn fake_created() -> Self {
62+
use std::str::FromStr;
63+
64+
use chrono::DateTime;
65+
use chrono::Utc;
66+
67+
use crate::infra::TrackOffset;
68+
use crate::primitives::Identifier;
69+
use crate::primitives::NonBlankString;
70+
use crate::train_schedule::Comfort;
71+
use crate::train_schedule::Distribution;
72+
use crate::train_schedule::MarginValue;
73+
use crate::train_schedule::Margins;
74+
use crate::train_schedule::OperationalPointPartReference;
75+
use crate::train_schedule::OperationalPointReference;
76+
use crate::train_schedule::PathItem;
77+
use crate::train_schedule::PathItemLocation;
78+
use crate::train_schedule::ScheduleItem;
79+
use crate::train_schedule::TrainScheduleOptions;
80+
81+
Self {
82+
train_name: Some(TrainNameChangeGroup {
83+
value: "created_exception_train_name".into(),
84+
}),
85+
constraint_distribution: Some(ConstraintDistributionChangeGroup {
86+
value: Distribution::Mareco,
87+
}),
88+
initial_speed: Some(InitialSpeedChangeGroup { value: 10.0 }),
89+
labels: Some(LabelsChangeGroup {
90+
value: vec!["Label 1".to_string(), "Label 3".to_string()],
91+
}),
92+
options: Some(OptionsChangeGroup {
93+
value: TrainScheduleOptions::default(),
94+
}),
95+
path_and_schedule: Some(PathAndScheduleChangeGroup {
96+
power_restrictions: vec![],
97+
schedule: vec![
98+
ScheduleItem {
99+
at: NonBlankString("aa".to_string()),
100+
..Default::default()
101+
},
102+
ScheduleItem {
103+
at: NonBlankString("bb".to_string()),
104+
..Default::default()
105+
},
106+
ScheduleItem {
107+
at: NonBlankString("cc".to_string()),
108+
..Default::default()
109+
},
110+
ScheduleItem {
111+
at: NonBlankString("dd".to_string()),
112+
..Default::default()
113+
},
114+
],
115+
path: vec![
116+
PathItem {
117+
id: "aa".into(),
118+
location: PathItemLocation::TrackOffset(TrackOffset {
119+
offset: 300,
120+
track: Identifier("TC0".to_string()),
121+
}),
122+
},
123+
PathItem {
124+
id: "bb".into(),
125+
location: PathItemLocation::OperationalPointPartReference(
126+
OperationalPointPartReference {
127+
operational_point: OperationalPointReference::Id {
128+
operational_point: Identifier("Mid_East_station".to_string()),
129+
},
130+
local_track_name: None,
131+
},
132+
),
133+
},
134+
PathItem {
135+
id: "cc".into(),
136+
location: PathItemLocation::TrackOffset(TrackOffset {
137+
offset: 300,
138+
track: Identifier("TC1".to_string()),
139+
}),
140+
},
141+
PathItem {
142+
id: "dd".into(),
143+
location: PathItemLocation::TrackOffset(TrackOffset {
144+
offset: 300,
145+
track: Identifier("TC2".to_string()),
146+
}),
147+
},
148+
],
149+
margins: Margins {
150+
boundaries: vec![],
151+
values: vec![MarginValue::Percentage(5.0)],
152+
},
153+
}),
154+
rolling_stock: Some(RollingStockChangeGroup {
155+
rolling_stock_name: "simulation_rolling_stock".into(),
156+
comfort: Comfort::AirConditioning,
157+
}),
158+
rolling_stock_category: Some(RollingStockCategoryChangeGroup { value: None }),
159+
speed_limit_tag: Some(SpeedLimitTagChangeGroup {
160+
value: Some(NonBlankString("GB".into())),
161+
}),
162+
start_time: Some(StartTimeChangeGroup {
163+
value: DateTime::<Utc>::from_str("2025-05-15T15:10:00+02:00").unwrap(),
164+
}),
165+
}
166+
}
167+
168+
pub fn fake_modified() -> Self {
169+
let mut created = Self::fake_created();
170+
created.start_time = None;
171+
created.train_name = Some(TrainNameChangeGroup {
172+
value: "modified_exception_train_name".to_string(),
173+
});
174+
created
175+
}
176+
}

editoast/src/models/fixtures.rs

Lines changed: 1 addition & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::str::FromStr;
2-
3-
use chrono::DateTime;
41
use chrono::Duration as ChronoDuration;
52
use chrono::Utc;
63
use database::DbConnection;
@@ -25,35 +22,13 @@ use schemas::fixtures::simple_created_exception_with_change_groups;
2522
use schemas::fixtures::simple_modified_exception_with_change_groups;
2623
use schemas::infra::InfraObject;
2724
use schemas::infra::RailJson;
28-
use schemas::infra::TrackOffset;
29-
use schemas::paced_train::ConstraintDistributionChangeGroup;
3025
use schemas::paced_train::ExceptionType;
31-
use schemas::paced_train::InitialSpeedChangeGroup;
32-
use schemas::paced_train::LabelsChangeGroup;
33-
use schemas::paced_train::OptionsChangeGroup;
3426
use schemas::paced_train::Paced;
3527
use schemas::paced_train::PacedTrainException;
36-
use schemas::paced_train::PathAndScheduleChangeGroup;
37-
use schemas::paced_train::RollingStockCategoryChangeGroup;
38-
use schemas::paced_train::RollingStockChangeGroup;
39-
use schemas::paced_train::SpeedLimitTagChangeGroup;
40-
use schemas::paced_train::StartTimeChangeGroup;
4128
use schemas::paced_train::TrainNameChangeGroup;
4229
use schemas::paced_train::TrainSchedule;
43-
use schemas::primitives::Identifier;
44-
use schemas::primitives::NonBlankString;
4530
use schemas::primitives::OSRDObject;
4631
use schemas::rolling_stock::SubCategoryColor;
47-
use schemas::train_schedule::Comfort;
48-
use schemas::train_schedule::Distribution;
49-
use schemas::train_schedule::MarginValue;
50-
use schemas::train_schedule::Margins;
51-
use schemas::train_schedule::OperationalPointPartReference;
52-
use schemas::train_schedule::OperationalPointReference;
53-
use schemas::train_schedule::PathItem;
54-
use schemas::train_schedule::PathItemLocation;
55-
use schemas::train_schedule::ScheduleItem;
56-
use schemas::train_schedule::TrainScheduleOptions;
5732

5833
use crate::infra_cache::operation::create::apply_create_operation;
5934
use crate::models;
@@ -139,91 +114,7 @@ pub fn create_created_exception_with_change_groups(key: &str) -> PacedTrainExcep
139114
key: key.into(),
140115
exception_type: ExceptionType::Created {},
141116
disabled: false,
142-
change_groups: TrainScheduleExceptionChangeGroups {
143-
train_name: Some(TrainNameChangeGroup {
144-
value: "created_exception_train_name".into(),
145-
}),
146-
constraint_distribution: Some(ConstraintDistributionChangeGroup {
147-
value: Distribution::Mareco,
148-
}),
149-
initial_speed: Some(InitialSpeedChangeGroup { value: 10.0 }),
150-
labels: Some(LabelsChangeGroup {
151-
value: vec!["Label 1".to_string(), "Label 3".to_string()],
152-
}),
153-
options: Some(OptionsChangeGroup {
154-
value: TrainScheduleOptions::default(),
155-
}),
156-
path_and_schedule: Some(PathAndScheduleChangeGroup {
157-
power_restrictions: vec![],
158-
schedule: vec![
159-
ScheduleItem {
160-
at: NonBlankString("aa".to_string()),
161-
..Default::default()
162-
},
163-
ScheduleItem {
164-
at: NonBlankString("bb".to_string()),
165-
..Default::default()
166-
},
167-
ScheduleItem {
168-
at: NonBlankString("cc".to_string()),
169-
..Default::default()
170-
},
171-
ScheduleItem {
172-
at: NonBlankString("dd".to_string()),
173-
..Default::default()
174-
},
175-
],
176-
path: vec![
177-
PathItem {
178-
id: "aa".into(),
179-
location: PathItemLocation::TrackOffset(TrackOffset {
180-
offset: 300,
181-
track: Identifier("TC0".to_string()),
182-
}),
183-
},
184-
PathItem {
185-
id: "bb".into(),
186-
location: PathItemLocation::OperationalPointPartReference(
187-
OperationalPointPartReference {
188-
operational_point: OperationalPointReference::Id {
189-
operational_point: Identifier("Mid_East_station".to_string()),
190-
},
191-
local_track_name: None,
192-
},
193-
),
194-
},
195-
PathItem {
196-
id: "cc".into(),
197-
location: PathItemLocation::TrackOffset(TrackOffset {
198-
offset: 300,
199-
track: Identifier("TC1".to_string()),
200-
}),
201-
},
202-
PathItem {
203-
id: "dd".into(),
204-
location: PathItemLocation::TrackOffset(TrackOffset {
205-
offset: 300,
206-
track: Identifier("TC2".to_string()),
207-
}),
208-
},
209-
],
210-
margins: Margins {
211-
boundaries: vec![],
212-
values: vec![MarginValue::Percentage(5.0)],
213-
},
214-
}),
215-
rolling_stock: Some(RollingStockChangeGroup {
216-
rolling_stock_name: "simulation_rolling_stock".into(),
217-
comfort: Comfort::AirConditioning,
218-
}),
219-
rolling_stock_category: Some(RollingStockCategoryChangeGroup { value: None }),
220-
speed_limit_tag: Some(SpeedLimitTagChangeGroup {
221-
value: Some(NonBlankString("GB".into())),
222-
}),
223-
start_time: Some(StartTimeChangeGroup {
224-
value: DateTime::<Utc>::from_str("2025-05-15T15:10:00+02:00").unwrap(),
225-
}),
226-
},
117+
change_groups: TrainScheduleExceptionChangeGroups::fake_created(),
227118
}
228119
}
229120

0 commit comments

Comments
 (0)