Skip to content

Commit

Permalink
editoast, front: udpate stdcm_search_environment with the LTVs
Browse files Browse the repository at this point in the history
Co-Authored-By: Younes Khoudli <[email protected]>
  • Loading branch information
Sh099078 and Khoyo committed Nov 7, 2024
1 parent 19f8aa2 commit 0ca14eb
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 6 deletions.
2 changes: 2 additions & 0 deletions editoast/editoast_models/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ diesel::table! {
timetable_id -> Int8,
search_window_begin -> Timestamptz,
search_window_end -> Timestamptz,
temporary_speed_limit_group_id -> Nullable<Int8>,
}
}

Expand Down Expand Up @@ -798,6 +799,7 @@ diesel::joinable!(search_signal -> infra_object_signal (id));
diesel::joinable!(search_study -> study (id));
diesel::joinable!(stdcm_search_environment -> electrical_profile_set (electrical_profile_set_id));
diesel::joinable!(stdcm_search_environment -> infra (infra_id));
diesel::joinable!(stdcm_search_environment -> temporary_speed_limit_group (temporary_speed_limit_group_id));
diesel::joinable!(stdcm_search_environment -> timetable (timetable_id));
diesel::joinable!(stdcm_search_environment -> work_schedule_group (work_schedule_group_id));
diesel::joinable!(study -> project (project_id));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE stdcm_search_environment
DROP COLUMN IF EXISTS temporary_speed_limit_group_id;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE stdcm_search_environment
ADD COLUMN temporary_speed_limit_group_id int8 REFERENCES temporary_speed_limit_group(id);
7 changes: 7 additions & 0 deletions editoast/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9993,6 +9993,9 @@ components:
search_window_end:
type: string
format: date-time
temporary_speed_limit_group_id:
type: integer
format: int64
timetable_id:
type: integer
format: int64
Expand Down Expand Up @@ -10020,6 +10023,10 @@ components:
search_window_end:
type: string
format: date-time
temporary_speed_limit_group_id:
type: integer
format: int64
nullable: true
timetable_id:
type: integer
format: int64
Expand Down
11 changes: 11 additions & 0 deletions editoast/src/models/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::models::Scenario;
use crate::models::Study;
use crate::models::Tags;

use super::temporary_speed_limits::TemporarySpeedLimitGroup;

pub fn project_changeset(name: &str) -> Changeset<Project> {
Project::changeset()
.name(name.to_owned())
Expand Down Expand Up @@ -296,6 +298,15 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule
.expect("Failed to create empty work schedule group")
}

pub async fn create_temporary_speed_limit_group(conn: &mut DbConnection) -> TemporarySpeedLimitGroup {
TemporarySpeedLimitGroup::changeset()
.name("Empty temporary speed limit group".to_string())
.creation_date(Utc::now().naive_utc())
.create(conn)
.await
.expect("Failed to create empty temporary speed limit group")
}

