Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function upsertMapWaypointsInOperationalPoints(
...baseFormattedStep,
waypointId: step.id,
opId: null,
location,
}
: {
...baseFormattedStep,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const createVirtualOp = (
weight,
country_code: '??',
is_passenger_station: false,
opRef,
};
};

Expand Down Expand Up @@ -207,7 +208,10 @@ const usePathProjection = (
pathfinding,
path: pathUsedForProjection,
geometry: pathProperties.geometry,
operationalPoints,
operationalPoints: operationalPoints.map((op, index) => ({
...op,
opRef: pathfindingOpRefs[index],
})),
operationalPointReferences: pathfindingOpRefs,
projectingOnSimulatedPathException,
operationalPointDistances,
Expand Down Expand Up @@ -245,6 +249,7 @@ const usePathProjection = (
secondary_code: matchedOp.secondary_code,
uic: matchedOp.uic,
weight,
opRef,
});
} else {
// NOT MATCHED: Point doesn't exist in infrastructure (e.g., NGE point)
Expand Down
4 changes: 3 additions & 1 deletion front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ export type ItineraryPathProperties = PathProperties & {
export type PathProjectionResultOperationalPoint = Omit<
PathProperties['operational_points'][number],
'part'
>;
> & {
opRef: OperationalPointReference;
};

export type PathProjectionResult = {
path: PathItem[];
Expand Down
4 changes: 4 additions & 0 deletions front/src/applications/stdcm/utils/fetchPathProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ const fetchPathProperties = async (
...omit(op, 'id'),
waypointId: `${op.id}-${op.position}-${index}`,
opId: op.id,
location: {
type: 'operational_point_part_reference' as const,
operational_point: { type: 'id' as const, operational_point: op.id },
},
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ const useGetProjectedTrainOperationalPoints = ({
const getOperationalPoints = async () => {
let operationalPointsWithUniqueIds: PathOperationalPoint[] =
projectedOperationalPoints?.map((op, i) => ({
...omit(op, 'id'),
...omit(op, ['id', 'opRef']),
waypointId: `${op.id}-${op.position}-${i}`,
opId: op.id,
location: {
type: 'operational_point_part_reference' as const,
operational_point: op.opRef,
},
})) || [];

operationalPointsWithUniqueIds =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,10 @@ function extractStationLabel(
return stationLabel.label;
}

function getOperationalPointReference(
function getTrackOccupancyOperationalPointReference(
op: PathOperationalPoint | undefined
): OperationalPointReference | undefined {
if (!op) return undefined;
// Normalize empty string ch to null — virtual OPs store ch as '' when the original
// secondary_code was null (see usePathProjection createVirtualOp), and passing ''
// to the backend would filter for OPs with an empty secondary_code rather than any.
const secondaryCode = op.secondary_code || null;
const mainCode = op.main_code;
if (mainCode) return { type: 'trigram', trigram: mainCode, secondary_code: secondaryCode };
const uic = op.uic;
if (uic) return { type: 'uic', uic, secondary_code: secondaryCode };
// Only use the opId when it refers to a real infra OP. Virtual OPs (unrecognised, created
// by usePathProjection when pathfinding fails) have a synthetic id like "virtual_op_Zürich"
if (op.opId && !op.opId.startsWith('virtual_op'))
return { type: 'id', operational_point: op.opId };
return undefined;
return op && op.location.type !== 'track_offset' ? op.location.operational_point : undefined;
}

/**
Expand Down Expand Up @@ -383,7 +370,7 @@ const useTrackOccupancy = ({
Array.from(trainScheduleProjectionsById.keys()),
(ids) =>
fetchTrackOccupancy(
getOperationalPointReference(waypoint),
getTrackOccupancyOperationalPointReference(waypoint),
waypointId,
Object.fromEntries(ids.map((id) => [id, trainScheduleProjectionsById.get(id)!]))
),
Expand Down Expand Up @@ -431,7 +418,9 @@ const useTrackOccupancy = ({

// refresh zones when reopening waypoint, if TOD was closed.
if (!currentSelected && newSelected) {
const opRef = getOperationalPointReference(pathOpsByWaypointId.get(waypointId));
const opRef = getTrackOccupancyOperationalPointReference(
pathOpsByWaypointId.get(waypointId)
);
if (!opRef) return;

const trains = Object.fromEntries(Array.from(trainScheduleProjectionsById.entries()));
Expand Down Expand Up @@ -505,7 +494,7 @@ const useTrackOccupancy = ({
await Promise.all(
[...impactedPathOperationalPointIDs].map(async (waypointId) => {
const newZones = await fetchTrackOccupancy(
getOperationalPointReference(pathOpsByWaypointId.get(waypointId)),
getTrackOccupancyOperationalPointReference(pathOpsByWaypointId.get(waypointId)),
waypointId,
{
[draggedTrainId]: newTrainData,
Expand Down Expand Up @@ -611,7 +600,7 @@ const useTrackOccupancy = ({
waypointId: string;
reference: OperationalPointReference;
}>((op) => {
const reference = getOperationalPointReference(op);
const reference = getTrackOccupancyOperationalPointReference(op);
if (!reference) return [];
return [{ waypointId: op.waypointId, reference }];
});
Expand Down Expand Up @@ -678,7 +667,7 @@ const useTrackOccupancy = ({
if (addedTrainIDs.size || modifiedTrainIDs.size) {
forEach(pathOperationalPointsState, async (_, waypointId) => {
const newZones = await fetchTrackOccupancy(
getOperationalPointReference(pathOpsByWaypointId.get(waypointId)),
getTrackOccupancyOperationalPointReference(pathOpsByWaypointId.get(waypointId)),
waypointId,
Object.fromEntries(
[...addedTrainIDs, ...modifiedTrainIDs].map((id) => [
Expand Down
2 changes: 2 additions & 0 deletions front/src/modules/simulationResult/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
import type {
PacedTrainException,
CoreSignalUpdate,
PathItemLocation,
PathProperties,
RollingStockWithLiveries,
SimulationResponseSuccess,
Expand Down Expand Up @@ -37,6 +38,7 @@ export type EditoastPathOperationalPoint = NonNullable<
export type PathOperationalPoint = Omit<EditoastPathOperationalPoint, 'id' | 'part'> & {
waypointId: string;
opId: string | null;
location: PathItemLocation;
};

// Space Time Chart
Expand Down
Loading