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: implement results in the new interface for one simulation #7815

Merged
merged 1 commit into from
Jul 11, 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
10 changes: 10 additions & 0 deletions front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
"pathfindingFailed": "No path have been found for these waypoints.",
"pleaseWait": "Please wait…",
"simulation":{
"available": "Simulation available",
"averageRequestTime": "For your request, the time required is generally 90 seconds.",
"calculatingSimulation": "Calculation in progress...",
"getSimulation": "Get the simulation",
"pendingSimulation": "Simulation in progress",
"results":{
"displayAll": "Display all operational points",
"displayMain": "Display main operational points",
"downloadSimulationSheet": "Download simulation report sheet",
"gesicoRequest":"and attach this document to your GESICO DSDM request.",
"selectThisSimulation": "Select this simulation",
"simulationNumber": "Simulation n°1",
"simulationSelected": "You have selected this simulation"
},
"stopCalculation" : "Stop calculation"
},
"spaceSpeedGraphic": "Space-Velocity graph",
Expand Down
10 changes: 10 additions & 0 deletions front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
"pathfindingFailed": "Aucun chemin n'a été trouvé pour ces points de jalonnement.",
"pleaseWait": "Veuillez patientez…",
"simulation":{
"available": "Simulation disponible",
"averageRequestTime": "Pour votre demande, le temps nécessaire est généralement de 90 secondes.",
"calculatingSimulation": "Calcul en cours...",
"getSimulation": "Obtenir la simulation",
"pendingSimulation": "simulation en cours",
"results":{
"displayAll": "Afficher tous les jalons",
"displayMain": "Afficher les jalons principaux",
"downloadSimulationSheet": "Télécharger la fiche de simulation",
"gesicoRequest":"et joignez ce document à votre demande GESICO DSDM",
"selectThisSimulation": "Retenir cette simulation",
"simulationNumber": "Simulation n°1",
"simulationSelected": "Vous avez retenu cette simulation"
},
"stopCalculation" : "Arrêter le calcul"
},
"spaceSpeedGraphic": "Graphique Espace-Vitesse",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,18 @@ import { formatDateToString, formatDayV2 } from 'utils/date';

import styles from './SimulationReportStyleSheet';
import type { SimulationReportSheetProps } from '../types';
import { extractSpeedLimit, getStopDurationTime, getOperationalPointsWithTimes } from '../utils';
import { extractSpeedLimit, getStopDurationTime } from '../utils';