pub async fn create_work_schedules_fixture_set(
conn: &mut DbConnection,
work_schedules: Vec<Changeset<WorkSchedule>>,
Expand Down
16 changes: 12 additions & 4 deletions editoast/src/models/stdcm_search_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub struct StdcmSearchEnvironment {
pub timetable_id: i64,
pub search_window_begin: NaiveDateTime,
pub search_window_end: NaiveDateTime,
#[schema(nullable = false)]
#[serde(skip_serializing_if = "Option::is_none")]
pub temporary_speed_limit_group_id: Option<i64>,
}

impl StdcmSearchEnvironment {
Expand Down Expand Up @@ -70,8 +73,9 @@ pub mod test {
use crate::models::electrical_profiles::ElectricalProfileSet;
use crate::models::fixtures::{
create_electrical_profile_set, create_empty_infra, create_timetable,
create_work_schedule_group,
create_work_schedule_group, create_temporary_speed_limit_group,
};
use crate::models::temporary_speed_limits::TemporarySpeedLimitGroup;
use crate::models::timetable::Timetable;
use crate::models::work_schedules::WorkScheduleGroup;
use crate::models::Infra;
Expand All @@ -80,16 +84,18 @@ pub mod test {

pub async fn stdcm_search_env_fixtures(
conn: &mut DbConnection,
) -> (Infra, Timetable, WorkScheduleGroup, ElectricalProfileSet) {
) -> (Infra, Timetable, WorkScheduleGroup, TemporarySpeedLimitGroup, ElectricalProfileSet) {
let infra = create_empty_infra(conn).await;
let timetable = create_timetable(conn).await;
let work_schedule_group = create_work_schedule_group(conn).await;
let temporary_speed_limit_group = create_temporary_speed_limit_group(conn).await;
let electrical_profile_set = create_electrical_profile_set(conn).await;

(
infra,
timetable,
work_schedule_group,
temporary_speed_limit_group,
electrical_profile_set,
)
}
Expand All @@ -101,13 +107,14 @@ pub mod test {
StdcmSearchEnvironment::count(&mut db_pool.get_ok(), Default::default())
.await
.expect("failed to count STDCM envs");
let (infra, timetable, work_schedule_group, electrical_profile_set) =
let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;

let changeset_1 = StdcmSearchEnvironment::changeset()
.infra_id(infra.id)
.electrical_profile_set_id(Some(electrical_profile_set.id))
.work_schedule_group_id(Some(work_schedule_group.id))
.temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id))
.timetable_id(timetable.id)
.search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into())
.search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into());
Expand Down Expand Up @@ -158,13 +165,14 @@ pub mod test {
StdcmSearchEnvironment::delete_all(&mut db_pool.get_ok())
.await
.expect("failed to delete envs");
let (infra, timetable, work_schedule_group, electrical_profile_set) =
let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut db_pool.get_ok()).await;

let too_old = StdcmSearchEnvironment::changeset()
.infra_id(infra.id)
.electrical_profile_set_id(Some(electrical_profile_set.id))
.work_schedule_group_id(Some(work_schedule_group.id))
.temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id))
.timetable_id(timetable.id)
.search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into())
.search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into());
Expand Down
10 changes: 8 additions & 2 deletions editoast/src/views/stdcm_search_environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct StdcmSearchEnvironmentCreateForm {
infra_id: i64,
electrical_profile_set_id: Option<i64>,
work_schedule_group_id: Option<i64>,
temporary_speed_limit_group_id: Option<i64>,
timetable_id: i64,
search_window_begin: NaiveDateTime, // TODO: move to DateTime<Utc>
search_window_end: NaiveDateTime,
Expand All @@ -56,6 +57,7 @@ impl<'de> Deserialize<'de> for StdcmSearchEnvironmentCreateForm {
infra_id: i64,
electrical_profile_set_id: Option<i64>,
work_schedule_group_id: Option<i64>,
temporary_speed_limit_group_id: Option<i64>,
timetable_id: i64,
search_window_begin: NaiveDateTime,
search_window_end: NaiveDateTime,
Expand All @@ -74,6 +76,7 @@ impl<'de> Deserialize<'de> for StdcmSearchEnvironmentCreateForm {
infra_id: internal.infra_id,
electrical_profile_set_id: internal.electrical_profile_set_id,
work_schedule_group_id: internal.work_schedule_group_id,
temporary_speed_limit_group_id: internal.temporary_speed_limit_group_id,
timetable_id: internal.timetable_id,
search_window_begin: internal.search_window_begin,
search_window_end: internal.search_window_end,
Expand All @@ -87,6 +90,7 @@ impl From<StdcmSearchEnvironmentCreateForm> for Changeset<StdcmSearchEnvironment
.infra_id(form.infra_id)
.electrical_profile_set_id(form.electrical_profile_set_id)
.work_schedule_group_id(form.work_schedule_group_id)
.temporary_speed_limit_group_id(form.temporary_speed_limit_group_id)
.timetable_id(form.timetable_id)
.search_window_begin(form.search_window_begin)
.search_window_end(form.search_window_end)
Expand Down Expand Up @@ -172,13 +176,14 @@ pub mod test {
let app = TestAppBuilder::default_app();
let pool = app.db_pool();

let (infra, timetable, work_schedule_group, electrical_profile_set) =
let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut pool.get_ok()).await;

let form = StdcmSearchEnvironmentCreateForm {
infra_id: infra.id,
electrical_profile_set_id: Some(electrical_profile_set.id),
work_schedule_group_id: Some(work_schedule_group.id),
temporary_speed_limit_group_id: Some(temporary_speed_limit_group.id),
timetable_id: timetable.id,
search_window_begin: NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into(),
search_window_end: NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into(),
Expand Down Expand Up @@ -211,7 +216,7 @@ pub mod test {
.await
.expect("failed to delete envs");

let (infra, timetable, work_schedule_group, electrical_profile_set) =
let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) =
stdcm_search_env_fixtures(&mut pool.get_ok()).await;

let begin = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into();
Expand Down Expand Up @@ -244,6 +249,7 @@ pub mod test {
infra_id: infra.id,
electrical_profile_set_id: Some(electrical_profile_set.id),
work_schedule_group_id: Some(work_schedule_group.id),
temporary_speed_limit_group_id: Some(temporary_speed_limit_group.id),
timetable_id: timetable.id,
search_window_begin: begin,
search_window_end: end,
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/hooks/useStdcmEnv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default function useStdcmEnvironment() {
timetableID: data.timetable_id,
electricalProfileSetId: data.electrical_profile_set_id,
workScheduleGroupId: data.work_schedule_group_id,
temporarySpeedLimitGroupId: data.temporary_speed_limit_group_id,
searchDatetimeWindow: {
begin: new Date(data.search_window_begin),
end: new Date(data.search_window_end),
Expand Down
4 changes: 4 additions & 0 deletions front/src/applications/stdcm/utils/formatStdcmConf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ValidStdcmConfig = {
gridMarginBefore?: number;
gridMarginAfter?: number;
workScheduleGroupId?: number;
temporarySpeedLimitGroupId?: number;
electricalProfileSetId?: number;
};

Expand All @@ -51,6 +52,7 @@ export const checkStdcmConf = (
gridMarginAfter,
searchDatetimeWindow,
workScheduleGroupId,
temporarySpeedLimitGroupId,
electricalProfileSetId,
totalLength,
totalMass,
Expand Down Expand Up @@ -195,6 +197,7 @@ export const checkStdcmConf = (
gridMarginBefore,
gridMarginAfter,
workScheduleGroupId,
temporarySpeedLimitGroupId,
electricalProfileSetId,
};
};
Expand All @@ -219,6 +222,7 @@ export const formatStdcmPayload = (
time_gap_after: toMsOrUndefined(validConfig.gridMarginBefore),
time_gap_before: toMsOrUndefined(validConfig.gridMarginAfter),
work_schedule_group_id: validConfig.workScheduleGroupId,
temporary_speed_limit_group_id: validConfig.temporarySpeedLimitGroupId,
electrical_profile_set_id: validConfig.electricalProfileSetId,
},
});
2 changes: 2 additions & 0 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3058,6 +3058,7 @@ export type StdcmSearchEnvironment = {
infra_id: number;
search_window_begin: string;
search_window_end: string;
temporary_speed_limit_group_id?: number;
timetable_id: number;
work_schedule_group_id?: number;
};
Expand All @@ -3066,6 +3067,7 @@ export type StdcmSearchEnvironmentCreateForm = {
infra_id: number;
search_window_begin: string;
search_window_end: string;
temporary_speed_limit_group_id?: number | null;
timetable_id: number;
work_schedule_group_id?: number | null;
};
Expand Down
4 changes: 4 additions & 0 deletions front/src/reducers/osrdconf/stdcmConf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const stdcmConfSlice = createSlice({
| 'timetableID'
| 'electricalProfileSetId'
| 'workScheduleGroupId'
| 'temporarySpeedLimitGroupId'
| 'searchDatetimeWindow'
>
>
Expand All @@ -79,6 +80,9 @@ export const stdcmConfSlice = createSlice({
if (action.payload.workScheduleGroupId) {
state.workScheduleGroupId = action.payload.workScheduleGroupId;
}
if (action.payload.temporarySpeedLimitGroupId) {
state.temporarySpeedLimitGroupId = action.payload.temporarySpeedLimitGroupId;
}
},
updateOriginArrival(
state: Draft<OsrdStdcmConfState>,
Expand Down
1 change: 1 addition & 0 deletions front/src/reducers/osrdconf/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface OsrdConfState extends InfraState {
timetableID?: number;
electricalProfileSetId?: number;
workScheduleGroupId?: number;
temporarySpeedLimitGroupId?: number;
searchDatetimeWindow?: { begin: Date; end: Date };
rollingStockID?: number;
speedLimitByTag?: string;
Expand Down

0 comments on commit 0ca14eb

Please sign in to comment.