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: bump osrd-ui to use the new manchette props #9507

Merged
merged 2 commits into from
Nov 18, 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
12 changes: 6 additions & 6 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"@nivo/line": "^0.80.0",
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
"@osrd-project/netzgrafik-frontend": "0.0.0-snapshot.6d049b7244241254c33afc3818f40ec57ab57217",
"@osrd-project/ui-core": "^0.0.52",
"@osrd-project/ui-icons": "^0.0.52",
"@osrd-project/ui-manchette": "^0.0.52",
"@osrd-project/ui-manchette-with-spacetimechart": "^0.0.52",
"@osrd-project/ui-spacetimechart": "^0.0.52",
"@osrd-project/ui-speedspacechart": "^0.0.52",
"@osrd-project/ui-core": "^0.0.53",
"@osrd-project/ui-icons": "^0.0.53",
"@osrd-project/ui-manchette": "^0.0.53",
"@osrd-project/ui-manchette-with-spacetimechart": "^0.0.53",
"@osrd-project/ui-spacetimechart": "^0.0.53",
"@osrd-project/ui-speedspacechart": "^0.0.53",
"@react-pdf/renderer": "^3.4.2",
"@redux-devtools/extension": "^3.3.0",
"@reduxjs/toolkit": "^2.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ const upsertNewProjectedTrains = (

const matchingTrain = trainSchedulesById.get(trainId);
const projectedTrain = {
...trainData,
id: +trainId,
name: matchingTrain?.train_name || 'Train name not found',
departure_time: trainData.departure_time,
departureTime: new Date(trainData.departure_time),
spaceTimeCurves: trainData.space_time_curves,
signalUpdates: trainData.signal_updates,
};

newProjectedTrains.set(trainId, projectedTrain);
Expand Down
8 changes: 7 additions & 1 deletion front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,16 @@ export type ManageTrainSchedulePathProperties = {
/**
* Properties signal_updates time_end and time_start are in seconds taking count of the departure time
*/
// TODO: reuse the type from osrd-ui/ui-manchette
export type TrainSpaceTimeData = {
id: number;
name: string;
} & ProjectPathTrainResult;
spaceTimeCurves: {
positions: number[];
times: number[];
}[];
departureTime: Date;
} & { signalUpdates: ProjectPathTrainResult['signal_updates'] };

export type PositionData<T extends 'gradient' | 'radius'> = {
[key in T]: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ const useProjectedTrainsForStdcm = (stdcmResponse?: StdcmSuccessResponse) => {
});

