Skip to content

Commit

Permalink
front: drop simulation results and stdcm v1
Browse files Browse the repository at this point in the history
  • Loading branch information
SharglutDev committed Aug 2, 2024
1 parent 1b5c4b4 commit 8f345ad
Show file tree
Hide file tree
Showing 79 changed files with 153 additions and 39,427 deletions.
5 changes: 0 additions & 5 deletions front/public/locales/en/simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@
"speedLimitComposition": "Composition",
"speedSpaceChart": "Speed Space Chart",
"speedSpaceSettings": {
"altitude": "Altitude",
"context": "Context",
"curves": "Curves",
"display": "Display",
"electricalProfiles": "Electrical profiles",
"energySource": "Energy source",
"maxSpeed": "Line speed",
"powerRestriction": "Power restriction",
"powerRestrictions": "Power restrictions",
"reticleInfos": "Reticle infos",
"slopes": "Slopes",
Expand Down
5 changes: 0 additions & 5 deletions front/public/locales/fr/simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,9 @@
"speedLimitComposition": "Composition",
"speedSpaceChart": "Graphique Espace Vitesse",
"speedSpaceSettings": {
"altitude": "Altitude",
"context": "Contexte",
"curves": "Courbes",
"display": "Affichage",
"electricalProfiles": "Profils électrique",
"energySource": "Source d'énergie",
"maxSpeed": "Vitesse ligne",
"powerRestriction": "Restriction de puissance",
"powerRestrictions": "Restrictions de puissance",
"reticleInfos": "Infos réticule",
"slopes": "Déclivités",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
import i18n from 'i18next';
import { differenceBy } from 'lodash';

import {
type SimulationReport,
type TrainScheduleSummary,
osrdEditoastApi,
} from 'common/api/osrdEditoastApi';
import { setFailure } from 'reducers/main';
import {
updateAllowancesSettings,
updateIsUpdating,
updateSelectedProjection,
updateSelectedTrainId,
updateSimulation,
} from 'reducers/osrdsimulation/actions';
import type { AllowancesSettings, Projection } from 'reducers/osrdsimulation/types';
/* eslint-disable import/prefer-default-export */
import { type TrainScheduleSummary } from 'common/api/osrdEditoastApi';
import { updateSelectedProjection, updateSelectedTrainId } from 'reducers/osrdsimulation/actions';
import type { Projection } from 'reducers/osrdsimulation/types';
import { store } from 'store';
import { castErrorToFailure } from 'utils/error';

export function selectProjection(
trainSchedules: TrainScheduleSummary[],
Expand Down Expand Up @@ -78,71 +64,3 @@ export function selectProjection(
);
store.dispatch(updateSelectedTrainId(sortedTrainSchedules[0].id));
}

/**
* - If first load of the scenario, get all timetable trains results and update the simulation.
* - If adding/updating train(s), get these train results and update the simulation.
* - If deleting train(s) and there are still trains in the timetable, do nothing
*/
export default async function getSimulationResults(
trainSchedulesIDs: number[],
selectedProjection: Projection,
allowancesSettings?: AllowancesSettings,
simulation?: SimulationReport[]
) {
if (trainSchedulesIDs.length > 0) {
store.dispatch(updateIsUpdating(true));
try {
// We only want to display the valid trains simulations
let { simulations: simulationLocal } = await store
.dispatch(
osrdEditoastApi.endpoints.postTrainScheduleResults.initiate({
body: {
path_id: selectedProjection.path,
train_ids: trainSchedulesIDs,
},
})
)
.unwrap();

// Means that we are adding or updating a train and we need to add it in the present simulation
if (simulation) {
const unaffectedTrains = differenceBy(simulation, simulationLocal, 'id');
simulationLocal = unaffectedTrains.concat(simulationLocal);
}

const sortedSimulationLocal = [...simulationLocal].sort(
(a: SimulationReport, b: SimulationReport) => a.base.stops[0].time - b.base.stops[0].time
);
store.dispatch(updateSimulation({ trains: sortedSimulationLocal }));

// Create margins settings for each train if not set
const newAllowancesSettings = { ...(allowancesSettings || {}) };
sortedSimulationLocal.forEach((train) => {
if (!newAllowancesSettings[train.id]) {
newAllowancesSettings[train.id] = {
base: true,
baseBlocks: true,
eco: true,
ecoBlocks: false,
};
}
});
store.dispatch(updateAllowancesSettings(newAllowancesSettings));
} catch (e) {
store.dispatch(
setFailure(
castErrorToFailure(e, {
name: i18n.t('simulation:errorMessages.unableToRetrieveTrainSchedule'),
})
)
);
} finally {
store.dispatch(updateIsUpdating(false));
}
} else if (!simulation) {
store.dispatch(updateSimulation({ trains: [] }));
store.dispatch(updateSelectedTrainId(undefined));
store.dispatch(updateSelectedProjection(undefined));
}
}
213 changes: 0 additions & 213 deletions front/src/applications/operationalStudies/consts.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,6 @@
import type { Position } from 'geojson';

import type { ElectrificationRange, ElectrificationUsage } from 'common/api/osrdEditoastApi';
import type { LinearMetadataItem } from 'common/IntervalsDataViz/types';
import i18n from 'i18n';
import type { Mode } from 'modules/simulationResult/components/SpeedSpaceChart/types';
import type { HeightPosition } from 'reducers/osrdsimulation/types';

export const BLOCKTYPES = [
{
key: 'BAL',
value: 'BAL',
},
{
key: 'BAPR',
value: 'BAPR',
},
{
key: 'ERTMS',
value: 'ERTMS 3.4.0',
},
{
key: 'TVM300',
value: 'TVM 300',
},
{
key: 'TVM430',
value: 'TVM 430',
},
];

export const SNCFCOLORS = {
blue: '#0088ce',
purple: '#6e1e78',
pink: '#a1006b',
red: '#cd0037',
redassistance: '#d52b1e',
orange: '#e05206',
yellow: '#ffb612',
green: '#82be00',
teal: '#d2e100',
cyan: '#009aa6',
carbon: '#333333',
gray: '#343a40',
coolgray11: '#4d4f53',
coolgray9: '#747678',
coolgray7: '#a0a0a0',
coolgray5: '#b9b9b9',
coolgray3: '#d7d7d7',
coolgray1: '#f2f2f2',
};

export const SNCFCOLORSONLY = {
blue: '#0088ce',
purple: '#6e1e78',
pink: '#a1006b',
red: '#cd0037',
redassistance: '#d52b1e',
orange: '#e05206',
yellow: '#ffb612',
green: '#82be00',
teal: '#d2e100',
cyan: '#009aa6',
carbon: '#333333',
};

export const DUMMYCONST = null;

export const MANAGE_TRAIN_SCHEDULE_TYPES = Object.freeze({
none: 'NONE',
Expand Down Expand Up @@ -124,152 +60,3 @@ export const STUDY_TYPES = [
export type StudyType = typeof STUDY_TYPES;

export type PowerRestrictionRange = LinearMetadataItem<{ value: string }>;

// electrical profiles
interface Profile {
mode: string;
color: string[];
isStriped: boolean;
}

/** Those keys are used to index objects of type HeightPosition but also to access properties ending by
* "_start" / "_middle" / "_end" in objects of type PowerRestrictionSegment in order to draw the linear graph. */
export const DRAWING_KEYS: (keyof HeightPosition)[] = ['position', 'height'];
export type DrawingKeys = typeof DRAWING_KEYS;

// TODO DROP V1: remove this
export interface ElectricalConditionSegment {
position_start: number;
position_end: number;
position_middle: number;
lastPosition: number;
height_start: number;
height_end: number;
height_middle: number;
electrification: ElectrificationUsage;
seenRestriction?: string;
usedRestriction?: string;
color: string;
textColor: string;
text: string;
isStriped: boolean;
isIncompatibleElectricalProfile: boolean;
isRestriction: boolean;
isIncompatiblePowerRestriction: boolean;
}

// TODO DROP V1: remove this
const electricalProfileColorsWithProfile: Mode = {
'25000V': { '25000V': '#6E1E78', '22500V': '#A453AD', '20000V': '#DD87E5' },
'1500V': {
O: '#FF0037',
A: '#FF335F',
A1: '#FF335F',
B: '#FF6687',
B1: '#FF6687',
C: '#FF99AF',
D: '#FF99AF',
E: '#FFCCD7',
F: '#FFCCD7',
G: '#FFF',
},
thermal: '#333',
'15000V': '#009AA6',
'3000V': '#1FBE00',
};

// TODO DROP V1: remove this
const electricalProfileColorsWithoutProfile: Mode = {
'25000V': '#6E1E78',
'1500V': '#FF0037',
thermal: '#333',
'15000V': '#009AA6',
'3000V': '#1FBE00',
};

export const legend: Profile[] = [
{ mode: '25000V', color: ['25KA', '25KB'], isStriped: false },
{ mode: '1500V', color: ['1500A', '1500B', '1500C'], isStriped: false },
{
mode: 'thermal',
color: ['Thermal'],
isStriped: false,
},
{ mode: '15000V', color: ['15000V'], isStriped: false },
{ mode: '3000V', color: ['3000V'], isStriped: false },
{
mode: 'unused',
color: ['noUsed'],
isStriped: true,
},
];

// TODO DROP V1: remove this
export const createProfileSegment = (
fullElectrificationRange: ElectrificationRange[],
electrificationRange: ElectrificationRange
) => {
const electrification = electrificationRange.electrificationUsage;
const segment: ElectricalConditionSegment = {
position_start: electrificationRange.start,
position_end: electrificationRange.stop,
position_middle: (electrificationRange.start + electrificationRange.stop) / 2,
lastPosition: fullElectrificationRange.slice(-1)[0].stop,
height_start: 4,
height_end: 24,
height_middle: 14,
electrification,
color: '',
textColor: '',
text: '',
isStriped: false,
isIncompatibleElectricalProfile: false,
isRestriction: false,
isIncompatiblePowerRestriction: false,
};

// add colors to object depending of the type of electrification
if (electrification.object_type === 'Electrified') {
const { mode, mode_handled, profile, profile_handled } = electrification;
segment.color =
electricalProfileColorsWithProfile[mode as keyof unknown][
electrification.profile as string
] || electricalProfileColorsWithoutProfile[mode as keyof unknown];

segment.textColor = electricalProfileColorsWithoutProfile[mode as keyof unknown];

if (!mode_handled) {
// uncompatible mode
segment.text = `${i18n.t('electricalProfiles.incompatibleMode', { ns: 'simulation' })}`;
} else if (mode !== 'thermal') {
// compatible electric mode (themal modes are not displayed)
if (profile) {
if (profile_handled) {
// compatible electric mode, with compatible profile
segment.text = `${mode} ${profile}`;
} else {
// compatible electric mode, with uncompatible profile
segment.isIncompatibleElectricalProfile = true;
segment.isStriped = true;
segment.text = `${mode}, ${i18n.t('electricalProfiles.incompatibleProfile', {
ns: 'simulation',
})}`;
}
} else {
// compatible electric mode, but missing profile
segment.text = mode;
segment.isStriped = true;
}
}
} else if (electrification.object_type === 'Neutral') {
segment.text = 'Neutral';
segment.color = '#000000';
segment.textColor = '#000000';
} else {
segment.text = 'NonElectrified';
segment.color = '#000000';
segment.textColor = '#000';
}

return segment;
};
2 changes: 1 addition & 1 deletion front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type ElectrificationRangeV2 = {
stop: number;
};

export type ElectrificationUsageV2 = ElectrificationValue &
type ElectrificationUsageV2 = ElectrificationValue &
SimulationResponseSuccess['electrical_profiles']['values'][number];

export type BoundariesData = {
Expand Down
Loading

0 comments on commit 8f345ad

Please sign in to comment.