From 44c161a42e3c2c69f2407c0a0c9a5c459e98f43f Mon Sep 17 00:00:00 2001 From: Youness CHRIFI ALAOUI Date: Wed, 21 Aug 2024 22:59:56 +0200 Subject: [PATCH 1/5] editoast: harmonize comfort type --- .../editoast_schemas/src/rolling_stock.rs | 1 - .../src/rolling_stock/effort_curves.rs | 20 +++------------- .../src/train_schedule/train_schedule_base.rs | 1 - editoast/openapi.yaml | 15 ++---------- .../src/tests/example_rolling_stock_1.json | 24 +++++++++---------- front/src/common/api/generatedEditoastApi.ts | 7 +++--- 6 files changed, 20 insertions(+), 48 deletions(-) diff --git a/editoast/editoast_schemas/src/rolling_stock.rs b/editoast/editoast_schemas/src/rolling_stock.rs index 6c12160a4f6..3122f7d3057 100644 --- a/editoast/editoast_schemas/src/rolling_stock.rs +++ b/editoast/editoast_schemas/src/rolling_stock.rs @@ -7,7 +7,6 @@ pub use effort_curves::EffortCurve; pub use effort_curves::EffortCurveConditions; pub use effort_curves::EffortCurves; pub use effort_curves::ModeEffortCurves; -pub use effort_curves::RollingStockComfortType; mod rolling_resistance; pub use rolling_resistance::RollingResistance; diff --git a/editoast/editoast_schemas/src/rolling_stock/effort_curves.rs b/editoast/editoast_schemas/src/rolling_stock/effort_curves.rs index f7ae502cd05..1cfa0ab8881 100644 --- a/editoast/editoast_schemas/src/rolling_stock/effort_curves.rs +++ b/editoast/editoast_schemas/src/rolling_stock/effort_curves.rs @@ -3,17 +3,16 @@ use serde::Deserialize; use serde::Deserializer; use serde::Serialize; use std::collections::BTreeMap; -use strum::Display; -use strum::EnumString; use utoipa::ToSchema; +use crate::train_schedule::Comfort; + editoast_common::schemas! { ConditionalEffortCurve, EffortCurve, EffortCurves, EffortCurveConditions, ModeEffortCurves, - RollingStockComfortType, } #[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize, ToSchema, Hash)] @@ -52,26 +51,13 @@ pub struct ConditionalEffortCurve { #[serde(deny_unknown_fields)] pub struct EffortCurveConditions { #[schema(required)] - comfort: Option, + comfort: Option, #[schema(required)] electrical_profile_level: Option, #[schema(required)] power_restriction_code: Option, } -/// Train comfort that will be used for the simulation -#[derive( - Display, Clone, Default, Debug, EnumString, PartialEq, Deserialize, Serialize, ToSchema, Hash, -)] -#[strum(serialize_all = "UPPERCASE")] -#[serde(rename_all = "UPPERCASE")] -pub enum RollingStockComfortType { - #[default] - Standard, - AC, - Heating, -} - #[derive(Clone, Debug, PartialEq, Serialize, ToSchema, Derivative)] #[derivative(Hash)] #[serde(deny_unknown_fields)] diff --git a/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs b/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs index 7f589af7e05..4b9e1646104 100644 --- a/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs +++ b/editoast/editoast_schemas/src/train_schedule/train_schedule_base.rs @@ -38,7 +38,6 @@ pub struct TrainScheduleBase { pub margins: Margins, #[serde(default)] pub initial_speed: f64, - #[schema(inline)] #[serde(default)] pub comfort: Comfort, pub constraint_distribution: Distribution, diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index 2e35ed169dc..2e91b17029d 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -5081,7 +5081,7 @@ components: properties: comfort: allOf: - - $ref: '#/components/schemas/RollingStockComfortType' + - $ref: '#/components/schemas/Comfort' nullable: true electrical_profile_level: type: string @@ -7690,13 +7690,6 @@ components: version: type: integer format: int64 - RollingStockComfortType: - type: string - description: Train comfort that will be used for the simulation - enum: - - STANDARD - - AC - - HEATING RollingStockError: oneOf: - type: string @@ -9657,11 +9650,7 @@ components: - constraint_distribution properties: comfort: - type: string - enum: - - STANDARD - - AIR_CONDITIONING - - HEATING + $ref: '#/components/schemas/Comfort' constraint_distribution: $ref: '#/components/schemas/Distribution' initial_speed: diff --git a/editoast/src/tests/example_rolling_stock_1.json b/editoast/src/tests/example_rolling_stock_1.json index 45aadb942c3..a314861dd2a 100644 --- a/editoast/src/tests/example_rolling_stock_1.json +++ b/editoast/src/tests/example_rolling_stock_1.json @@ -645,7 +645,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": "C1" }, @@ -670,7 +670,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": "C2" }, @@ -695,7 +695,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": null }, @@ -720,7 +720,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": "C1" }, @@ -745,7 +745,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": "C2" }, @@ -770,7 +770,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": null }, @@ -795,7 +795,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": "C1" }, @@ -820,7 +820,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": "C2" }, @@ -845,7 +845,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": null }, @@ -870,7 +870,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": "C1" }, @@ -895,7 +895,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": "C2" }, @@ -920,7 +920,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": null }, diff --git a/front/src/common/api/generatedEditoastApi.ts b/front/src/common/api/generatedEditoastApi.ts index fe3ed19463d..9d014770958 100644 --- a/front/src/common/api/generatedEditoastApi.ts +++ b/front/src/common/api/generatedEditoastApi.ts @@ -2290,9 +2290,9 @@ export type StudyPatchForm = { study_type?: string | null; tags?: Tags | null; }; -export type RollingStockComfortType = 'STANDARD' | 'AC' | 'HEATING'; +export type Comfort = 'STANDARD' | 'AIR_CONDITIONING' | 'HEATING'; export type EffortCurveConditions = { - comfort: RollingStockComfortType | null; + comfort: Comfort | null; electrical_profile_level: string | null; power_restriction_code: string | null; }; @@ -2843,7 +2843,6 @@ export type SimulationResponse = core_error: InternalError; status: 'simulation_failed'; }; -export type Comfort = 'STANDARD' | 'AIR_CONDITIONING' | 'HEATING'; export type StepTimingData = { /** Time at which the train should arrive at the location */ arrival_time: string; @@ -2860,7 +2859,7 @@ export type PathfindingItem = { }; export type Distribution = 'STANDARD' | 'MARECO'; export type TrainScheduleBase = { - comfort?: 'STANDARD' | 'AIR_CONDITIONING' | 'HEATING'; + comfort?: Comfort; constraint_distribution: Distribution; initial_speed?: number; labels?: string[]; From 8647b8d7100bfdd2705fb54bf1226ce47874821d Mon Sep 17 00:00:00 2001 From: Youness CHRIFI ALAOUI Date: Thu, 29 Aug 2024 15:21:30 +0200 Subject: [PATCH 2/5] front: harmonize comfort type --- front/public/locales/en/rollingstock.json | 1 - front/public/locales/fr/rollingstock.json | 1 - .../helpers/__tests__/sampleData.ts | 6 ++-- .../RollingStockCard/RollingStockCard.tsx | 7 ++--- .../RollingStockCardButtons.tsx | 4 +-- .../RollingStockCardDetail.tsx | 8 +++--- .../components/RollingStockCurve.tsx | 28 ++++++------------- .../CurveParamSelectors.tsx | 20 ++++++------- .../RollingStockEditorCurves.tsx | 10 ++----- .../RollingStockInformationPanel.tsx | 4 +-- .../RollingStockEditorCurves.spec.ts | 2 +- front/src/modules/rollingStock/consts.ts | 6 ++-- .../modules/rollingStock/helpers/curves.ts | 4 +-- .../helpers/rollingStockEditor.ts | 4 +-- .../src/modules/rollingStock/helpers/utils.ts | 6 ++-- front/src/modules/rollingStock/types.ts | 8 +++--- .../stories/RollingStockSelector.stories.tsx | 4 +-- front/tests/007-op-rollingstock-tab.spec.ts | 2 +- .../rollingStock/dual-mode_rolling_stock.json | 4 +-- 19 files changed, 52 insertions(+), 77 deletions(-) diff --git a/front/public/locales/en/rollingstock.json b/front/public/locales/en/rollingstock.json index 2f41b19e169..3f61b094c39 100644 --- a/front/public/locales/en/rollingstock.json +++ b/front/public/locales/en/rollingstock.json @@ -10,7 +10,6 @@ "comfortLevels": "Comfort levels", "comfortAcceleration": "Comfort acceleration", "comfortTypes": { - "AC": "Air conditioning", "AIR_CONDITIONING": "Air conditioning", "HEATING": "Heating", "STANDARD": "Standard" diff --git a/front/public/locales/fr/rollingstock.json b/front/public/locales/fr/rollingstock.json index 944faeebfd5..449dc6707d5 100644 --- a/front/public/locales/fr/rollingstock.json +++ b/front/public/locales/fr/rollingstock.json @@ -10,7 +10,6 @@ "comfortLevels": "Niveaux de confort", "comfortAcceleration": "Accélération «\u202Fconfort\u202F»", "comfortTypes": { - "AC": "Climatisation", "AIR_CONDITIONING": "Climatisation", "HEATING": "Chauffage", "STANDARD": "Standard" diff --git a/front/src/modules/powerRestriction/helpers/__tests__/sampleData.ts b/front/src/modules/powerRestriction/helpers/__tests__/sampleData.ts index d28fc80a862..c9284e6a526 100644 --- a/front/src/modules/powerRestriction/helpers/__tests__/sampleData.ts +++ b/front/src/modules/powerRestriction/helpers/__tests__/sampleData.ts @@ -511,7 +511,7 @@ export const effortCurves: EffortCurves['modes'] = { }, { cond: { - comfort: 'AC', + comfort: 'AIR_CONDITIONING', electrical_profile_level: 'level1', power_restriction_code: 'code2', }, @@ -531,7 +531,7 @@ export const effortCurves: EffortCurves['modes'] = { curves: [ { cond: { - comfort: 'AC', + comfort: 'AIR_CONDITIONING', electrical_profile_level: 'level2', power_restriction_code: 'code3', }, @@ -542,7 +542,7 @@ export const effortCurves: EffortCurves['modes'] = { }, { cond: { - comfort: 'AC', + comfort: 'AIR_CONDITIONING', electrical_profile_level: 'level2', power_restriction_code: 'code4', }, diff --git a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCard.tsx b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCard.tsx index c54930b70b0..4e98c134664 100644 --- a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCard.tsx +++ b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCard.tsx @@ -8,10 +8,7 @@ import { IoIosSpeedometer } from 'react-icons/io'; import { MdLocalGasStation } from 'react-icons/md'; import { LazyLoadComponent } from 'react-lazy-load-image-component'; -import type { - RollingStockComfortType, - LightRollingStockWithLiveries, -} from 'common/api/osrdEditoastApi'; +import type { Comfort, LightRollingStockWithLiveries } from 'common/api/osrdEditoastApi'; import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img'; import { RollingStockInfo } from 'modules/rollingStock/components/RollingStockSelector/RollingStockHelpers'; @@ -35,7 +32,7 @@ const RollingStockCard = ({ ref2scroll = undefined, setOpenedRollingStockCardId, }: RollingStockCardProps) => { - const [curvesComfortList, setCurvesComfortList] = useState([]); + const [curvesComfortList, setCurvesComfortList] = useState([]); const ref2scrollWhenOpened: React.RefObject = useRef(null); diff --git a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardButtons.tsx b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardButtons.tsx index 367a9d841a4..2585f83a6ec 100644 --- a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardButtons.tsx +++ b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardButtons.tsx @@ -13,7 +13,7 @@ import { useAppDispatch } from 'store'; interface RollingStockCardButtonsProps { id: number; - curvesComfortList: string[]; + curvesComfortList: Comfort[]; setOpenedRollingStockCardId: (openCardId: number | undefined) => void; } @@ -54,7 +54,7 @@ const RollingStockCardButtons = ({ ), }); } - if (curvesComfortList.includes('AC')) { + if (curvesComfortList.includes('AIR_CONDITIONING')) { options.push({ value: 'AIR_CONDITIONING', label: ( diff --git a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardDetail.tsx b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardDetail.tsx index cb4bf2fec5d..8704058986c 100644 --- a/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardDetail.tsx +++ b/front/src/modules/rollingStock/components/RollingStockCard/RollingStockCardDetail.tsx @@ -5,7 +5,7 @@ import { isEmpty, uniq } from 'lodash'; import { useTranslation } from 'react-i18next'; import { osrdEditoastApi } from 'common/api/osrdEditoastApi'; -import type { RollingStockComfortType, RollingStockWithLiveries } from 'common/api/osrdEditoastApi'; +import type { Comfort, RollingStockWithLiveries } from 'common/api/osrdEditoastApi'; import { Loader } from 'common/Loaders/Loader'; import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img'; import RollingStockCurves from 'modules/rollingStock/components/RollingStockCurve'; @@ -20,14 +20,14 @@ type RollingStockCardDetailProps = { id: number; hideCurves?: boolean; form?: string; - curvesComfortList: RollingStockComfortType[]; - setCurvesComfortList: (curvesComfortList: RollingStockComfortType[]) => void; + curvesComfortList: Comfort[]; + setCurvesComfortList: (curvesComfortList: Comfort[]) => void; }; export const getCurvesComforts = (curvesData: EffortCurveForms) => { const modes = Object.keys(curvesData); return modes.length - ? modes.reduce((list, mode) => { + ? modes.reduce((list, mode) => { const modeComfortList = curvesData[mode].curves.reduce( (acc, curve) => { const { comfort } = curve.cond; diff --git a/front/src/modules/rollingStock/components/RollingStockCurve.tsx b/front/src/modules/rollingStock/components/RollingStockCurve.tsx index fdc6fb421c3..0a8606bc813 100644 --- a/front/src/modules/rollingStock/components/RollingStockCurve.tsx +++ b/front/src/modules/rollingStock/components/RollingStockCurve.tsx @@ -5,7 +5,7 @@ import type { PointTooltipProps } from '@nivo/line'; import cx from 'classnames'; import { useTranslation } from 'react-i18next'; -import type { RollingStock, RollingStockComfortType } from 'common/api/osrdEditoastApi'; +import type { RollingStock, Comfort } from 'common/api/osrdEditoastApi'; import { COLORS } from 'modules/rollingStock/components/RollingStockSelector/consts/consts'; import { comfort2pictogram } from 'modules/rollingStock/components/RollingStockSelector/RollingStockHelpers'; import { STANDARD_COMFORT_LEVEL, THERMAL_TRACTION_IDENTIFIER } from 'modules/rollingStock/consts'; @@ -44,21 +44,15 @@ const parseData = ( }; function LegendComfortSwitches(props: { - curvesComfortList: RollingStockComfortType[]; + curvesComfortList: Comfort[]; comfortsStates: { [key: string]: boolean }; onComfortsStatesChange: (comfort: string) => void; }) { const { curvesComfortList, comfortsStates, onComfortsStatesChange } = props; - // TODO: remove this condition when getRollingStock endpoint returns comfort - // with type Comfort instead of RollingStockComfortType */ - const curvesComfortListV2 = curvesComfortList.map((comfort) => - comfort === 'AC' ? 'AIR_CONDITIONING' : comfort - ); - - return curvesComfortListV2.length > 1 ? ( + return curvesComfortList.length > 1 ? ( - {curvesComfortListV2.map((comfort) => ( + {curvesComfortList.map((comfort) => ( ) : ( - {comfort2pictogram(curvesComfortListV2[0])} + {comfort2pictogram(curvesComfortList[0])} ); } @@ -108,11 +102,9 @@ function Legend(props: { {isOnEditionMode && showPowerRestriction && curve.power_restriction} {isOnEditionMode && !showPowerRestriction && curve.electrical_profile_level} {!isOnEditionMode && !showPowerRestriction && curve.mode} - {/* TODO: remove this condition when getRollingStock endpoint returns comfort - with type Comfort instead of RollingStockComfortType */} {curve.comfort !== STANDARD_COMFORT_LEVEL && !isOnEditionMode && - comfort2pictogram(curve.comfort === 'AC' ? 'AIR_CONDITIONING' : curve.comfort)} + comfort2pictogram(curve.comfort)} ))} @@ -181,7 +173,7 @@ export default function RollingStockCurve({ selectedElectricalParam, }: { data: RollingStock['effort_curves']['modes']; - curvesComfortList: RollingStockComfortType[]; + curvesComfortList: Comfort[]; isOnEditionMode?: boolean; showPowerRestriction?: boolean; hoveredElectricalParam?: string | null; @@ -244,11 +236,7 @@ export default function RollingStockCurve({ {transformedCurve.comfort !== STANDARD_COMFORT_LEVEL && ( - {/* TODO: remove this condition when getRollingStock endpoint returns comfort - with type Comfort instead of RollingStockComfortType */} - {comfort2pictogram( - transformedCurve.comfort === 'AC' ? 'AIR_CONDITIONING' : transformedCurve.comfort - )} + {comfort2pictogram(transformedCurve.comfort)} )} diff --git a/front/src/modules/rollingStock/components/RollingStockEditor/CurveParamSelectors.tsx b/front/src/modules/rollingStock/components/RollingStockEditor/CurveParamSelectors.tsx index 40dff416b07..f51aa5f6264 100644 --- a/front/src/modules/rollingStock/components/RollingStockEditor/CurveParamSelectors.tsx +++ b/front/src/modules/rollingStock/components/RollingStockEditor/CurveParamSelectors.tsx @@ -6,11 +6,7 @@ import { compact, isEmpty } from 'lodash'; import { useTranslation } from 'react-i18next'; import { osrdEditoastApi } from 'common/api/osrdEditoastApi'; -import type { - ConditionalEffortCurve, - RollingStock, - RollingStockComfortType, -} from 'common/api/osrdEditoastApi'; +import type { ConditionalEffortCurve, RollingStock, Comfort } from 'common/api/osrdEditoastApi'; import { useModal } from 'common/BootstrapSNCF/ModalSNCF'; import Selector from 'common/Selector/Selector'; import PowerRestrictionGridModal from 'modules/rollingStock/components/RollingStockEditor/PowerRestrictionGridModal'; @@ -51,14 +47,14 @@ const addNewCurveToMode = ( type RollingStockEditorCurvesProps = { selectedParams: { - comfortLevel: RollingStockComfortType; + comfortLevel: Comfort; electricalProfile: string | null; powerRestriction: string | null; tractionMode: string | null; }; selectedParamsSetter: ( key: 'comfortLevel' | 'tractionMode' | 'electricalProfile' | 'powerRestriction', - value: RollingStockComfortType | string | null + value: Comfort | string | null ) => void; effortCurves: EffortCurveForms | null; @@ -126,7 +122,7 @@ const CurveParamSelectors = ({ })); }, [availableModes, rollingstockParams.tractionModes]); - const updateComfortLevelsList = (value: RollingStockComfortType) => { + const updateComfortLevelsList = (value: Comfort) => { if (!effortCurves) return; // add the new comfort to all the modes const updatedCurves = Object.keys(effortCurves).reduce((acc, mode) => { @@ -200,7 +196,7 @@ const CurveParamSelectors = ({ const removeAnotherRsParam = ( title: 'comfort' | 'electrical_profile_level' | 'power_restriction_code', - value: string | RollingStockComfortType + value: string | Comfort ) => { if (!effortCurves) return; const condKey = title as keyof ConditionalEffortCurve['cond']; @@ -229,7 +225,7 @@ const CurveParamSelectors = ({ const confirmRsParamRemoval = ( title: 'comfort' | 'tractionMode' | 'electrical_profile_level' | 'power_restriction_code', - value: string | null | RollingStockComfortType + value: string | null | Comfort ) => { if (value === null) return; openModal( @@ -260,10 +256,10 @@ const CurveParamSelectors = ({ displayedItems={translateItemsList(t, rollingstockParams.comfortLevels, 'comfortTypes')} selectedItem={selectedComfortLvl} permanentItems={[STANDARD_COMFORT_LEVEL]} - onItemSelected={(item: RollingStockComfortType) => { + onItemSelected={(item: Comfort) => { selectedParamsSetter('comfortLevel', item); }} - onItemRemoved={(item: RollingStockComfortType) => { + onItemRemoved={(item: Comfort) => { confirmRsParamRemoval('comfort', item); }} selectNewItemButtonProps={{ diff --git a/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockEditorCurves.tsx b/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockEditorCurves.tsx index a6fcd51e525..62b909ee6eb 100644 --- a/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockEditorCurves.tsx +++ b/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockEditorCurves.tsx @@ -3,11 +3,7 @@ import type { Dispatch, PropsWithChildren, SetStateAction } from 'react'; import { isEmpty } from 'lodash'; -import type { - EffortCurves, - RollingStock, - RollingStockComfortType, -} from 'common/api/osrdEditoastApi'; +import type { EffortCurves, RollingStock, Comfort } from 'common/api/osrdEditoastApi'; import { getCurvesComforts } from 'modules/rollingStock/components/RollingStockCard/RollingStockCardDetail'; import RollingStockCurve from 'modules/rollingStock/components/RollingStockCurve'; import CurveParamSelectors from 'modules/rollingStock/components/RollingStockEditor/CurveParamSelectors'; @@ -60,14 +56,14 @@ const RollingStockEditorCurves = ({ children, }: PropsWithChildren) => { const [selectedParams, setSelectedParams] = useState<{ - comfortLevel: RollingStockComfortType; + comfortLevel: Comfort; electricalProfile: string | null; powerRestriction: string | null; }>(EMPTY_SELECTED_PARAMS); const updateSelectedParams = ( key: 'comfortLevel' | 'tractionMode' | 'electricalProfile' | 'powerRestriction', - value: RollingStockComfortType | string | null + value: Comfort | string | null ) => { if (key === 'tractionMode') { setSelectedTractionMode(value); diff --git a/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockInformationPanel.tsx b/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockInformationPanel.tsx index ac772bcf06a..5bef7d1442b 100644 --- a/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockInformationPanel.tsx +++ b/front/src/modules/rollingStock/components/RollingStockEditor/RollingStockInformationPanel.tsx @@ -2,7 +2,7 @@ import React, { useState } from 'react'; import cx from 'classnames'; -import type { RollingStockComfortType, RollingStockWithLiveries } from 'common/api/osrdEditoastApi'; +import type { Comfort, RollingStockWithLiveries } from 'common/api/osrdEditoastApi'; import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img'; import RollingStockCardDetail, { getCurvesComforts, @@ -21,7 +21,7 @@ export default function RollingStockInformationPanel({ isEditing, rollingStock, }: RollingStockInformationPanelProps) { - const [curvesComfortList, setCurvesComfortList] = useState([]); + const [curvesComfortList, setCurvesComfortList] = useState([]); return (
diff --git a/front/src/modules/rollingStock/components/RollingStockEditor/__tests__/RollingStockEditorCurves.spec.ts b/front/src/modules/rollingStock/components/RollingStockEditor/__tests__/RollingStockEditorCurves.spec.ts index 70376c2adb2..b6dba86273f 100644 --- a/front/src/modules/rollingStock/components/RollingStockEditor/__tests__/RollingStockEditorCurves.spec.ts +++ b/front/src/modules/rollingStock/components/RollingStockEditor/__tests__/RollingStockEditorCurves.spec.ts @@ -5,7 +5,7 @@ import { sortSelectedModeCurves, } from 'modules/rollingStock/helpers/utils'; -const emptyEffortCurves = createEmptyCurves('1500V', ['STANDARD', 'AC', 'HEATING']); +const emptyEffortCurves = createEmptyCurves('1500V', ['STANDARD', 'AIR_CONDITIONING', 'HEATING']); const newCurveWithAllCond = createEmptyCurve('STANDARD', 'A1', 'C1US'); const newCurveWithOnlyPR = createEmptyCurve('STANDARD', null, 'C1US'); const newCurveWithOnlyEP = createEmptyCurve('STANDARD', 'B'); diff --git a/front/src/modules/rollingStock/consts.ts b/front/src/modules/rollingStock/consts.ts index 6919c3b28cf..b7cc6081840 100644 --- a/front/src/modules/rollingStock/consts.ts +++ b/front/src/modules/rollingStock/consts.ts @@ -1,4 +1,4 @@ -import type { Comfort, RollingStockComfortType } from 'common/api/osrdEditoastApi'; +import type { Comfort } from 'common/api/osrdEditoastApi'; import { isElectric } from 'modules/rollingStock/helpers/electric'; import type { ElectricalProfileByMode, @@ -8,7 +8,7 @@ import type { } from 'modules/rollingStock/types'; export const THERMAL_TRACTION_IDENTIFIER = 'thermal'; -export const STANDARD_COMFORT_LEVEL: RollingStockComfortType = 'STANDARD'; +export const STANDARD_COMFORT_LEVEL: Comfort = 'STANDARD'; export const DEFAULT_SIGNALING_SYSTEMS = ['BAL', 'BAPR']; @@ -310,7 +310,7 @@ export const ComfortLevels: Record = { HEATING: 'HEATING', }; -export const COMFORTS = Object.keys(ComfortLevels) as RollingStockComfortType[]; +export const COMFORTS = Object.keys(ComfortLevels) as Comfort[]; export const EP_BY_MODE: ElectricalProfileByMode = { '1500V': [ diff --git a/front/src/modules/rollingStock/helpers/curves.ts b/front/src/modules/rollingStock/helpers/curves.ts index c41729cce6e..82d568ca882 100644 --- a/front/src/modules/rollingStock/helpers/curves.ts +++ b/front/src/modules/rollingStock/helpers/curves.ts @@ -1,10 +1,10 @@ -import type { RollingStockComfortType } from 'common/api/osrdEditoastApi'; +import type { Comfort } from 'common/api/osrdEditoastApi'; import { geti18nKeyForNull } from 'utils/strings'; // eslint-disable-next-line import/prefer-default-export export const getCurveName = ( name: string, - comfort: RollingStockComfortType, + comfort: Comfort, electricalProfileLevel: string | null, powerRestrictionCode: string | null, isOnEditionMode?: boolean diff --git a/front/src/modules/rollingStock/helpers/rollingStockEditor.ts b/front/src/modules/rollingStock/helpers/rollingStockEditor.ts index aad8782fbef..b01d0fcb1b7 100644 --- a/front/src/modules/rollingStock/helpers/rollingStockEditor.ts +++ b/front/src/modules/rollingStock/helpers/rollingStockEditor.ts @@ -1,12 +1,12 @@ /* eslint-disable import/prefer-default-export */ -import type { RollingStockComfortType } from 'common/api/osrdEditoastApi'; +import type { Comfort } from 'common/api/osrdEditoastApi'; import type { EffortCurveForms, ElectricalParamsLists } from 'modules/rollingStock/types'; import type { ValueOf } from 'utils/types'; /** Get the list of electrical profiles and power restrictions for an ModeEffortCurves */ export const getElectricalProfilesAndPowerRestrictions = ( effortCurvesByMode: ValueOf, - selectedComfortLvl: RollingStockComfortType, + selectedComfortLvl: Comfort, selectedElectricalProfile: string | null ) => effortCurvesByMode.curves.reduce( diff --git a/front/src/modules/rollingStock/helpers/utils.ts b/front/src/modules/rollingStock/helpers/utils.ts index e5c20dfb197..322b9c166e7 100644 --- a/front/src/modules/rollingStock/helpers/utils.ts +++ b/front/src/modules/rollingStock/helpers/utils.ts @@ -4,7 +4,7 @@ import { floor, groupBy, has, isNil, isNull, omit, pick } from 'lodash'; import type { EffortCurve, - RollingStockComfortType, + Comfort, RollingStock, RollingStockForm, } from 'common/api/osrdEditoastApi'; @@ -296,7 +296,7 @@ const formatCurveCondition = ( }; export const createEmptyCurve = ( - comfort: RollingStockComfortType, + comfort: Comfort, electricalProfile: string | null = null, powerRestriction: string | null = null ) => ({ @@ -309,7 +309,7 @@ export const createEmptyCurve = ( }); /** given a tractionMode and a list of comfort, return empty EffortCurves */ -export const createEmptyCurves = (tractionMode: string, comforts: RollingStockComfortType[]) => ({ +export const createEmptyCurves = (tractionMode: string, comforts: Comfort[]) => ({ curves: comforts.map((comfort) => createEmptyCurve(comfort)), default_curve: { speeds: [0], max_efforts: [0] }, is_electric: tractionMode !== THERMAL_TRACTION_IDENTIFIER, diff --git a/front/src/modules/rollingStock/types.ts b/front/src/modules/rollingStock/types.ts index 5f6d80d002c..45c00182361 100644 --- a/front/src/modules/rollingStock/types.ts +++ b/front/src/modules/rollingStock/types.ts @@ -1,7 +1,7 @@ import type { EffortCurveConditions, LoadingGaugeType, - RollingStockComfortType, + Comfort, RollingStock, } from 'common/api/osrdEditoastApi'; @@ -148,7 +148,7 @@ export type EffortCurveForms = Record< >; export type RollingStockSelectorParams = { - comfortLevels: RollingStockComfortType[]; + comfortLevels: Comfort[]; electricalProfiles: (string | null)[]; powerRestrictions: (string | null)[]; tractionModes: string[]; @@ -162,7 +162,7 @@ export type ElectricalParamsLists = Omit< export type TransformedCurves = { [index: string]: { mode: string; - comfort: RollingStockComfortType; + comfort: Comfort; speeds: number[]; max_efforts: number[]; electricalProfile: string | null; @@ -172,7 +172,7 @@ export type TransformedCurves = { export type ParsedCurve = { color: string; - comfort: RollingStockComfortType; + comfort: Comfort; data: { x: number; y: number; diff --git a/front/src/stories/RollingStockSelector.stories.tsx b/front/src/stories/RollingStockSelector.stories.tsx index fa6a2718570..32e5ffa0897 100644 --- a/front/src/stories/RollingStockSelector.stories.tsx +++ b/front/src/stories/RollingStockSelector.stories.tsx @@ -4,7 +4,7 @@ import type { Meta } from '@storybook/react'; import exampleRollingStockImage1 from 'assets/defaultRSImages/example_rolling_stock_image_1.gif'; import exampleRollingStockImage2 from 'assets/defaultRSImages/example_rolling_stock_image_2.gif'; -import type { RollingStockComfortType } from 'common/api/osrdEditoastApi'; +import type { Comfort } from 'common/api/osrdEditoastApi'; import { RollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector'; import ROLLING_STOCK_SAMPLE_DATA from 'modules/rollingStock/components/RollingStockSelector/sampleData'; @@ -22,7 +22,7 @@ const image = ( const defaultArgs = { rollingStockSelected: ROLLING_STOCK_SAMPLE_DATA, - rollingStockComfort: 'STANDARD' as RollingStockComfortType, + rollingStockComfort: 'STANDARD' as Comfort, image, }; diff --git a/front/tests/007-op-rollingstock-tab.spec.ts b/front/tests/007-op-rollingstock-tab.spec.ts index caf3e9c5444..63826766a17 100644 --- a/front/tests/007-op-rollingstock-tab.spec.ts +++ b/front/tests/007-op-rollingstock-tab.spec.ts @@ -77,7 +77,7 @@ test.describe('Verifying that all elements in the rolling stock tab are loaded c await rollingstockCard.click(); await expect(rollingstockCard).not.toHaveClass(/inactive/); - // Select the comfort AC + // Select the comfort AIR_CONDITIONING const comfortACRadioText = await rollingStockSelector.comfortACButton.innerText(); await rollingStockSelector.comfortACButton.click(); diff --git a/front/tests/assets/rollingStock/dual-mode_rolling_stock.json b/front/tests/assets/rollingStock/dual-mode_rolling_stock.json index 74d56ae2f6a..da9ea5e39fd 100644 --- a/front/tests/assets/rollingStock/dual-mode_rolling_stock.json +++ b/front/tests/assets/rollingStock/dual-mode_rolling_stock.json @@ -271,7 +271,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": null }, @@ -352,7 +352,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": null }, From 607a9a974b911a60d1cab8a0348c68fae0fb517e Mon Sep 17 00:00:00 2001 From: Youness CHRIFI ALAOUI Date: Fri, 30 Aug 2024 10:22:16 +0200 Subject: [PATCH 3/5] tests: harmonize comfort type --- .../osrd_schemas/rolling_stock.py | 2 +- .../electric_rolling_stock.json | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/python/osrd_schemas/osrd_schemas/rolling_stock.py b/python/osrd_schemas/osrd_schemas/rolling_stock.py index 5392327fa37..ab1f730fc64 100644 --- a/python/osrd_schemas/osrd_schemas/rolling_stock.py +++ b/python/osrd_schemas/osrd_schemas/rolling_stock.py @@ -22,7 +22,7 @@ class ComfortType(str, Enum): """ STANDARD = "STANDARD" - AC = "AC" + AIR_CONDITIONING = "AIR_CONDITIONING" HEATING = "HEATING" diff --git a/tests/data/rolling_stocks/electric_rolling_stock.json b/tests/data/rolling_stocks/electric_rolling_stock.json index c200aa710c8..697bf644261 100644 --- a/tests/data/rolling_stocks/electric_rolling_stock.json +++ b/tests/data/rolling_stocks/electric_rolling_stock.json @@ -643,7 +643,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": "C1" }, @@ -668,7 +668,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": "C2" }, @@ -693,7 +693,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "25000V", "power_restriction_code": null }, @@ -718,7 +718,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": "C1" }, @@ -743,7 +743,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": "C2" }, @@ -768,7 +768,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "22500V", "power_restriction_code": null }, @@ -793,7 +793,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": "C1" }, @@ -818,7 +818,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": "C2" }, @@ -843,7 +843,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": "20000V", "power_restriction_code": null }, @@ -868,7 +868,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": "C1" }, @@ -893,7 +893,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": "C2" }, @@ -918,7 +918,7 @@ }, { "cond": { - "comfort": "AC", + "comfort": "AIR_CONDITIONING", "electrical_profile_level": null, "power_restriction_code": null }, From 73f64a97a5b75f1b721ec0bb307d7bf6c2f3b3e4 Mon Sep 17 00:00:00 2001 From: Youness CHRIFI ALAOUI Date: Fri, 30 Aug 2024 10:23:56 +0200 Subject: [PATCH 4/5] core: harmonize comfort type --- .../{RJSComfortType.java => Comfort.java} | 4 ++-- .../schema/rollingstock/RJSEffortCurves.java | 2 +- .../schedule/RJSStandaloneTrainSchedule.java | 8 ++++---- .../parser/RJSRollingStockParser.java | 11 +--------- .../RJSStandaloneTrainScheduleParser.java | 4 +--- .../java/fr/sncf/osrd/train/RollingStock.java | 7 +------ .../osrd/train/StandaloneTrainSchedule.java | 5 +++-- .../standalone_sim/SimulationRequest.kt | 2 +- .../osrd/api/api_v2/stdcm/STDCMEndpointV2.kt | 5 +++-- .../osrd/api/api_v2/stdcm/STDCMRequestV2.kt | 2 +- .../fr/sncf/osrd/api/stdcm/STDCMEndpoint.kt | 4 ++-- .../fr/sncf/osrd/api/stdcm/STDCMRequest.kt | 4 ++-- .../standalone_sim/StandaloneSimulation.kt | 3 ++- .../stdcm/graph/EnvelopeSimContextBuilder.kt | 2 +- .../stdcm/graph/PostProcessingSimulation.kt | 4 +--- .../fr/sncf/osrd/stdcm/graph/STDCMGraph.kt | 2 +- .../sncf/osrd/stdcm/graph/STDCMPathfinding.kt | 5 +++-- .../osrd/stdcm/graph/STDCMPostProcessing.kt | 2 +- .../sncf/osrd/stdcm/graph/STDCMSimulations.kt | 2 +- .../osrd/api/StandaloneSimulationTest.java | 18 ++++++++--------- .../standalone_sim/ConflictDetectionTest.java | 6 +++--- .../ScheduleMetadataExtractorTests.java | 13 +++--------- .../fr/sncf/osrd/train/TestRollingStock.java | 20 +++++++++---------- .../java/fr/sncf/osrd/train/TestTrains.java | 2 +- .../StandaloneSimulationTest.kt | 8 ++++---- .../fr/sncf/osrd/stdcm/BacktrackingTests.kt | 8 ++++---- .../osrd/stdcm/DepartureTimeShiftTests.kt | 4 ++-- .../osrd/stdcm/EngineeringAllowanceTests.kt | 14 ++++++------- .../fr/sncf/osrd/stdcm/FullSTDCMTests.kt | 4 ++-- .../kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt | 6 +++--- .../osrd/stdcm/STDCMPathfindingBuilder.kt | 2 +- 31 files changed, 81 insertions(+), 102 deletions(-) rename core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/{RJSComfortType.java => Comfort.java} (64%) diff --git a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSComfortType.java b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/Comfort.java similarity index 64% rename from core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSComfortType.java rename to core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/Comfort.java index 3d8dcc5de43..40745ac1131 100644 --- a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSComfortType.java +++ b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/Comfort.java @@ -1,7 +1,7 @@ package fr.sncf.osrd.railjson.schema.rollingstock; -public enum RJSComfortType { - AC, +public enum Comfort { + AIR_CONDITIONING, HEATING, STANDARD } diff --git a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSEffortCurves.java b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSEffortCurves.java index 7e64385460a..ce1c35e1d34 100644 --- a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSEffortCurves.java +++ b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/rollingstock/RJSEffortCurves.java @@ -36,7 +36,7 @@ public static final class RJSConditionalEffortCurve { } public static final class RJSEffortCurveConditions { - public RJSComfortType comfort = null; + public Comfort comfort = null; @Json(name = "electrical_profile_level") public String electricalProfileLevel = null; diff --git a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/schedule/RJSStandaloneTrainSchedule.java b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/schedule/RJSStandaloneTrainSchedule.java index 91c92bb779b..16c23f2fe7c 100644 --- a/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/schedule/RJSStandaloneTrainSchedule.java +++ b/core/osrd-railjson/src/main/java/fr/sncf/osrd/railjson/schema/schedule/RJSStandaloneTrainSchedule.java @@ -2,7 +2,7 @@ import com.squareup.moshi.Json; import fr.sncf.osrd.railjson.schema.common.Identified; -import fr.sncf.osrd.railjson.schema.rollingstock.RJSComfortType; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; public class RJSStandaloneTrainSchedule implements Identified { /** The identifier of this train */ @@ -35,7 +35,7 @@ public class RJSStandaloneTrainSchedule implements Identified { public String tag; /** The type of comfort the train using */ - public RJSComfortType comfort; + public Comfort comfort; /** Ranges on the path where power restrictions are to be applied */ @Json(name = "power_restriction_ranges") @@ -52,7 +52,7 @@ public RJSStandaloneTrainSchedule( RJSAllowance[] allowances, RJSTrainStop[] stops, String tag, - RJSComfortType comfort, + Comfort comfort, RJSTrainScheduleOptions options, RJSPowerRestrictionRange[] powerRestrictionRanges) { this.id = id; @@ -73,7 +73,7 @@ public RJSStandaloneTrainSchedule( RJSAllowance[] allowances, RJSTrainStop[] stops, String tag) { - this(id, rollingStock, initialSpeed, allowances, stops, tag, RJSComfortType.STANDARD, null, null); + this(id, rollingStock, initialSpeed, allowances, stops, tag, Comfort.STANDARD, null, null); } public RJSStandaloneTrainSchedule( diff --git a/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSRollingStockParser.java b/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSRollingStockParser.java index 6e17c945494..0062118cb42 100644 --- a/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSRollingStockParser.java +++ b/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSRollingStockParser.java @@ -1,6 +1,5 @@ package fr.sncf.osrd.railjson.parser; -import fr.sncf.osrd.railjson.schema.rollingstock.RJSComfortType; import fr.sncf.osrd.railjson.schema.rollingstock.RJSEffortCurves; import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance; import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingStock; @@ -130,15 +129,7 @@ private static RollingStock.EffortCurveConditions parseEffortCurveConditions( RJSEffortCurves.RJSEffortCurveConditions rjsCond, String fieldKey) { if (rjsCond == null) throw OSRDError.newMissingRollingStockFieldError(fieldKey); return new RollingStock.EffortCurveConditions( - parseComfort(rjsCond.comfort), rjsCond.electricalProfileLevel, rjsCond.powerRestrictionCode); - } - - /** Parse rjsComfort into a RollingStock comfort */ - public static RollingStock.Comfort parseComfort(RJSComfortType rjsComfort) { - if (rjsComfort == null) return null; - if (rjsComfort == RJSComfortType.AC) return RollingStock.Comfort.AIR_CONDITIONING; - if (rjsComfort == RJSComfortType.HEATING) return RollingStock.Comfort.HEATING; - return RollingStock.Comfort.STANDARD; + rjsCond.comfort, rjsCond.electricalProfileLevel, rjsCond.powerRestrictionCode); } /** Parse RJSModeEffortCurve into a ModeEffortCurve */ diff --git a/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSStandaloneTrainScheduleParser.java b/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSStandaloneTrainScheduleParser.java index 073cde0d9bc..88410a5a636 100644 --- a/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSStandaloneTrainScheduleParser.java +++ b/core/src/main/java/fr/sncf/osrd/railjson/parser/RJSStandaloneTrainScheduleParser.java @@ -1,7 +1,5 @@ package fr.sncf.osrd.railjson.parser; -import static fr.sncf.osrd.railjson.parser.RJSRollingStockParser.parseComfort; - import com.google.common.collect.ImmutableRangeMap; import com.google.common.collect.Range; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -49,7 +47,7 @@ public static StandaloneTrainSchedule parse( throw new OSRDError(ErrorType.InvalidScheduleInvalidInitialSpeed); // Parse comfort - var comfort = parseComfort(rjsTrainSchedule.comfort); + var comfort = rjsTrainSchedule.comfort; // Parse options var options = new TrainScheduleOptions(rjsTrainSchedule.options); diff --git a/core/src/main/java/fr/sncf/osrd/train/RollingStock.java b/core/src/main/java/fr/sncf/osrd/train/RollingStock.java index b1fa7fa3959..e586f213ae1 100644 --- a/core/src/main/java/fr/sncf/osrd/train/RollingStock.java +++ b/core/src/main/java/fr/sncf/osrd/train/RollingStock.java @@ -11,6 +11,7 @@ import fr.sncf.osrd.envelope_sim.electrification.Electrified; import fr.sncf.osrd.envelope_sim.electrification.Neutral; import fr.sncf.osrd.envelope_sim.electrification.NonElectrified; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType; import java.util.Map; import java.util.Set; @@ -154,12 +155,6 @@ public boolean match(EffortCurveConditions other) { public record InfraConditions(String mode, String electricalProfile, String powerRestriction) {} - public enum Comfort { - STANDARD, - HEATING, - AIR_CONDITIONING, - } - protected record CurveAndCondition(TractiveEffortPoint[] curve, InfraConditions cond) {} public record CurvesAndConditions( diff --git a/core/src/main/java/fr/sncf/osrd/train/StandaloneTrainSchedule.java b/core/src/main/java/fr/sncf/osrd/train/StandaloneTrainSchedule.java index 9bbea9473be..34a3180d090 100644 --- a/core/src/main/java/fr/sncf/osrd/train/StandaloneTrainSchedule.java +++ b/core/src/main/java/fr/sncf/osrd/train/StandaloneTrainSchedule.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableRangeMap; import com.google.common.collect.RangeMap; import fr.sncf.osrd.envelope_sim.allowances.Allowance; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.utils.jacoco.ExcludeFromGeneratedCodeCoverage; import java.util.List; import java.util.Objects; @@ -22,7 +23,7 @@ public class StandaloneTrainSchedule { public final String tag; - public final RollingStock.Comfort comfort; + public final Comfort comfort; public final RangeMap powerRestrictionMap; @@ -36,7 +37,7 @@ public StandaloneTrainSchedule( List stops, List allowances, String tag, - RollingStock.Comfort comfort, + Comfort comfort, ImmutableRangeMap powerRestrictionMap, TrainScheduleOptions options) { this.rollingStock = rollingStock; diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/standalone_sim/SimulationRequest.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/standalone_sim/SimulationRequest.kt index 9359200e732..4d6f566585f 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/standalone_sim/SimulationRequest.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/standalone_sim/SimulationRequest.kt @@ -6,12 +6,12 @@ import fr.sncf.osrd.api.api_v2.RangeValues import fr.sncf.osrd.api.api_v2.TrackRange import fr.sncf.osrd.conflicts.TravelledPath import fr.sncf.osrd.envelope_sim.PhysicsRollingStock.GammaType +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.railjson.schema.rollingstock.RJSEffortCurves.RJSModeEffortCurve import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution import fr.sncf.osrd.sim_infra.api.Path import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.utils.json.UnitAdapterFactory import fr.sncf.osrd.utils.units.Duration import fr.sncf.osrd.utils.units.Length diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt index 2fada787b5e..f68fad1434a 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMEndpointV2.kt @@ -16,6 +16,7 @@ import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.envelope_sim_infra.MRSP import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingEdgeLocationId +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl @@ -140,7 +141,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { path: STDCMResult, rollingStock: RollingStock, speedLimitTag: String?, - comfort: RollingStock.Comfort, + comfort: Comfort, ): SimulationSuccess { val reportTrain = runScheduleMetadataExtractor( @@ -180,7 +181,7 @@ class STDCMEndpointV2(private val infraManager: InfraManager) : Take { infra: FullInfra, path: STDCMResult, rollingStock: RollingStock, - comfort: RollingStock.Comfort + comfort: Comfort ): RangeValues { val envelopeSimPath = EnvelopeTrainPath.from(infra.rawInfra, path.trainPath, null) val electrificationMap = diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt index 59fe1a2baf2..68adc02e15e 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/api_v2/stdcm/STDCMRequestV2.kt @@ -10,9 +10,9 @@ import fr.sncf.osrd.api.api_v2.conflicts.TrainRequirementsRequest import fr.sncf.osrd.api.api_v2.standalone_sim.MarginValue import fr.sncf.osrd.api.api_v2.standalone_sim.MarginValueAdapter import fr.sncf.osrd.api.api_v2.standalone_sim.PhysicsRollingStockModel +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.utils.json.UnitAdapterFactory import fr.sncf.osrd.utils.units.Duration import fr.sncf.osrd.utils.units.TimeDelta diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMEndpoint.kt b/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMEndpoint.kt index 31d2489702c..86bf5625136 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMEndpoint.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMEndpoint.kt @@ -11,6 +11,7 @@ import fr.sncf.osrd.envelope_sim_infra.MRSP import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.railjson.parser.RJSRollingStockParser import fr.sncf.osrd.railjson.parser.RJSStandaloneTrainScheduleParser +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.reporting.warnings.DiagnosticRecorderImpl @@ -22,7 +23,6 @@ import fr.sncf.osrd.stdcm.STDCMStep import fr.sncf.osrd.stdcm.graph.findPath import fr.sncf.osrd.stdcm.preprocessing.implementation.makeBlockAvailability import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.train.StandaloneTrainSchedule import fr.sncf.osrd.train.TrainStop import org.takes.Request @@ -52,7 +52,7 @@ class STDCMEndpoint(private val infraManager: InfraManager) : Take { // TODO : change with get infra when the front is ready val infra = infraManager.getInfra(request.infra, request.expectedVersion, recorder) val rollingStock = RJSRollingStockParser.parse(request.rollingStock) - val comfort = RJSRollingStockParser.parseComfort(request.comfort) + val comfort = request.comfort val steps = parseSteps(infra, request.steps) val tag = request.speedLimitComposition var standardAllowance: AllowanceValue? = null diff --git a/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMRequest.kt b/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMRequest.kt index 6642579a798..8ad4b552257 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMRequest.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/api/stdcm/STDCMRequest.kt @@ -7,7 +7,7 @@ import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory import edu.umd.cs.findbugs.annotations.SuppressFBWarnings import fr.sncf.osrd.api.pathfinding.request.PathfindingWaypoint import fr.sncf.osrd.railjson.schema.common.ID -import fr.sncf.osrd.railjson.schema.rollingstock.RJSComfortType +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingResistance import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingStock import fr.sncf.osrd.railjson.schema.schedule.RJSAllowance @@ -41,7 +41,7 @@ constructor( maximumRunTime: Double = 12.0 * 3600.0 ) { /** Train comfort */ - var comfort: RJSComfortType? = null + var comfort: Comfort? = null /** Time step used in simulations (defaults to 2) */ @Json(name = "time_step") var timeStep = 2.0 diff --git a/core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt b/core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt index cedc714b504..32c976cc7af 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulation.kt @@ -25,6 +25,7 @@ import fr.sncf.osrd.envelope_sim.pipelines.MaxSpeedEnvelope import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.envelope_sim_infra.MRSP import fr.sncf.osrd.external_generated_inputs.ElectricalProfileMapping +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution import fr.sncf.osrd.sim_infra.api.* import fr.sncf.osrd.sim_infra.impl.ChunkPath @@ -51,7 +52,7 @@ fun runStandaloneSimulation( routes: StaticIdxList, electricalProfileMap: ElectricalProfileMapping?, rollingStock: RollingStock, - comfort: RollingStock.Comfort, + comfort: Comfort, constraintDistribution: RJSAllowanceDistribution, speedLimitTag: String?, powerRestrictions: DistanceRangeMap, diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/EnvelopeSimContextBuilder.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/EnvelopeSimContextBuilder.kt index 78b9902b9fc..f25545da669 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/EnvelopeSimContextBuilder.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/EnvelopeSimContextBuilder.kt @@ -2,8 +2,8 @@ package fr.sncf.osrd.stdcm.graph import fr.sncf.osrd.envelope_sim.EnvelopeSimContext import fr.sncf.osrd.envelope_sim.EnvelopeSimPath +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort /** Computes the rolling stock effort curves that will be used and creates a context */ fun build( diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/PostProcessingSimulation.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/PostProcessingSimulation.kt index 809943e75de..74685750a03 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/PostProcessingSimulation.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/PostProcessingSimulation.kt @@ -9,13 +9,13 @@ import fr.sncf.osrd.envelope_sim.allowances.LinearAllowance import fr.sncf.osrd.envelope_sim.allowances.MarecoAllowance import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceRange import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.standalone_sim.EnvelopeStopWrapper import fr.sncf.osrd.stdcm.infra_exploration.withEnvelope import fr.sncf.osrd.stdcm.preprocessing.interfaces.BlockAvailabilityInterface import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.train.TrainStop import fr.sncf.osrd.utils.units.Distance import fr.sncf.osrd.utils.units.Length @@ -24,8 +24,6 @@ import fr.sncf.osrd.utils.units.meters import java.util.* import kotlin.math.max -object STDCMStandardAllowance - private data class FixedTimePoint( val time: Double, val offset: Offset, diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt index 30f12686a3e..73b4630dc77 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMGraph.kt @@ -6,12 +6,12 @@ import fr.sncf.osrd.envelope.Envelope import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue.FixedTime import fr.sncf.osrd.graph.Graph +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.stdcm.STDCMAStarHeuristic import fr.sncf.osrd.stdcm.STDCMHeuristicBuilder import fr.sncf.osrd.stdcm.STDCMStep import fr.sncf.osrd.stdcm.preprocessing.interfaces.BlockAvailabilityInterface import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.utils.units.meters import java.lang.Double.isFinite import java.lang.Double.isNaN diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt index 94c65cc7993..64e8776b2ce 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPathfinding.kt @@ -8,6 +8,7 @@ import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingConstraint import fr.sncf.osrd.graph.PathfindingEdgeLocationId +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.ErrorType import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.sim_infra.api.Block @@ -45,7 +46,7 @@ val logger: Logger = LoggerFactory.getLogger("STDCM") fun findPath( fullInfra: FullInfra, rollingStock: RollingStock, - comfort: RollingStock.Comfort?, + comfort: Comfort?, startTime: Double, steps: List, blockAvailability: BlockAvailabilityInterface, @@ -76,7 +77,7 @@ fun findPath( class STDCMPathfinding( private val fullInfra: FullInfra, private val rollingStock: RollingStock, - private val comfort: RollingStock.Comfort?, + private val comfort: Comfort?, private val startTime: Double, private val steps: List, private val blockAvailability: BlockAvailabilityInterface, diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPostProcessing.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPostProcessing.kt index d1959bf68d2..c48b91e06c2 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPostProcessing.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMPostProcessing.kt @@ -15,11 +15,11 @@ import fr.sncf.osrd.graph.Pathfinding.EdgeLocation import fr.sncf.osrd.graph.Pathfinding.EdgeRange import fr.sncf.osrd.graph.PathfindingEdgeLocationId import fr.sncf.osrd.graph.PathfindingEdgeRangeId +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.* import fr.sncf.osrd.stdcm.STDCMResult import fr.sncf.osrd.stdcm.preprocessing.interfaces.BlockAvailabilityInterface import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.train.TrainStop import fr.sncf.osrd.utils.units.meters import io.opentelemetry.api.trace.SpanKind diff --git a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMSimulations.kt b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMSimulations.kt index 53d9226dc33..c33f83e5f17 100644 --- a/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMSimulations.kt +++ b/core/src/main/kotlin/fr/sncf/osrd/stdcm/graph/STDCMSimulations.kt @@ -16,6 +16,7 @@ import fr.sncf.osrd.envelope_sim.pipelines.MaxEffortEnvelope import fr.sncf.osrd.envelope_sim.pipelines.MaxSpeedEnvelope import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.envelope_sim_infra.MRSP +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.reporting.exceptions.OSRDError import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.sim_infra.api.BlockId @@ -24,7 +25,6 @@ import fr.sncf.osrd.sim_infra.api.RawSignalingInfra import fr.sncf.osrd.stdcm.BacktrackingSelfTypeHolder import fr.sncf.osrd.stdcm.infra_exploration.InfraExplorer import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.utils.SelfTypeHolder import fr.sncf.osrd.utils.units.Distance import fr.sncf.osrd.utils.units.Offset diff --git a/core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java b/core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java index 33dab7f3808..776d321a0ea 100644 --- a/core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java +++ b/core/src/test/java/fr/sncf/osrd/api/StandaloneSimulationTest.java @@ -19,7 +19,7 @@ import fr.sncf.osrd.railjson.schema.common.graph.EdgeDirection; import fr.sncf.osrd.railjson.schema.infra.RJSRoutePath; import fr.sncf.osrd.railjson.schema.infra.trackranges.RJSDirectionalTrackRange; -import fr.sncf.osrd.railjson.schema.rollingstock.RJSComfortType; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.railjson.schema.rollingstock.RJSRollingStock; import fr.sncf.osrd.railjson.schema.schedule.RJSAllowance; import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution; @@ -377,7 +377,7 @@ public void withElectricalProfilesAndComfort() throws IOException { trainSchedules.add(trainSchedule); } var trainSchedule = new RJSStandaloneTrainSchedule( - "Test", "electric_rolling_stock1", 0, null, stops, null, RJSComfortType.AC, null, null); + "Test", "electric_rolling_stock1", 0, null, stops, null, Comfort.AIR_CONDITIONING, null, null); trainSchedules.add(trainSchedule); // build the simulation request @@ -397,7 +397,7 @@ public void withElectricalProfilesAndComfort() throws IOException { assertTrue( result1Standard < result1Ac, - "AC should be slower than standard, but was " + result1Standard + " vs " + result1Ac); + "AIR_CONDITIONING should be slower than standard, but was " + result1Standard + " vs " + result1Ac); for (int i = 1; i < 5; i++) { var resultA = Iterables.getLast(simResult.baseSimulations.get(i - 1).headPositions).time; @@ -433,7 +433,7 @@ public void testWithPowerRestrictions() throws IOException { null, stops, null, - RJSComfortType.STANDARD, + Comfort.STANDARD, null, powerRestrictionRanges)); trains.add(new RJSStandaloneTrainSchedule("without", "electric_rolling_stock", 0, null, stops, null)); @@ -470,7 +470,7 @@ public void testWithPowerRestrictionsAndElectricalProfiles() throws IOException null, stops, null, - RJSComfortType.STANDARD, + Comfort.STANDARD, null, powerRestrictionRanges)); trains.add(new RJSStandaloneTrainSchedule("without", "electric_rolling_stock", 0, null, stops, null)); @@ -503,7 +503,7 @@ public void testElectrificationRangesInResult() throws IOException { new RJSAllowance[0], new RJSTrainStop[] {RJSTrainStop.lastStop(0.1)}, null, - RJSComfortType.AC, + Comfort.AIR_CONDITIONING, null, null); @@ -552,7 +552,7 @@ public void testElectrificationRangesInResultWithIgnored() throws IOException { new RJSAllowance[0], new RJSTrainStop[] {RJSTrainStop.lastStop(0.1)}, null, - RJSComfortType.AC, + Comfort.AIR_CONDITIONING, null, null); @@ -563,7 +563,7 @@ public void testElectrificationRangesInResultWithIgnored() throws IOException { new RJSAllowance[0], new RJSTrainStop[] {RJSTrainStop.lastStop(0.1)}, null, - RJSComfortType.STANDARD, + Comfort.STANDARD, new RJSTrainScheduleOptions(true), null); @@ -609,7 +609,7 @@ public void testElectrificationRangesInResultWithPowerRestriction() throws IOExc new RJSAllowance[0], new RJSTrainStop[] {RJSTrainStop.lastStop(0.1)}, null, - RJSComfortType.AC, + Comfort.AIR_CONDITIONING, null, new RJSPowerRestrictionRange[] {new RJSPowerRestrictionRange(90.0, 5000.0, "C2")}); diff --git a/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java b/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java index 032172a354c..0c682ce5571 100644 --- a/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java +++ b/core/src/test/java/fr/sncf/osrd/standalone_sim/ConflictDetectionTest.java @@ -21,10 +21,10 @@ import fr.sncf.osrd.envelope_sim.SimpleContextBuilder; import fr.sncf.osrd.envelope_sim.pipelines.MaxEffortEnvelope; import fr.sncf.osrd.envelope_sim.pipelines.MaxSpeedEnvelope; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.sim_infra.api.PathProperties; import fr.sncf.osrd.sim_infra.impl.ChunkPath; import fr.sncf.osrd.standalone_sim.result.ResultTrain; -import fr.sncf.osrd.train.RollingStock; import fr.sncf.osrd.train.StandaloneTrainSchedule; import fr.sncf.osrd.train.TestTrains; import fr.sncf.osrd.train.TrainStop; @@ -194,7 +194,7 @@ record ConflictStatus(boolean spacing, boolean routing) {} case ROUTING -> routingConflict = true; } var conflictStatus = new ConflictStatus(spacingConflict, routingConflict); - if (statusHist.size() != 0 && statusHist.get(statusHist.size() - 1).equals(conflictStatus)) continue; + if (!statusHist.isEmpty() && statusHist.get(statusHist.size() - 1).equals(conflictStatus)) continue; statusHist.add(conflictStatus); } var expectedStatusHist = List.of( @@ -485,7 +485,7 @@ private static SimResult simpleSim( intermediateStops, List.of(), "test", - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, null, null); return new SimResult(ScheduleMetadataExtractor.run(envelope, path, chunkPath, schedule, fullInfra), envelope); diff --git a/core/src/test/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractorTests.java b/core/src/test/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractorTests.java index 3e5d70d5bd3..420aa8097f5 100644 --- a/core/src/test/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractorTests.java +++ b/core/src/test/java/fr/sncf/osrd/standalone_sim/ScheduleMetadataExtractorTests.java @@ -10,6 +10,7 @@ import fr.sncf.osrd.api.FullInfra; import fr.sncf.osrd.envelope.Envelope; import fr.sncf.osrd.envelope_sim.SimpleContextBuilder; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.sim_infra.api.PathProperties; import fr.sncf.osrd.sim_infra.api.TrackInfraKt; import fr.sncf.osrd.sim_infra.impl.ChunkPath; @@ -136,7 +137,7 @@ public void oneLineInfraStopsTests() throws Exception { List.of(new TrainStop[] {new TrainStop(500., 1000, true), new TrainStop(501., 10, true)}), List.of(), "test", - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, null, null); var res = ScheduleMetadataExtractor.run(envelope, pathProps, chunkPath, schedule, infra); @@ -170,15 +171,7 @@ private static void makeRouteOccupancy( RollingStock testRollingStock, Envelope envelope) { var schedule = new StandaloneTrainSchedule( - testRollingStock, - 0, - new ArrayList<>(), - List.of(), - List.of(), - "test", - RollingStock.Comfort.STANDARD, - null, - null); + testRollingStock, 0, new ArrayList<>(), List.of(), List.of(), "test", Comfort.STANDARD, null, null); ScheduleMetadataExtractor.run(envelope, path, chunkPath, schedule, fullInfra); } } diff --git a/core/src/test/java/fr/sncf/osrd/train/TestRollingStock.java b/core/src/test/java/fr/sncf/osrd/train/TestRollingStock.java index 26a8dcdde1e..43ab6499b1e 100644 --- a/core/src/test/java/fr/sncf/osrd/train/TestRollingStock.java +++ b/core/src/test/java/fr/sncf/osrd/train/TestRollingStock.java @@ -7,6 +7,7 @@ import fr.sncf.osrd.envelope_sim.EnvelopeSimPath; import fr.sncf.osrd.envelope_sim.EnvelopeSimPathBuilder; import fr.sncf.osrd.envelope_sim.PhysicsRollingStock; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; @@ -33,10 +34,7 @@ static Stream mapTractiveEffortCurveArgs() { EnvelopeSimPathBuilder.withElectricalProfiles25000(40), EnvelopeSimPathBuilder.withElectricalProfiles25000(60), EnvelopeSimPathBuilder.withModes(50)), - List.of( - RollingStock.Comfort.STANDARD, - RollingStock.Comfort.AIR_CONDITIONING, - RollingStock.Comfort.HEATING), + List.of(Comfort.STANDARD, Comfort.AIR_CONDITIONING, Comfort.HEATING), Arrays.asList(powerRestrictionMap, emptyPowerRestrictionMap)) .stream() .map(args -> Arguments.of(args.get(0), args.get(1), args.get(2))); @@ -45,7 +43,7 @@ static Stream mapTractiveEffortCurveArgs() { @ParameterizedTest @MethodSource("mapTractiveEffortCurveArgs") void testMapTractiveEffortCurveCoherent( - EnvelopeSimPath path, RollingStock.Comfort comfort, RangeMap powerRestrictionMap) { + EnvelopeSimPath path, Comfort comfort, RangeMap powerRestrictionMap) { var rollingStock = TestTrains.REALISTIC_FAST_TRAIN; var elecCondMap = path.getElectrificationMap( @@ -82,7 +80,7 @@ void testMapTractiveEffortCurveWithProfiles() { var rollingStock = TestTrains.REALISTIC_FAST_TRAIN; - var comfort = RollingStock.Comfort.STANDARD; + var comfort = Comfort.STANDARD; var elecCondMap = path.getElectrificationMap( rollingStock.basePowerClass, powerRestrictionMap, rollingStock.powerRestrictions); var res = rollingStock.mapTractiveEffortCurves(elecCondMap, comfort); @@ -121,7 +119,10 @@ void testMapTractiveEffortCurveWithProfiles() { new InfraConditions("thermal", null, null), // 20 No mode given new InfraConditions("thermal", null, null) // 30 Invalid mode }, - res.conditions().subRangeMap(Range.closed(0., path.getLength())).asMapOfRanges().values().stream() + res.conditions() + .subRangeMap(Range.closed(0., path.getLength())) + .asMapOfRanges() + .values() .toArray()); // Check that the curves are correct @@ -153,14 +154,13 @@ static void testRangeCoverage(RangeMap map, double length) { var subMap = map.subRangeMap(Range.closed(0., length)); var span = subMap.span(); - assertTrue((span.upperEndpoint() - span.lowerEndpoint()) == length, "map does not cover the whole path"); + assertEquals((span.upperEndpoint() - span.lowerEndpoint()), length, "map does not cover the whole path"); var entries = subMap.asMapOfRanges().entrySet().iterator(); var prev = entries.next(); while (entries.hasNext()) { var next = entries.next(); - assertTrue( - prev.getKey().upperEndpoint().equals(next.getKey().lowerEndpoint()), "ranges are not contiguous"); + assertEquals(prev.getKey().upperEndpoint(), next.getKey().lowerEndpoint(), "ranges are not contiguous"); prev = next; } } diff --git a/core/src/test/java/fr/sncf/osrd/train/TestTrains.java b/core/src/test/java/fr/sncf/osrd/train/TestTrains.java index 3bd495aa80b..e59413d59b6 100644 --- a/core/src/test/java/fr/sncf/osrd/train/TestTrains.java +++ b/core/src/test/java/fr/sncf/osrd/train/TestTrains.java @@ -5,8 +5,8 @@ import com.google.common.collect.Lists; import fr.sncf.osrd.envelope_sim.PhysicsRollingStock; import fr.sncf.osrd.envelope_sim.SimpleRollingStock.CurveShape; +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort; import fr.sncf.osrd.railjson.schema.rollingstock.RJSLoadingGaugeType; -import fr.sncf.osrd.train.RollingStock.Comfort; import fr.sncf.osrd.utils.Helpers; import java.util.*; import org.junit.jupiter.api.Test; diff --git a/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt b/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt index 635264374f5..ab8949bfc33 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/standalone_sim/StandaloneSimulationTest.kt @@ -14,9 +14,9 @@ import fr.sncf.osrd.envelope_sim.pipelines.MaxSpeedEnvelope import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.envelope_sim_infra.MRSP import fr.sncf.osrd.external_generated_inputs.ElectricalProfileMapping +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.railjson.schema.schedule.RJSAllowanceDistribution import fr.sncf.osrd.sim_infra.api.makePathProperties -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.utils.Helpers import fr.sncf.osrd.utils.distanceRangeMapOf @@ -62,7 +62,7 @@ class StandaloneSimulationTest { true ) private val curvesAndConditions = - rollingStock.mapTractiveEffortCurves(electrificationMap, RollingStock.Comfort.STANDARD) + rollingStock.mapTractiveEffortCurves(electrificationMap, Comfort.STANDARD) private var context = EnvelopeSimContext(rollingStock, envelopeSimPath, 2.0, curvesAndConditions.curves) private val maxSpeedEnvelope = MaxSpeedEnvelope.from(context, doubleArrayOf(), mrsp) @@ -79,7 +79,7 @@ class StandaloneSimulationTest { routes.toIdxList(), ElectricalProfileMapping(), rollingStock, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, RJSAllowanceDistribution.LINEAR, null, distanceRangeMapOf(), @@ -196,7 +196,7 @@ class StandaloneSimulationTest { routes.toIdxList(), ElectricalProfileMapping(), rollingStock, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, testCase.allowanceDistribution, null, distanceRangeMapOf(), diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/BacktrackingTests.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/BacktrackingTests.kt index 72ccbe498f3..73221212c03 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/BacktrackingTests.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/BacktrackingTests.kt @@ -2,10 +2,10 @@ package fr.sncf.osrd.stdcm import com.google.common.collect.ImmutableMultimap import fr.sncf.osrd.graph.Pathfinding.EdgeLocation +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.stdcm.graph.simulateBlock import fr.sncf.osrd.stdcm.preprocessing.OccupancySegment -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.utils.DummyInfra import fr.sncf.osrd.utils.units.Offset @@ -33,7 +33,7 @@ class BacktrackingTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -75,7 +75,7 @@ class BacktrackingTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -115,7 +115,7 @@ class BacktrackingTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/DepartureTimeShiftTests.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/DepartureTimeShiftTests.kt index 1651d913e16..0675539bf02 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/DepartureTimeShiftTests.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/DepartureTimeShiftTests.kt @@ -2,10 +2,10 @@ package fr.sncf.osrd.stdcm import com.google.common.collect.ImmutableMultimap import fr.sncf.osrd.graph.Pathfinding.EdgeLocation +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.stdcm.graph.simulateBlock import fr.sncf.osrd.stdcm.preprocessing.OccupancySegment -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.utils.DummyInfra import fr.sncf.osrd.utils.units.Offset @@ -182,7 +182,7 @@ class DepartureTimeShiftTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/EngineeringAllowanceTests.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/EngineeringAllowanceTests.kt index 2a05fa45ba9..b04b0a6e4ca 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/EngineeringAllowanceTests.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/EngineeringAllowanceTests.kt @@ -2,10 +2,10 @@ package fr.sncf.osrd.stdcm import com.google.common.collect.ImmutableMultimap import fr.sncf.osrd.graph.Pathfinding.EdgeLocation +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.stdcm.graph.simulateBlock import fr.sncf.osrd.stdcm.preprocessing.OccupancySegment -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.utils.DummyInfra import fr.sncf.osrd.utils.units.Offset @@ -42,7 +42,7 @@ class EngineeringAllowanceTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -54,7 +54,7 @@ class EngineeringAllowanceTests { firstBlockEnvelope.endSpeed, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -122,7 +122,7 @@ class EngineeringAllowanceTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -134,7 +134,7 @@ class EngineeringAllowanceTests { firstBlockEnvelope.endSpeed, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -205,7 +205,7 @@ class EngineeringAllowanceTests { 0.0, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null @@ -217,7 +217,7 @@ class EngineeringAllowanceTests { firstBlockEnvelope.endSpeed, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/FullSTDCMTests.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/FullSTDCMTests.kt index 9d31ff65b53..9b94f5ad571 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/FullSTDCMTests.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/FullSTDCMTests.kt @@ -8,11 +8,11 @@ import fr.sncf.osrd.api.stdcm.makeTrainSchedule import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue import fr.sncf.osrd.graph.PathfindingEdgeLocationId import fr.sncf.osrd.railjson.parser.RJSRollingStockParser +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.standalone_sim.result.ResultTrain.SpacingRequirement import fr.sncf.osrd.standalone_sim.run import fr.sncf.osrd.stdcm.preprocessing.implementation.makeBlockAvailability -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.utils.Helpers import fr.sncf.osrd.utils.Helpers.smallInfra @@ -273,7 +273,7 @@ class FullSTDCMTests { makeTrainSchedule( res.envelope.endPos, TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, res.stopResults ), infra diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt index 19db271ebf8..642b79db8f4 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMHelpers.kt @@ -8,6 +8,7 @@ import fr.sncf.osrd.envelope_sim_infra.EnvelopeTrainPath import fr.sncf.osrd.graph.GraphAdapter import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingEdgeLocationId +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.* import fr.sncf.osrd.sim_infra.impl.ChunkPath import fr.sncf.osrd.standalone_sim.EnvelopeStopWrapper @@ -17,7 +18,6 @@ import fr.sncf.osrd.stdcm.graph.simulateBlock import fr.sncf.osrd.stdcm.infra_exploration.InfraExplorer import fr.sncf.osrd.stdcm.infra_exploration.initInfraExplorer import fr.sncf.osrd.stdcm.preprocessing.OccupancySegment -import fr.sncf.osrd.train.RollingStock import fr.sncf.osrd.train.StandaloneTrainSchedule import fr.sncf.osrd.train.TestTrains import fr.sncf.osrd.train.TrainStop @@ -48,7 +48,7 @@ fun makeRequirementsFromPath( listOf(TrainStop(trainPath.getLength().meters, 1.0, true)), listOf(), null, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, null, null ) @@ -107,7 +107,7 @@ fun getBlocksRunTime(infra: FullInfra, blocks: List): Double { speed, Offset(0.meters), TestTrains.REALISTIC_FAST_TRAIN, - RollingStock.Comfort.STANDARD, + Comfort.STANDARD, 2.0, null, null diff --git a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt index 97802c60999..c53f5d8b5fd 100644 --- a/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt +++ b/core/src/test/kotlin/fr/sncf/osrd/stdcm/STDCMPathfindingBuilder.kt @@ -6,6 +6,7 @@ import fr.sncf.osrd.api.FullInfra import fr.sncf.osrd.envelope_sim.allowances.utils.AllowanceValue import fr.sncf.osrd.graph.Pathfinding import fr.sncf.osrd.graph.PathfindingEdgeLocationId +import fr.sncf.osrd.railjson.schema.rollingstock.Comfort import fr.sncf.osrd.sim_infra.api.Block import fr.sncf.osrd.sim_infra.api.BlockId import fr.sncf.osrd.stdcm.graph.findPath @@ -13,7 +14,6 @@ import fr.sncf.osrd.stdcm.preprocessing.DummyBlockAvailability import fr.sncf.osrd.stdcm.preprocessing.OccupancySegment import fr.sncf.osrd.stdcm.preprocessing.interfaces.BlockAvailabilityInterface import fr.sncf.osrd.train.RollingStock -import fr.sncf.osrd.train.RollingStock.Comfort import fr.sncf.osrd.train.TestTrains /** From 1d1fac45b9c9918c491ac1f76b8241a1f747260e Mon Sep 17 00:00:00 2001 From: Youness CHRIFI ALAOUI Date: Mon, 2 Sep 2024 17:33:12 +0200 Subject: [PATCH 5/5] editoast: add new migration --- .../down.sql | 2 ++ .../up.sql | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/down.sql create mode 100644 editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/up.sql diff --git a/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/down.sql b/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/down.sql new file mode 100644 index 00000000000..6d28956b02b --- /dev/null +++ b/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/down.sql @@ -0,0 +1,2 @@ +UPDATE rolling_stock +SET effort_curves = REGEXP_REPLACE(effort_curves::text, '"AIR_CONDITIONING"', '"AC"', 'g')::jsonb; diff --git a/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/up.sql b/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/up.sql new file mode 100644 index 00000000000..44ca511b710 --- /dev/null +++ b/editoast/migrations/2024-09-02-132335_replace_mode_ac_with_air_conditioning/up.sql @@ -0,0 +1,2 @@ +UPDATE rolling_stock +SET effort_curves = REGEXP_REPLACE(effort_curves::text, '"AC"', '"AIR_CONDITIONING"', 'g')::jsonb;