Skip to content

Commit

Permalink
front: refacto useOutputData
Browse files Browse the repository at this point in the history
The logic to compute the data for the output table has been modified:

- instead of handling both pathsteps and regular operational points on the path at the same time, we now handle first the path steps (which may have some additional
information, such as margins, schedules, stop duration...) and then handle the regular operational points (we only need to compute the arrival time). This
simplifies a lot the hook

- instead of re-computing the time of each waypoint, we now use the times received in the summary of the train.

Signed-off-by: Clara Ni <[email protected]>
  • Loading branch information
clarani committed Nov 18, 2024
1 parent 6600f73 commit e989762
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ const formatTrainScheduleSummaries = (
duration: trainSummary.time,
pathLength: formatKmValue(trainSummary.length, 'millimeters', 1),
mechanicalEnergyConsumed: jouleToKwh(trainSummary.energy_consumption, true),
pathItemTimes: {
base: trainSummary.path_item_times_base,
provisional: trainSummary.path_item_times_provisional,
final: trainSummary.path_item_times_final,
},
}
: {
isValid: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ const useScenarioData = (
allTrainsProjected,
}
: undefined,
simulationResults,
simulationResults: {
...simulationResults,
selectedTrainSummary: selectedTrainId
? trainScheduleSummariesById.get(selectedTrainId)
: undefined,
},
conflicts,
removeTrains,
upsertTrainSchedules,
Expand Down
2 changes: 2 additions & 0 deletions front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
} from 'common/api/osrdEditoastApi';
import type { RangedValue } from 'common/types';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import type { ArrayElement } from 'utils/types';

export interface Step {
Expand Down Expand Up @@ -143,6 +144,7 @@ export type SimulationResultsData = {
selectedTrainSchedule?: TrainScheduleResult;
selectedTrainRollingStock?: RollingStockWithLiveries;
selectedTrainPowerRestrictions: LayerData<PowerRestrictionValues>[];
selectedTrainSummary?: TrainScheduleWithDetails;
trainSimulation?: SimulationResponseSuccess;
pathProperties?: PathPropertiesFormatted;
pathLength?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const SimulationResults = ({
selectedTrainSchedule,
selectedTrainRollingStock,
selectedTrainPowerRestrictions,
selectedTrainSummary,
trainSimulation,
pathProperties,
path,
Expand Down Expand Up @@ -205,23 +206,19 @@ const SimulationResults = ({
</div>

{/* TIME STOPS TABLE */}
{selectedTrainSchedule &&
trainSimulation.status === 'success' &&
pathProperties &&
operationalPoints &&
infraId && (
<div className="time-stop-outputs">
<p className="mt-2 mb-3 ml-3 font-weight-bold">{t('timetableOutput')}</p>
<TimesStopsOutput
simulatedTrain={trainSimulation}
pathProperties={pathProperties}
operationalPoints={operationalPoints}
selectedTrainSchedule={selectedTrainSchedule}
path={path}
dataIsLoading={formattedOpPointsLoading}
/>
</div>
)}
{selectedTrainSchedule && pathProperties && selectedTrainSummary && (
<div className="time-stop-outputs">
<p className="mt-2 mb-3 ml-3 font-weight-bold">{t('timetableOutput')}</p>
<TimesStopsOutput
simulatedTrain={trainSimulation}
trainSummary={selectedTrainSummary}
pathProperties={pathProperties}
selectedTrainSchedule={selectedTrainSchedule}
path={path}
dataIsLoading={formattedOpPointsLoading}
/>
</div>
)}

{/* SIMULATION EXPORT BUTTONS */}
{selectedTrainSchedule &&
Expand Down
10 changes: 6 additions & 4 deletions front/src/modules/timesStops/TimesStopsOutput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import cx from 'classnames';

import type {
OperationalPointWithTimeAndSpeed,
PathPropertiesFormatted,
SimulationResponseSuccess,
} from 'applications/operationalStudies/types';
import type { PathfindingResultSuccess, TrainScheduleResult } from 'common/api/osrdEditoastApi';
import { Loader } from 'common/Loaders/Loader';
import type { TrainScheduleWithDetails } from 'modules/trainschedule/components/Timetable/types';
import { NO_BREAK_SPACE } from 'utils/strings';

import useOutputTableData from './hooks/useOutputTableData';
Expand All @@ -15,35 +15,37 @@ import { TableType, type TimeStopsRow } from './types';

type TimesStopsOutputProps = {
simulatedTrain: SimulationResponseSuccess;
trainSummary: TrainScheduleWithDetails;
pathProperties: PathPropertiesFormatted;
operationalPoints: OperationalPointWithTimeAndSpeed[];
selectedTrainSchedule: TrainScheduleResult;
path?: PathfindingResultSuccess;
dataIsLoading: boolean;
};

const TimesStopsOutput = ({
simulatedTrain,
trainSummary,
pathProperties,
operationalPoints,
selectedTrainSchedule,
path,
dataIsLoading,
}: TimesStopsOutputProps) => {
const enrichedOperationalPoints = useOutputTableData(
simulatedTrain,
trainSummary,
pathProperties,
operationalPoints,
selectedTrainSchedule,
path
);

if (dataIsLoading) {
return (
<div style={{ height: '600px' }}>
<Loader />
</div>
);
}

return (
<TimesStops
rows={enrichedOperationalPoints}
Expand Down
29 changes: 0 additions & 29 deletions front/src/modules/timesStops/helpers/__tests__/arrivalTime.spec.ts

This file was deleted.

Loading

0 comments on commit e989762

Please sign in to comment.