Skip to content

Commit b06479a

Browse files
committed
front: remove all the calls to trainSchedules endpoints
Signed-off-by: Clara Ni <[email protected]>
1 parent 865efea commit b06479a

File tree

14 files changed

+43
-337
lines changed

14 files changed

+43
-337
lines changed

front/src/applications/operationalStudies/helpers/TrainOpProjectionLazyLoader.ts

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ import {
55
type OperationalPointIdentifier,
66
type PostPacedTrainOccupancyBlocksApiResponse,
77
type PostPacedTrainProjectPathOpApiResponse,
8-
type PostTrainScheduleOccupancyBlocksApiResponse,
9-
type PostTrainScheduleProjectPathOpApiResponse,
108
} from 'common/api/osrdEditoastApi';
119
import type { TimetableItemId } from 'reducers/osrdconf/types';
1210
import {
1311
extractEditoastIdFromPacedTrainId,
14-
extractEditoastIdFromTrainScheduleId,
1512
formatEditoastIdToPacedTrainId,
16-
formatEditoastIdToTrainScheduleId,
1713
isTrainScheduleId,
1814
} from 'utils/trainId';
1915

2016
import TrainProjectionLazyLoaderAbstract, {
2117
type ProjectionResult,
2218
type TrainProjectionLazyLoaderOptions,
2319
} from './TrainProjectionLazyLoaderAbstract';
20+
2421
export default class TrainOpProjectionLazyLoader extends TrainProjectionLazyLoaderAbstract {
2522
readonly opRefs: OperationalPointIdentifier[];
2623

@@ -44,58 +41,16 @@ export default class TrainOpProjectionLazyLoader extends TrainProjectionLazyLoad
4441
return;
4542
}
4643

47-
const rawTrainScheduleIds = [];
4844
const rawPacedTrainIds = [];
4945

5046
for (const id of batch) {
5147
if (isTrainScheduleId(id)) {
52-
rawTrainScheduleIds.push(extractEditoastIdFromTrainScheduleId(id));
48+
throw new Error('TrainSchedules are not handled anymore.');
5349
} else {
5450
rawPacedTrainIds.push(extractEditoastIdFromPacedTrainId(id));
5551
}
5652
}
5753

58-
let trainSchedulePromise: Promise<PostTrainScheduleProjectPathOpApiResponse> = Promise.resolve(
59-
{}
60-
);
61-
let trainScheduleOccupancyBlocksPromise: Promise<PostTrainScheduleOccupancyBlocksApiResponse> =
62-
Promise.resolve({});
63-
if (rawTrainScheduleIds.length > 0) {
64-
trainSchedulePromise = this.options
65-
.dispatch(
66-
osrdEditoastApi.endpoints.postTrainScheduleProjectPathOp.initiate(
67-
{
68-
body: {
69-
infra_id: infraId,
70-
train_ids: rawTrainScheduleIds,
71-
operational_points_refs: this.opRefs,
72-
operational_points_distances: this.opDistances,
73-
},
74-
},
75-
{ subscribe: false }
76-
)
77-
)
78-
.unwrap();
79-
80-
if (path) {
81-
trainScheduleOccupancyBlocksPromise = this.options
82-
.dispatch(
83-
osrdEditoastApi.endpoints.postTrainScheduleOccupancyBlocks.initiate(
84-
{
85-
occupancyBlockForm: {
86-
infra_id: infraId,
87-
path,
88-
ids: rawTrainScheduleIds,
89-
electrical_profile_set_id: electricalProfileSetId,
90-
},
91-
},
92-
{ subscribe: false }
93-
)
94-
)
95-
.unwrap();
96-
}
97-
}
98-
9954
let pacedTrainPromise: Promise<PostPacedTrainProjectPathOpApiResponse> = Promise.resolve({});
10055
let pacedTrainOccupancyBlocksPromise: Promise<PostPacedTrainOccupancyBlocksApiResponse> =
10156
Promise.resolve({});
@@ -136,9 +91,7 @@ export default class TrainOpProjectionLazyLoader extends TrainProjectionLazyLoad
13691
}
13792
}
13893

139-
const rawTrainScheduleResults = await trainSchedulePromise;
14094
const rawPacedTrainResults = await pacedTrainPromise;
141-
const rawTrainScheduleOccupancyBlocks = await trainScheduleOccupancyBlocksPromise;
14295
const rawPacedTrainOccupancyBlocks = await pacedTrainOccupancyBlocksPromise;
14396