const SimulationReportSheetV2 = ({
stdcmData,
pathProperties,
rollingStockData,
speedLimitByTag,
simulationReportSheetNumber,
mapCanvas,
creationDate,
operationalPointsList,
}: SimulationReportSheetProps) => {
const { t } = useTranslation('stdcm-simulation-report-sheet');
let renderedIndex = 0;

clarani marked this conversation as resolved.
Show resolved Hide resolved
const date = creationDate && t('formattedDate', formatDateToString(creationDate));
const { rollingStock, speedLimitByTag, departure_time: departureTime, creationDate } = stdcmData;

// TODO: Add RC information when it becomes avalaible, until that, we use fake ones
const fakeInformation = {
Expand All @@ -36,18 +33,6 @@ const SimulationReportSheetV2 = ({
path_number2: 'n°YYYYYY',
};

const simulationReport: SimulationReportSheetProps = {
stdcmData,
pathProperties,
rollingStockData,
speedLimitByTag,
simulationReportSheetNumber,
mapCanvas,
creationDate,
};

const opList = getOperationalPointsWithTimes(simulationReport);

return (
<Document>
<Page wrap={false} style={styles.main.page} size={[1344]}>
Expand All @@ -68,7 +53,9 @@ const SimulationReportSheetV2 = ({
{simulationReportSheetNumber}
</Text>
<Text style={styles.header.creationDate}>{date}</Text>
<Text style={styles.header.creationDate}>
{t('formattedDate', formatDateToString(creationDate))}
</Text>
</View>
<Image src={logoSNCF} style={styles.header.sncfLogo} />
</View>
Expand All @@ -85,7 +72,7 @@ const SimulationReportSheetV2 = ({
<View style={styles.rcInfo.rcBox}>
<View style={styles.rcInfo.stdcmApplication}>
<Text style={styles.rcInfo.applicationDate}>{t('applicationDate')}</Text>
<Text style={styles.rcInfo.date}>{formatDayV2(stdcmData.departure_time)}</Text>
<Text style={styles.rcInfo.date}>{formatDayV2(departureTime)}</Text>
<Text style={styles.rcInfo.referencePath}>{t('referencePath')}</Text>
<Text style={styles.rcInfo.pathNumber}>{fakeInformation.path_number1}</Text>
</View>
Expand All @@ -104,22 +91,22 @@ const SimulationReportSheetV2 = ({
<Text style={styles.convoyAndRoute.convoyInfoData}>-</Text>
<Text style={styles.convoyAndRoute.convoyInfoTitles}>{t('maxSpeed')}</Text>
<Text style={styles.convoyAndRoute.convoyInfoData}>
{`${Math.floor(rollingStockData.max_speed * 3.6)} km/h`}
{`${Math.floor(rollingStock.max_speed * 3.6)} km/h`}
</Text>
</View>
<View style={styles.convoyAndRoute.convoyInfoBox2}>
<Text style={styles.convoyAndRoute.convoyInfoTitles}>{t('maxWeight')}</Text>
<Text style={styles.convoyAndRoute.convoyInfoData}>
{`${Math.floor(rollingStockData.mass / 1000)} t`}
{`${Math.floor(rollingStock.mass / 1000)} t`}
</Text>
<Text style={styles.convoyAndRoute.convoyInfoTitles}>{t('referenceEngine')}</Text>
<Text style={styles.convoyAndRoute.convoyInfoData}>
{rollingStockData.metadata?.reference || '-'}
{rollingStock.metadata?.reference || '-'}
</Text>
<Text style={styles.convoyAndRoute.convoyInfoTitles}>{t('maxLength')}</Text>
<Text
style={styles.convoyAndRoute.convoyInfoData}
>{`${rollingStockData.length} m`}</Text>
>{`${rollingStock.length} m`}</Text>
</View>
</View>
</View>
Expand Down Expand Up @@ -155,9 +142,9 @@ const SimulationReportSheetV2 = ({
<TD>{t('motif')}</TD>
</View>
</TH>
{opList.map((step, index) => {
{operationalPointsList.map((step, index) => {
const isFirstStep = index === 0;
const isLastStep = index === opList.length - 1;
const isLastStep = index === operationalPointsList.length - 1;
const shouldRenderRow = isFirstStep || step.duration > 0 || isLastStep;
if (shouldRenderRow) {
renderedIndex += 1;
Expand All @@ -183,7 +170,7 @@ const SimulationReportSheetV2 = ({
</View>
<View style={styles.convoyAndRoute.stopTableStartWidth}>
<TD style={styles.convoyAndRoute.stopTableStartColumn}>
{isFirstStep ? step.departureTime : ''}
{isFirstStep ? step.stopEndTime : ''}
</TD>
</View>
<View style={styles.convoyAndRoute.stopTableMotifWidth}>
Expand Down Expand Up @@ -259,10 +246,10 @@ const SimulationReportSheetV2 = ({
<TD>{t('crossedATE')}</TD>
</View>
</TH>
{opList.map((step, index) => {
{operationalPointsList.map((step, index) => {
const isFirstStep = index === 0;
const isLastStep = index === opList.length - 1;
const prevStep = opList[index - 1];
const isLastStep = index === operationalPointsList.length - 1;
const prevStep = operationalPointsList[index - 1];
return (
<TR
key={index}
Expand Down Expand Up @@ -328,12 +315,12 @@ const SimulationReportSheetV2 = ({
</View>
<View style={styles.simulation.weightWidth}>
<TD style={styles.simulation.td}>
{!isFirstStep ? '=' : `${Math.floor(rollingStockData.mass / 1000)} t`}
{!isFirstStep ? '=' : `${Math.floor(rollingStock.mass / 1000)} t`}
</TD>
</View>
<View style={styles.simulation.refEngineWidth}>
<TD style={styles.simulation.td}>
{!isFirstStep ? '=' : rollingStockData.metadata?.reference}
{!isFirstStep ? '=' : rollingStock.metadata?.reference}
</TD>
</View>
<View style={styles.simulation.convSignWidth}>
Expand All @@ -349,9 +336,11 @@ const SimulationReportSheetV2 = ({
<View style={styles.simulation.horizontalBar} />
</View>
</View>
<View style={styles.map.map} id="simulationMap">
<Image src={mapCanvas} />
</View>
{mapCanvas && (
<View style={styles.map.map} id="simulationMap">
<Image src={mapCanvas} />
</View>
)}
<View style={styles.footer.warrantyBox}>
<Text style={styles.footer.warrantyMessage}>{t('withoutWarranty')}</Text>
</View>
Expand Down
8 changes: 8 additions & 0 deletions front/src/applications/stdcm/hooks/useStdcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
TrainScheduleResult,
} from 'common/api/osrdEditoastApi';
import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import { useStoreDataForSpeedLimitByTagSelector } from 'common/SpeedLimitByTagSelector/useStoreDataForSpeedLimitByTagSelector';
import createTrain from 'modules/simulationResult/components/SpaceTimeChart/createTrain';
import { CHART_AXES } from 'modules/simulationResult/consts';
import { setFailure } from 'reducers/main';
Expand Down Expand Up @@ -76,6 +77,8 @@ const useStdcm = () => {

const { timetableID } = osrdconf;

const { speedLimitByTag } = useStoreDataForSpeedLimitByTagSelector();

const resetResults = () => {
dispatch(updateSelectedTrainId(undefined));
dispatch(updateConsolidatedSimulation([]));
Expand Down Expand Up @@ -160,6 +163,8 @@ const useStdcm = () => {
setStdcmV2Response({
...response,
rollingStock: stdcmRollingStock,
creationDate: new Date(),
speedLimitByTag,
} as StdcmV2SuccessResponse);

const stdcmTrain: TrainScheduleResult = {
Expand Down Expand Up @@ -213,6 +218,8 @@ const useStdcm = () => {
dispatch(updateSimulation(emptySimulation));
};

const isPending = currentStdcmRequestStatus === STDCM_REQUEST_STATUS.pending;

return {
stdcmResults,
stdcmV2Results,
Expand All @@ -221,6 +228,7 @@ const useStdcm = () => {
cancelStdcmRequest,
pathProperties,
setPathProperties,
isPending,
};
};

Expand Down
23 changes: 18 additions & 5 deletions front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {
ManageTrainSchedulePathProperties,
PathPropertiesFormatted,
TrainSpaceTimeData,
} from 'applications/operationalStudies/types';
Expand All @@ -22,16 +21,30 @@ export type StdcmV2SuccessResponse = Omit<
> & {
simulation: Extract<SimulationResponse, { status: 'success' }>;
rollingStock: LightRollingStock;
creationDate: Date;
speedLimitByTag?: string;
};

export type SimulationReportSheetProps = {
stdcmData: StdcmV2SuccessResponse;
pathProperties?: ManageTrainSchedulePathProperties;
rollingStockData: RollingStockWithLiveries;
speedLimitByTag?: string;
simulationReportSheetNumber: string;
mapCanvas?: string;
creationDate?: Date;
operationalPointsList: StdcmResultsOperationalPointsList;
};

export type StdcmResultsOperationalPointsList = StdcmResultsOperationalPoint[];

type StdcmResultsOperationalPoint = {
opId: string;
positionOnPath: number;
time: string | null;
name?: string;
ch?: string;
stop?: string | null;
duration: number;
departureTime: string;
stopEndTime: string;
trackName?: string;
};

export type StdcmV2Results = {
Expand Down
31 changes: 11 additions & 20 deletions front/src/applications/stdcm/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { SimulationReportSheetProps } from './types';
import type { SimulationResponse } from 'common/api/generatedEditoastApi';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';

import type { StdcmResultsOperationalPointsList } from './types';

function generateRandomString(length: number): string {
return Array.from({ length }, () => Math.floor(Math.random() * 10)).join('');
Expand Down Expand Up @@ -112,28 +115,16 @@ const getStopDurationBetweenToPositions = (
return null;
};

export function getOperationalPointsWithTimes(simulationReport: SimulationReportSheetProps): {
opId: string;
positionOnPath: number;
time: string | null;
name: string | undefined;
ch: string | undefined;
stop: string | null | undefined;
duration: number;
departureTime: string;
stopEndTime: string;
trackName: string | undefined;
}[] {
const operationalPoints = simulationReport.pathProperties?.suggestedOperationalPoints || [];
const { simulation } = simulationReport.stdcmData;

export function getOperationalPointsWithTimes(
operationalPoints: SuggestedOP[],
simulation: Extract<SimulationResponse, { status: 'success' }>,
departureTime: string
): StdcmResultsOperationalPointsList {
const { positions, times } = simulation.final_output;
const departureTime = new Date(simulationReport.stdcmData.departure_time)
.toLocaleTimeString()
.substring(0, 5);
const pathDepartureTime = new Date(departureTime).toLocaleTimeString().substring(0, 5);

// Parse departure time into hours and minutes
const [departureHour, departureMinute] = departureTime.split(':').map(Number);
const [departureHour, departureMinute] = pathDepartureTime.split(':').map(Number);

// Map operational points with their positions, times, and stop durations
const opResults = operationalPoints.map((op) => {
Expand Down
7 changes: 0 additions & 7 deletions front/src/applications/stdcm/views/StdcmConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ const StdcmConfig = ({
);
}, [infra, osrdconf, originV2, destinationV2]);

const [creationDate, setCreationDate] = useState<Date>();

const handleClick = () => {
const currentDateTime = new Date();
setCreationDate(currentDateTime);
launchStdcmRequest();
};

Expand Down Expand Up @@ -212,9 +208,6 @@ const StdcmConfig = ({
mapCanvas={mapCanvas}
stdcmV2Results={stdcmV2Results}
pathProperties={pathProperties}
rollingStockData={rollingStock}
speedLimitByTag={speedLimitByTag}
creationDate={creationDate}
/>
)}
</div>
Expand Down
Loading
Loading