Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: manchette: display waypoints added with map click #8698

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions front/public/locales/en/simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"used": "used"
},
"projectionInProgress": "Projection in progress: {{ count }}/{{ total }} trains",
"requestedPoint": "requested point ({{ count }})",
"reset": "Reset the chart",
"resetTimer": "Reset timer",
"rotate": "Rotate the chart",
Expand Down
1 change: 1 addition & 0 deletions front/public/locales/fr/simulation.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"used": "utilisée"
},
"projectionInProgress": "Projection en cours: {{ count }}/{{ total }} trains",
"requestedPoint": "point demandé ({{ count }})",
"reset": "Réinitialiser le graphique",
"resetTimer": "Réinitialiser le compteur",
"rotate": "Pivoter le graphique",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ const useScenarioData = () => {
[projectedTrainsById]
);

const trainScheduleUsedForProjection = useMemo(
() => trainSchedules?.find((trainSchedule) => trainSchedule.id === trainIdUsedForProjection),
[trainIdUsedForProjection, trainSchedules]
);

useEffect(() => {
if (!rawTrainSchedules) {
setTrainSchedules(undefined);
Expand Down Expand Up @@ -193,6 +198,7 @@ const useScenarioData = () => {
infra: { infra, isInfraLoaded, reloadCount },
trainScheduleSummaries,
trainSchedules,
trainScheduleUsedForProjection,
trainIdUsedForProjection,
projectedTrains,
simulationResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const Scenario = () => {
infra: { infra, isInfraLoaded, reloadCount },
trainScheduleSummaries,
trainSchedules,
trainScheduleUsedForProjection,
trainIdUsedForProjection,
projectedTrains,
simulationResults,
Expand Down Expand Up @@ -308,6 +309,7 @@ const Scenario = () => {
collapsedTimetable={collapsedTimetable}
spaceTimeData={projectedTrains}
simulationResults={simulationResults}
trainScheduleUsedForProjection={trainScheduleUsedForProjection}
trainIdUsedForProjection={trainIdUsedForProjection}
infraId={infraId}
timetableTrainNb={timetable.train_ids.length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useSelector } from 'react-redux';
import { Rnd } from 'react-rnd';

import type { SimulationResults, TrainSpaceTimeData } from 'applications/operationalStudies/types';
import type { TrainScheduleResult } from 'common/api/osrdEditoastApi';
import SimulationWarpedMap from 'common/Map/WarpedMap/SimulationWarpedMap';
import { getScaleDomainFromValuesV2 } from 'modules/simulationResult/components/ChartHelpers/getScaleDomainFromValues';
import SimulationResultsMapV2 from 'modules/simulationResult/components/SimulationResultsMapV2';
Expand All @@ -33,6 +34,7 @@ type SimulationResultsV2Props = {
collapsedTimetable: boolean;
spaceTimeData?: TrainSpaceTimeData[];
infraId?: number;
trainScheduleUsedForProjection?: TrainScheduleResult;
trainIdUsedForProjection?: number;
simulationResults: SimulationResults;
timetableTrainNb: number;
Expand All @@ -42,6 +44,7 @@ const SimulationResultsV2 = ({
collapsedTimetable,
spaceTimeData,
infraId,
trainScheduleUsedForProjection,
trainIdUsedForProjection,
simulationResults: {
selectedTrainSchedule,
Expand Down Expand Up @@ -88,6 +91,7 @@ const SimulationResultsV2 = ({
);

const projectedOperationalPoints = useGetProjectedTrainOperationalPoints(
trainScheduleUsedForProjection,
trainIdUsedForProjection,
infraId
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import { useEffect, useState } from 'react';

import { useTranslation } from 'react-i18next';

import { STDCM_TRAIN_ID } from 'applications/stdcm/consts';
import {
osrdEditoastApi,
type PathProperties,
type PostInfraByInfraIdPathPropertiesApiArg,
type TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
import { addElementAtIndex } from 'utils/array';

const useGetProjectedTrainOperationalPoints = (
trainScheduleUsedForProjection?: TrainScheduleResult,
trainIdUsedForProjection?: number,
infraId?: number
) => {
const { t } = useTranslation('simulation');
const [operationalPoints, setOperationalPoints] = useState<
NonNullable<PathProperties['operational_points']>
>([]);

const { data: pathfindingResult } = osrdEditoastApi.endpoints.getTrainScheduleByIdPath.useQuery(
{
id: trainIdUsedForProjection as number,
infraId: infraId as number,
id: trainIdUsedForProjection!,
infraId: infraId!,
},
{
skip: !trainIdUsedForProjection || !infraId || trainIdUsedForProjection === STDCM_TRAIN_ID,
Expand All @@ -30,23 +35,60 @@ const useGetProjectedTrainOperationalPoints = (

useEffect(() => {
const getOperationalPoints = async () => {
if (infraId && pathfindingResult && pathfindingResult.status === 'success') {
const pathPropertiesParams: PostInfraByInfraIdPathPropertiesApiArg = {
if (infraId && trainScheduleUsedForProjection && pathfindingResult?.status === 'success') {
const { operational_points } = await postPathProperties({
infraId,
props: ['operational_points'],
pathPropertiesInput: {
track_section_ranges: pathfindingResult.track_section_ranges,
},
};
const { operational_points } = await postPathProperties(pathPropertiesParams).unwrap();
}).unwrap();

let operationalPointsWithAllWaypoints = operational_points!;

// Check if there are vias added by map click and insert them in the operational points
let waypointCounter = 1;

trainScheduleUsedForProjection.path.forEach((step, i) => {
if (!('track' in step)) return;

const positionOnPath = pathfindingResult.path_item_positions[i];
const indexToInsert = operationalPointsWithAllWaypoints.findIndex(
(op) => op.position >= positionOnPath
);

const formattedStep: NonNullable<PathProperties['operational_points']>[number] = {
id: step.id,
extensions: {
identifier: {
name: t('requestedPoint', { count: waypointCounter }),
uic: 0,
},
},
part: { track: step.track, position: step.offset },
position: positionOnPath,
};

waypointCounter += 1;

// If we can't find any op position greater than the current step position, we add it at the end
if (indexToInsert === -1) {
operationalPointsWithAllWaypoints.push(formattedStep);
return;
}

operationalPointsWithAllWaypoints = addElementAtIndex(
operationalPointsWithAllWaypoints,
indexToInsert,
formattedStep
);
});

setOperationalPoints(
operational_points as NonNullable<PathProperties['operational_points']>
);
setOperationalPoints(operationalPointsWithAllWaypoints);
}
};
getOperationalPoints();
}, [pathfindingResult, infraId]);
}, [pathfindingResult, infraId, t]);

return operationalPoints;
};
Expand Down
Loading