14497
if (this.cancelled) {
@@ -147,14 +100,6 @@ export default class TrainOpProjectionLazyLoader extends TrainProjectionLazyLoad
147100

148101
const rawResults = new Map<TimetableItemId, ProjectionResult>();
149102

150-
for (const [id, result] of Object.entries(rawTrainScheduleResults)) {
151-
const trainScheduleId = formatEditoastIdToTrainScheduleId(Number(id));
152-
rawResults.set(trainScheduleId, {
153-
space_time_curves: result,
154-
signal_updates: rawTrainScheduleOccupancyBlocks[id],
155-
});
156-
}
157-
158103
for (const [id, result] of Object.entries(rawPacedTrainResults)) {
159104
const pacedTrainId = formatEditoastIdToPacedTrainId(Number(id));
160105
const pacedTrainProjectionResult: ProjectionResult = {

front/src/applications/operationalStudies/helpers/TrainSimulationLazyLoader.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ import {
22
osrdEditoastApi,
33
type PacedTrainSimulationSummaryResult,
44
type PostPacedTrainSimulationSummaryApiResponse,
5-
type PostTrainScheduleSimulationSummaryApiResponse,
6-
type SimulationSummaryResult,
75
} from 'common/api/osrdEditoastApi';
8-
import type { PacedTrainId, TimetableItemId, TrainScheduleId } from 'reducers/osrdconf/types';
6+
import type { PacedTrainId, TimetableItemId } from 'reducers/osrdconf/types';
97
import type { AppDispatch } from 'store';
108
import {
119
formatEditoastIdToPacedTrainId,
12-
formatEditoastIdToTrainScheduleId,
1310
extractEditoastIdFromPacedTrainId,
14-
extractEditoastIdFromTrainScheduleId,
1511
isTrainScheduleId,
1612
} from 'utils/trainId';
1713

@@ -21,10 +17,7 @@ type TrainSimulationLazyLoaderOptions = {
2117
dispatch: AppDispatch;
2218
infraId: number;
2319
electricalProfileSetId?: number;
24-
onProgress: (
25-
trainScheduleSummaries: Map<TrainScheduleId, SimulationSummaryResult>,
26-
pacedTrainSummaries: Map<PacedTrainId, PacedTrainSimulationSummaryResult>
27-
) => void;
20+
onProgress: (pacedTrainSummaries: Map<PacedTrainId, PacedTrainSimulationSummaryResult>) => void;
2821
};
2922

3023
/**
@@ -79,35 +72,15 @@ export default class TrainSimulationLazyLoader {
7972
}
8073

8174
async processBatch(batch: TimetableItemId[]) {
82-
const rawTrainScheduleIds = [];
8375
const rawPacedTrainIds = [];
8476
for (const id of batch) {
8577
if (isTrainScheduleId(id)) {
86-
rawTrainScheduleIds.push(extractEditoastIdFromTrainScheduleId(id));
78+
throw new Error('TrainSchedules are not handled anymore.');
8779
} else {
8880
rawPacedTrainIds.push(extractEditoastIdFromPacedTrainId(id));
8981
}
9082
}
9183

92-
let trainSchedulePromise: Promise<PostTrainScheduleSimulationSummaryApiResponse> =
93-
Promise.resolve({});
94-
if (rawTrainScheduleIds.length > 0) {
95-
trainSchedulePromise = this.options
96-
.dispatch(
97-
osrdEditoastApi.endpoints.postTrainScheduleSimulationSummary.initiate(
98-
{
99-
body: {
100-
infra_id: this.options.infraId,
101-
ids: rawTrainScheduleIds,
102-
electrical_profile_set_id: this.options.electricalProfileSetId,
103-
},
104-
},
105-
{ subscribe: false }
106-
)
107-
)
108-
.unwrap();
109-
}
110-
11184
let pacedTrainPromise: Promise<PostPacedTrainSimulationSummaryApiResponse> = Promise.resolve(
11285
{}
11386
);
@@ -128,24 +101,18 @@ export default class TrainSimulationLazyLoader {
128101
.unwrap();
129102
}
130103

131-
const rawTrainScheduleSummaries = await trainSchedulePromise;
132104
const rawPacedTrainSummaries = await pacedTrainPromise;
133105

134106
if (this.cancelled) {
135107
return;
136108
}
137109

138-
const trainScheduleSummaries = new Map();
139110
const pacedTrainSummaries = new Map();
140-
for (const [rawId, rawSummary] of Object.entries(rawTrainScheduleSummaries)) {
141-
const id = formatEditoastIdToTrainScheduleId(Number(rawId));
142-
trainScheduleSummaries.set(id, rawSummary);
143-
}
144111
for (const [rawId, rawSummary] of Object.entries(rawPacedTrainSummaries)) {
145112
const id = formatEditoastIdToPacedTrainId(Number(rawId));
146113
pacedTrainSummaries.set(id, rawSummary);
147114
}
148115

149-
this.options.onProgress(trainScheduleSummaries, pacedTrainSummaries);
116+
this.options.onProgress(pacedTrainSummaries);
150117
}
151118
}

front/src/applications/operationalStudies/helpers/TrainTrackProjectionLazyLoader.ts

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ import { isEmpty } from 'lodash';
22

33
import {
44
osrdEditoastApi,
5-
type PostTrainScheduleProjectPathApiResponse,
6-
type PostTrainScheduleOccupancyBlocksApiResponse,
75
type PostPacedTrainProjectPathApiResponse,
86
type PostPacedTrainOccupancyBlocksApiResponse,
97
type CoreTrainPath,
108
} from 'common/api/osrdEditoastApi';
119
import type { TimetableItemId } from 'reducers/osrdconf/types';
1210
import {
1311
extractEditoastIdFromPacedTrainId,
14-
extractEditoastIdFromTrainScheduleId,
1512
formatEditoastIdToPacedTrainId,
16-
formatEditoastIdToTrainScheduleId,
1713
isTrainScheduleId,
1814
} from 'utils/trainId';
1915

@@ -44,55 +40,15 @@ export default class TrainTrackProjectionLazyLoader extends TrainProjectionLazyL
4440
async processBatch(batch: TimetableItemId[]) {
4541
const { infraId, path, electricalProfileSetId } = this.options;
4642

47-
const rawTrainScheduleIds = [];
4843
const rawPacedTrainIds = [];
4944
for (const id of batch) {
5045
if (isTrainScheduleId(id)) {
51-
rawTrainScheduleIds.push(extractEditoastIdFromTrainScheduleId(id));
46+
throw new Error('TrainSchedules are not handled anymore.');
5247
} else {
5348
rawPacedTrainIds.push(extractEditoastIdFromPacedTrainId(id));
5449
}
5550
}
5651

57-
let trainSchedulePromise: Promise<PostTrainScheduleProjectPathApiResponse> = Promise.resolve(
58-
{}
59-
);
60-
let trainScheduleOccupancyBlocksPromise: Promise<PostTrainScheduleOccupancyBlocksApiResponse> =
61-
Promise.resolve({});
62-
if (rawTrainScheduleIds.length > 0) {
63-
trainSchedulePromise = this.options
64-
.dispatch(
65-
osrdEditoastApi.endpoints.postTrainScheduleProjectPath.initiate(
66-
{
67-
projectPathForm: {
68-
infra_id: infraId,
69-
track_section_ranges: path.track_section_ranges,
70-
ids: rawTrainScheduleIds,
71-
electrical_profile_set_id: electricalProfileSetId,
72-
},
73-
},
74-
{ subscribe: false }
75-
)
76-
)
77-
.unwrap();
78-
79-
trainScheduleOccupancyBlocksPromise = this.options
80-
.dispatch(
81-
osrdEditoastApi.endpoints.postTrainScheduleOccupancyBlocks.initiate(
82-
{
83-
occupancyBlockForm: {
84-
infra_id: infraId,
85-
path,
86-
ids: rawTrainScheduleIds,
87-
electrical_profile_set_id: electricalProfileSetId,
88-
},
89-
},
90-
{ subscribe: false }
91-
)
92-
)
93-
.unwrap();
94-
}
95-
9652
let pacedTrainPromise: Promise<PostPacedTrainProjectPathApiResponse> = Promise.resolve({});
9753
let pacedTrainOccupancyBlocksPromise: Promise<PostPacedTrainOccupancyBlocksApiResponse> =
9854
Promise.resolve({});
@@ -130,9 +86,7 @@ export default class TrainTrackProjectionLazyLoader extends TrainProjectionLazyL
13086
.unwrap();
13187
}
13288

133-
const rawTrainScheduleResults = await trainSchedulePromise;
13489
const rawPacedTrainResults = await pacedTrainPromise;
135-
const rawTrainScheduleOccupancyBlocks = await trainScheduleOccupancyBlocksPromise;
13690
const rawPacedTrainOccupancyBlocks = await pacedTrainOccupancyBlocksPromise;
13791

13892
if (this.cancelled) {
@@ -141,14 +95,6 @@ export default class TrainTrackProjectionLazyLoader extends TrainProjectionLazyL
14195

14296
const rawResults = new Map<TimetableItemId, ProjectionResult>();
14397

144-
for (const [id, result] of Object.entries(rawTrainScheduleResults)) {
145-
const trainScheduleId = formatEditoastIdToTrainScheduleId(Number(id));
146-
rawResults.set(trainScheduleId, {
147-
space_time_curves: result,
148-
signal_updates: rawTrainScheduleOccupancyBlocks[id],
149-
});
150-
}
151-
15298
for (const [id, result] of Object.entries(rawPacedTrainResults)) {
15399
const pacedTrainId = formatEditoastIdToPacedTrainId(Number(id));
154100
const pacedTrainProjectionResult: ProjectionResult = {

front/src/applications/operationalStudies/hooks/useLazySimulateTrains.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@ import { useRef, useEffect, useCallback, useState } from 'react';
33
import type {
44
LightRollingStockWithLiveries,
55
PacedTrainSimulationSummaryResult,
6-
SimulationSummaryResult,
76
} from 'common/api/osrdEditoastApi';
87
import formatTimetableItemSummaries from 'modules/simulationResult/helpers/formatTimetableItemSummaries';
98
import type { TimetableItemWithDetails } from 'modules/timetableItem/types';
10-
import type {
11-
TimetableItemId,
12-
TimetableItem,
13-
TrainScheduleId,
14-
PacedTrainId,
15-
} from 'reducers/osrdconf/types';
9+
import type { TimetableItemId, TimetableItem, PacedTrainId } from 'reducers/osrdconf/types';
1610
import { useAppDispatch } from 'store';
1711

1812
import TrainSimulationLazyLoader from '../helpers/TrainSimulationLazyLoader';
@@ -62,12 +56,8 @@ export default function useLazySimulateTrains({
6256
dispatch,
6357
infraId,
6458
electricalProfileSetId,
65-
onProgress: (
66-
trainScheduleSummaries: Map<TrainScheduleId, SimulationSummaryResult>,
67-
pacedTrainSummaries: Map<PacedTrainId, PacedTrainSimulationSummaryResult>
68-
) => {
59+
onProgress: (pacedTrainSummaries: Map<PacedTrainId, PacedTrainSimulationSummaryResult>) => {
6960
const summaries = formatTimetableItemSummaries(
70-
trainScheduleSummaries,
7161
pacedTrainSummaries,
7262
timetableItemsByIdRef.current,
7363
rollingStocks

front/src/applications/operationalStudies/hooks/usePathProjection.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { useAppDispatch } from 'store';
2424
import { formatUicToCi } from 'utils/strings';
2525
import {
2626
extractEditoastIdFromPacedTrainId,
27-
extractEditoastIdFromTrainScheduleId,
2827
extractPacedTrainIdFromOccurrenceId,
2928
isOccurrenceId,
3029
isPacedTrainId,
@@ -113,12 +112,11 @@ const usePathProjection = (
113112
const projectionType = useSelector(getProjectionType);
114113
const dispatch = useAppDispatch();
115114

116-
let rawTrainScheduleId: number | undefined;
117115
let rawPacedTrainId: number | undefined;
118116
let exceptionKey: string | undefined;
119117
if (trainIdUsedForProjection) {
120118
if (isTrainScheduleId(trainIdUsedForProjection)) {
121-
rawTrainScheduleId = extractEditoastIdFromTrainScheduleId(trainIdUsedForProjection);
119+
throw new Error('TrainSchedules are not handled anymore.');
122120
} else if (isPacedTrainId(trainIdUsedForProjection)) {
123121
rawPacedTrainId = extractEditoastIdFromPacedTrainId(trainIdUsedForProjection);
124122
} else {
@@ -131,18 +129,13 @@ const usePathProjection = (
131129
}
132130
}
133131

134-
const scheduleArg = rawTrainScheduleId ? { id: rawTrainScheduleId, infraId } : skipToken;
135132
const pacedArg = rawPacedTrainId ? { id: rawPacedTrainId, infraId, exceptionKey } : skipToken;
136133
const basePacedArg = exceptionKey ? { id: rawPacedTrainId!, infraId } : skipToken;
137134

138-
const { data: schedulePath } =
139-
osrdEditoastApi.endpoints.getTrainScheduleByIdPath.useQuery(scheduleArg);
140-
const { data: pacedPath } = osrdEditoastApi.endpoints.getPacedTrainByIdPath.useQuery(pacedArg);
135+
const { data: pathfinding } = osrdEditoastApi.endpoints.getPacedTrainByIdPath.useQuery(pacedArg);
141136
const { currentData: basePacedPath } =
142137
osrdEditoastApi.endpoints.getPacedTrainByIdPath.useQuery(basePacedArg);
143138

144-
const pathfinding = rawTrainScheduleId ? schedulePath : pacedPath;
145-
146139
const { data: pathProperties } =
147140
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useQuery(
148141
pathfinding?.status === 'success'
@@ -153,7 +146,7 @@ const usePathProjection = (
153146
: skipToken
154147
);
155148

156-
const projectingOnSimulatedPathException = pathfindingResultsDiffer(basePacedPath, pacedPath);
149+
const projectingOnSimulatedPathException = pathfindingResultsDiffer(basePacedPath, pathfinding);
157150

158151
const pathUsedForProjection = useMemo(() => {
159152
if (!trainIdUsedForProjection) return undefined;

0 commit comments

Comments
 (0)