useEffect(() => {
const projectedTimetableTrains = Array.from(projectedTimetableTrainsById.values());
const newSpaceTimeData = projectedTimetableTrains.filter(
(projectedTrain) => projectedTrain.space_time_curves.length > 0
);
const newSpaceTimeData = Array.from(projectedTimetableTrainsById.values());

if (stdcmProjectedTrain) {
newSpaceTimeData.push(stdcmProjectedTrain);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import type { ProjectPathTrainResult } from 'common/api/osrdEditoastApi';
import type { TrainSpaceTimeData } from 'applications/operationalStudies/types';

SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
import { STDCM_TRAIN_ID } from '../consts';
import type { StdcmSuccessResponse } from '../types';

const formatStdcmTrainIntoSpaceTimeData = (
stdcmResponse: StdcmSuccessResponse
): ProjectPathTrainResult & { id: number; name: string } => {
const { simulation, rollingStock, departure_time } = stdcmResponse;
): TrainSpaceTimeData => {
const { simulation, departure_time } = stdcmResponse;
return {
id: STDCM_TRAIN_ID,
name: 'stdcm',
space_time_curves: [
spaceTimeCurves: [
{
times: simulation.final_output.times,
positions: simulation.final_output.positions,
},
],
signal_updates: [],
rolling_stock_length: rollingStock.length,
departure_time,
signalUpdates: [],
departureTime: new Date(departure_time),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,90 +52,101 @@ const ManchetteWithSpaceTimeChartWrapper = ({
const [waypointsPanelIsOpen, setWaypointsPanelIsOpen] = useState(false);

// Cut the space time chart curves if the first or last waypoints are hidden
const spaceTimeChartLayersData = useMemo(() => {
let filteredProjectPathTrainResult = projectPathTrainResult;
let filteredConflicts = conflicts;

if (!waypointsPanelData || waypointsPanelData.filteredWaypoints.length < 2)
return { filteredProjectPathTrainResult, filteredConflicts };

const { filteredWaypoints } = waypointsPanelData;
const firstPosition = filteredWaypoints.at(0)!.position;
const lastPosition = filteredWaypoints.at(-1)!.position;

if (firstPosition !== 0 || lastPosition !== operationalPoints.at(-1)!.position) {
filteredProjectPathTrainResult = projectPathTrainResult.map((train) => ({
...train,
space_time_curves: train.space_time_curves.map(({ positions, times }) => {
const cutPositions: number[] = [];
const cutTimes: number[] = [];

for (let i = 1; i < positions.length; i += 1) {
const currentRange: LayerRangeData = {
spaceStart: positions[i - 1],
spaceEnd: positions[i],
timeStart: times[i - 1],
timeEnd: times[i],
};

const interpolatedRange = cutSpaceTimeRect(currentRange, firstPosition, lastPosition);

// TODO : remove reformatting the datas when /~https://github.com/OpenRailAssociation/osrd-ui/issues/694 is merged
if (!interpolatedRange) continue;

if (i === 1 || cutPositions.length === 0) {
cutPositions.push(interpolatedRange.spaceStart);
cutTimes.push(interpolatedRange.timeStart);
const { filteredProjectPathTrainResult: cutProjectedTrains, filteredConflicts: cutConflicts } =
useMemo(() => {
let filteredProjectPathTrainResult = projectPathTrainResult;
let filteredConflicts = conflicts;

if (!waypointsPanelData || waypointsPanelData.filteredWaypoints.length < 2)
return { filteredProjectPathTrainResult, filteredConflicts };

const { filteredWaypoints } = waypointsPanelData;
const firstPosition = filteredWaypoints.at(0)!.position;
const lastPosition = filteredWaypoints.at(-1)!.position;

if (firstPosition !== 0 || lastPosition !== operationalPoints.at(-1)!.position) {
filteredProjectPathTrainResult = projectPathTrainResult.map((train) => ({
...train,
spaceTimeCurves: train.spaceTimeCurves.map(({ positions, times }) => {
const cutPositions: number[] = [];
const cutTimes: number[] = [];

for (let i = 1; i < positions.length; i += 1) {
const currentRange: LayerRangeData = {
spaceStart: positions[i - 1],
spaceEnd: positions[i],
timeStart: times[i - 1],
timeEnd: times[i],
};

const interpolatedRange = cutSpaceTimeRect(currentRange, firstPosition, lastPosition);

// TODO : remove reformatting the datas when /~https://github.com/OpenRailAssociation/osrd-ui/issues/694 is merged
if (!interpolatedRange) continue;

if (i === 1 || cutPositions.length === 0) {
cutPositions.push(interpolatedRange.spaceStart);
cutTimes.push(interpolatedRange.timeStart);
}
cutPositions.push(interpolatedRange.spaceEnd);
cutTimes.push(interpolatedRange.timeEnd);
}
cutPositions.push(interpolatedRange.spaceEnd);
cutTimes.push(interpolatedRange.timeEnd);
}

return {
positions: cutPositions,
times: cutTimes,
};
}),
signal_updates: compact(
train.signal_updates.map((signal) => {
const updatedSignalRange = cutSpaceTimeRect(
{
spaceStart: signal.position_start,
spaceEnd: signal.position_end,
timeStart: signal.time_start,
timeEnd: signal.time_end,
},
firstPosition,
lastPosition
);

if (!updatedSignalRange) return null;

// TODO : remove reformatting the datas when /~https://github.com/OpenRailAssociation/osrd-ui/issues/694 is merged

return {
...signal,
position_start: updatedSignalRange.spaceStart,
position_end: updatedSignalRange.spaceEnd,
time_start: updatedSignalRange.timeStart,
time_end: updatedSignalRange.timeEnd,
positions: cutPositions,
times: cutTimes,
};
})
),
}));

filteredConflicts = compact(
conflicts.map((conflict) => cutSpaceTimeRect(conflict, firstPosition, lastPosition))
);
}),
signalUpdates: compact(
train.signalUpdates.map((signal) => {
const updatedSignalRange = cutSpaceTimeRect(
{
spaceStart: signal.position_start,
spaceEnd: signal.position_end,
timeStart: signal.time_start,
timeEnd: signal.time_end,
},
firstPosition,
lastPosition
);

if (!updatedSignalRange) return null;

// TODO : remove reformatting the datas when /~https://github.com/OpenRailAssociation/osrd-ui/issues/694 is merged
return {
...signal,
position_start: updatedSignalRange.spaceStart,
position_end: updatedSignalRange.spaceEnd,
time_start: updatedSignalRange.timeStart,
time_end: updatedSignalRange.timeEnd,
};
})
),
}));

filteredConflicts = compact(
conflicts.map((conflict) => cutSpaceTimeRect(conflict, firstPosition, lastPosition))
);

return { filteredProjectPathTrainResult, filteredConflicts };
}

return { filteredProjectPathTrainResult, filteredConflicts };
}

return { filteredProjectPathTrainResult, filteredConflicts };
}, [waypointsPanelData?.filteredWaypoints, projectPathTrainResult, conflicts]);
}, [waypointsPanelData?.filteredWaypoints, projectPathTrainResult, conflicts]);

const manchetteWaypoints = useMemo(() => {
const rawWaypoints = waypointsPanelData?.filteredWaypoints ?? operationalPoints;
return rawWaypoints.map((waypoint) => ({
id: waypoint.id,
position: waypoint.position,
name: waypoint.extensions?.identifier?.name,
secondaryCode: waypoint.extensions?.sncf?.ch,
}));
}, [waypointsPanelData, operationalPoints]);

const { manchetteProps, spaceTimeChartProps, handleScroll } = useManchettesWithSpaceTimeChart(
waypointsPanelData?.filteredWaypoints ?? operationalPoints,
spaceTimeChartLayersData.filteredProjectPathTrainResult,
manchetteWaypoints,
cutProjectedTrains,
SharglutDev marked this conversation as resolved.
Show resolved Hide resolved
manchetteWithSpaceTimeChartRef,
selectedTrainScheduleId
);
Expand All @@ -146,19 +157,17 @@ const ManchetteWithSpaceTimeChartWrapper = ({
showSignalsStates: false,
});

const occupancyBlocks = spaceTimeChartLayersData.filteredProjectPathTrainResult.flatMap(
(train) => {
const departureTime = new Date(train.departure_time).getTime();

return train.signal_updates.map((block) => ({
timeStart: departureTime + block.time_start,
timeEnd: departureTime + block.time_end,
spaceStart: block.position_start,
spaceEnd: block.position_end,
color: ASPECT_LABELS_COLORS[block.aspect_label as AspectLabel],
}));
}
);
const occupancyBlocks = cutProjectedTrains.flatMap((train) => {
const departureTime = train.departureTime.getTime();

return train.signalUpdates.map((block) => ({
timeStart: departureTime + block.time_start,
timeEnd: departureTime + block.time_end,
spaceStart: block.position_start,
spaceEnd: block.position_end,
color: ASPECT_LABELS_COLORS[block.aspect_label as AspectLabel],
}));
});

return (
<div className="manchette-space-time-chart-wrapper">
Expand Down Expand Up @@ -207,7 +216,7 @@ const ManchetteWithSpaceTimeChartWrapper = ({
spaceOrigin={
(waypointsPanelData?.filteredWaypoints ?? operationalPoints).at(0)?.position || 0
}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +new Date(p.departure_time)))}
timeOrigin={Math.min(...projectPathTrainResult.map((p) => +p.departureTime))}
{...spaceTimeChartProps}
>
{spaceTimeChartProps.paths.map((path) => (
Expand All @@ -224,9 +233,7 @@ const ManchetteWithSpaceTimeChartWrapper = ({
imageUrl={upward}
/>
)}
{settings.showConflicts && (
<ConflictLayer conflicts={spaceTimeChartLayersData.filteredConflicts} />
)}
{settings.showConflicts && <ConflictLayer conflicts={cutConflicts} />}
{settings.showSignalsStates && (
<OccupancyBlockLayer occupancyBlocks={occupancyBlocks} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useChartSynchronizer } from './ChartSynchronizer';
* @TODO do not work with colors as string as soon as possible
*/
const getOccupancyBounds = (
routeAspects: TrainSpaceTimeData['signal_updates'],
routeAspects: TrainSpaceTimeData['signalUpdates'],
timePosition: Date
): [number, number] => {
// TODO GET v2 : probably remove this conversion as trains will travel on several days
Expand Down Expand Up @@ -59,8 +59,8 @@ const TrainDetails = ({ projectedTrain }: TrainDetailsProps) => {
const { t } = useTranslation(['simulation']);

const occupancyBounds = useMemo(
() => getOccupancyBounds(projectedTrain.signal_updates, new Date(headPosition?.time)),
[projectedTrain.signal_updates, headPosition, tailPosition, speed]
() => getOccupancyBounds(projectedTrain.signalUpdates, new Date(headPosition?.time)),
[projectedTrain.signalUpdates, headPosition, tailPosition, speed]
);

return (
Expand Down
Loading
Loading