Skip to content

Commit

Permalink
front: adapt power restriction tsv2
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainValls authored and clarani committed Jul 11, 2024
1 parent 45b2718 commit bea61b1
Show file tree
Hide file tree
Showing 51 changed files with 1,579 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,11 @@
"electrification": "Electrification",
"inconsistent_one": "The interval below has inconsistencies. The default speed effort curve will be used for this.",
"inconsistent_other": "The intervals below contain inconsistencies. The default speed effort curves will be used for these.",
"powerRestrictionInvalidCombination": "- {{powerRestrictionCode}} is incompatible with electrification {{electrification}} of the path between {{begin}}m and {{end}}m",
"marginsAndPowerRestrictionsReset": "Margins and power restrictions have been reset.",
"missingPowerRestriction": "- Missing power restriction between {{begin}}m and {{end}}m.",
"modeNotHandled": "- No power restriction should be given between {{begin}}m and {{end}}m since the electrification mode {{electrification}} is not handled.",
"pathfindingChange": "Pathfinding changed",
"marginsAndPowerRestrictionsReset": "Margins and power restrictions have been reset."
"powerRestrictionInvalidCombination": "- {{powerRestrictionCode}} is incompatible with electrification {{electrification}} of the path between {{begin}}m and {{end}}m",
"powerRestrictionsReset": "Power restrictions have been reset."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@
"electrification": "Électrification",
"inconsistent_one": "Un intervalle comporte des incohérences. La courbe effort vitesse par défaut sera utilisée pour celui-ci.",
"inconsistent_other": "Plusieurs intervalles comportent des incohérences. Les courbes effort vitesse par défaut seront utilisées pour ceux-ci.",
"powerRestrictionInvalidCombination": "- Code {{powerRestrictionCode}} incompatible avec l'électrification à {{electrification}} de l'itinéraire entre {{begin}}m et {{end}}m. ",
"marginsAndPowerRestrictionsReset": "Les marges et les restrictions de puissance ont été réinitialisées.",
"missingPowerRestriction": "- Restriction de puissance manquante entre {{begin}}m et {{end}}m.",
"modeNotHandled": "- Aucune restriction de puissance ne devrait être renseignée entre {{begin}}m and {{end}}m comme le matériel roulant ne supporte pas l'électrification {{electrification}}.",
"pathfindingChange": "Changement de chemin",
"marginsAndPowerRestrictionsReset": "Les marges et les restrictions de puissance ont été réinitialisées."
"powerRestrictionInvalidCombination": "- Code {{powerRestrictionCode}} incompatible avec l'électrification à {{electrification}} de l'itinéraire entre {{begin}}m et {{end}}m.",
"powerRestrictionsReset": "Les restrictions de puissance ont été réinitialisées."
}
}
1 change: 1 addition & 0 deletions front/src/applications/operationalStudies/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export const useSetupItineraryForTrainUpdate = (
suggestedOperationalPoints,
allWaypoints,
length: pathfindingResult.length,
trackSectionRanges: pathfindingResult.track_section_ranges,
});

adjustConfWithTrainToModifyV2(
Expand Down
18 changes: 15 additions & 3 deletions front/src/applications/operationalStudies/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type {
PathProperties,
PathResponse,
PathfindingResultSuccess,
ProjectPathTrainResult,
RangedValue,
SimulationResponse,
TrainScheduleBase,
} from 'common/api/osrdEditoastApi';
import type { SuggestedOP } from 'modules/trainschedule/components/ManageTrainSchedule/types';
import type { ArrayElement } from 'utils/types';

export interface Destination {
uic: number;
Expand Down Expand Up @@ -89,6 +93,7 @@ export type ManageTrainSchedulePathProperties = {
/** Operational points along the path (including origin and destination) and vias added by clicking on map */
allWaypoints: SuggestedOP[];
length: number;
trackSectionRanges: NonNullable<PathfindingResultSuccess['track_section_ranges']>;
};

/**
Expand All @@ -106,6 +111,7 @@ export type PositionData<T extends 'gradient' | 'radius'> = {
position: number;
};

/** Start and stop are in meters */
export type ElectrificationRangeV2 = {
electrificationUsage: ElectrificationUsageV2;
start: number;
Expand Down Expand Up @@ -143,15 +149,21 @@ export type ElectricalProfileValue = Extract<
{ status: 'success' }
>['electrical_profiles']['values'][number];

/**
* Electrifications start and stop are in meters
*/
/** Electrifications start and stop are in meters */
export type PathPropertiesFormatted = {
electrifications: ElectrificationRangeV2[];
curves: PositionData<'radius'>[];
slopes: PositionData<'gradient'>[];
operationalPoints: NonNullable<PathProperties['operational_points']>;
geometry: NonNullable<PathProperties['geometry']>;
voltages: RangedValue[];
};

export type PowerRestrictionV2 = ArrayElement<TrainScheduleBase['power_restrictions']>;

export type SimulationResponseSuccess = Extract<SimulationResponse, { status: 'success' }>;

export type ElectrificationVoltage = {
type: string;
voltage?: string;
};
7 changes: 7 additions & 0 deletions front/src/applications/operationalStudies/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { omit } from 'lodash';

import type { PathProperties, ProjectPathTrainResult } from 'common/api/osrdEditoastApi';
import getPathVoltages from 'modules/pathfinding/helpers/getPathVoltages';
import { convertUTCDateToLocalDate, isoDateToMs } from 'utils/date';
import { mmToM } from 'utils/physics';
import { ms2sec } from 'utils/timeManipulation';
Expand Down Expand Up @@ -183,12 +184,18 @@ export const preparePathPropertiesData = (
electricalProfilesRanges
);

const voltageRanges = getPathVoltages(
electrifications as NonNullable<PathProperties['electrifications']>,
pathLength
);

return {
electrifications: electrificationRanges,
curves: formattedCurves,
slopes: formattedSlopes,
operationalPoints: operational_points as NonNullable<PathProperties['operational_points']>,
geometry: geometry as NonNullable<PathProperties['geometry']>,
voltages: voltageRanges,
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect, useMemo, useState } from 'react';

import { compact } from 'lodash';
import { useTranslation } from 'react-i18next';
Expand All @@ -13,10 +13,13 @@ import { useOsrdConfSelectors } from 'common/osrdContext';
import { useStoreDataForSpeedLimitByTagSelector } from 'common/SpeedLimitByTagSelector/useStoreDataForSpeedLimitByTagSelector';
import Tabs from 'common/Tabs';
import ItineraryV2 from 'modules/pathfinding/components/Itinerary/ItineraryV2';
import getPathVoltages from 'modules/pathfinding/helpers/getPathVoltages';
import { upsertViasInOPs } from 'modules/pathfinding/utils';
import PowerRestrictionsSelectorV2 from 'modules/powerRestriction/components/PowerRestrictionsSelectorV2';
import RollingStock2Img from 'modules/rollingStock/components/RollingStock2Img';
import { RollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector';
import { useStoreDataForRollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import { isElectric } from 'modules/rollingStock/helpers/electric';
import TimesStops from 'modules/timesStops/TimesStops';
import { Map } from 'modules/trainschedule/components/ManageTrainSchedule';
import SimulationSettings from 'modules/trainschedule/components/ManageTrainSchedule/SimulationSettings';
Expand Down Expand Up @@ -52,16 +55,12 @@ const ManageTrainScheduleV2 = () => {
allWaypoints,
});
}
}, [pathSteps]);
}, []);

// TODO TS2 : test this hook in simulation results issue
// useSetupItineraryForTrainUpdate(setPathProperties);

// const { data: pathWithElectrifications = { electrification_ranges: [] as RangedValue[] } } =
// osrdEditoastApi.endpoints.getPathfindingByPathfindingIdElectrifications.useQuery(
// { pathfindingId: pathFindingID as number },
// { skip: !pathFindingID }
// );
const voltageRanges = useMemo(
() => getPathVoltages(pathProperties?.electrifications, pathProperties?.length),
[pathProperties]
);

const tabRollingStock = {
id: 'rollingstock',
Expand Down Expand Up @@ -151,13 +150,14 @@ const ManageTrainScheduleV2 = () => {
dispatchUpdateSpeedLimitByTag={dispatchUpdateSpeedLimitByTag}
constraintDistribution={constraintDistribution}
/>
{/* {rollingStock && isElectric(rollingStock.effort_curves.modes) && (
{rollingStock && isElectric(rollingStock.effort_curves.modes) && pathProperties && (
<PowerRestrictionsSelectorV2
rollingStockModes={rollingStock.effort_curves.modes}
rollingStockPowerRestrictions={rollingStock.power_restrictions}
pathElectrificationRanges={pathWithElectrifications.electrification_ranges}
voltageRanges={voltageRanges}
pathProperties={pathProperties}
/>
)} */}
)}
</div>
),
};
Expand Down
1 change: 1 addition & 0 deletions front/src/applications/stdcm/hooks/useStdcmResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const useStdcmResults = (
suggestedOperationalPoints: updatedSuggestedOPs,
allWaypoints: updatedSuggestedOPs,
length: path.length,
trackSectionRanges: path.track_section_ranges,
});
}
};
Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/stdcmV2/components/StdcmVias.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfig

const updatePathStepsList = (pathStep: PathStep | null, index: number) => {
const newPathSteps = replaceElementAtIndex(pathSteps, index, pathStep);
dispatch(updatePathSteps(newPathSteps));
dispatch(updatePathSteps({ pathSteps: newPathSteps }));
};

const updatePathStepStopTime = (stopTime: string, index: number) => {
Expand Down Expand Up @@ -95,7 +95,7 @@ const StdcmVias = ({ disabled = false, setCurrentSimulationInputs }: StdcmConfig
Icon={<Location size="lg" variant="base" />}
onClick={() => {
const newPathSteps = addElementAtIndex(pathSteps, pathSteps.length - 1, null);
dispatch(updatePathSteps(newPathSteps));
dispatch(updatePathSteps({ pathSteps: newPathSteps }));
}}
/>
</div>
Expand Down
14 changes: 10 additions & 4 deletions front/src/common/IntervalsDataViz/IntervalItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
segment,
setDraginStartAt,
setResizing,
disableDrag = true,
}: IntervalItemProps<T>) => {
let valueText = '';
if (field && segment[field]) {
Expand Down Expand Up @@ -161,15 +162,20 @@ const IntervalItem = <T extends { [key: string]: string | number }>({
{/* Create a div for the resize */}
{data[segment.index] && segment.end === data[segment.index].end && (
<div
title="Resize"
aria-label="Resize"
className={cx('resize', resizing && resizing.index === segment.index && 'selected')}
title={!disableDrag ? 'Resize' : 'Interval boundary'}
aria-label={!disableDrag ? 'Resize' : 'Interval boundary'}
className={cx('resize', {
selected: resizing && resizing.index === segment.index,
disabled: disableDrag,
})}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
}}
onMouseDown={(e) => {
setResizing({ index: segment.index, startAt: e.clientX, startPosition: segment.end });
if (!disableDrag) {
setResizing({ index: segment.index, startAt: e.clientX, startPosition: segment.end });
}
e.stopPropagation();
e.preventDefault();
}}
Expand Down
2 changes: 2 additions & 0 deletions front/src/common/IntervalsDataViz/dataviz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const LinearMetadataDataviz = <T extends { [key: string]: any }>({
onDragX,
onResize,
onCreate,
disableDrag,
}: LinearMetadataDatavizProps<T>) => {
// Html ref of the div wrapper
const wrapper = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -412,6 +413,7 @@ export const LinearMetadataDataviz = <T extends { [key: string]: any }>({
segment={segment}
setDraginStartAt={setDraginStartAt}
setResizing={setResizing}
disableDrag={disableDrag}
/>
))}
</div>
Expand Down
25 changes: 12 additions & 13 deletions front/src/common/IntervalsDataViz/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ $resize-width: 3px;
}

&.with-data {
z-index: 2;
z-index: 2;
}

&.highlighted {
Expand All @@ -195,14 +195,14 @@ $resize-width: 3px;
background-color: $color;
text-align: center;
white-space: nowrap;
overflow-y:hidden;
overflow-y: hidden;
span {
color:#fff;
color: #fff;
display: block;
font-size: 0.6em;
// trick to hide the value if the div is too small
// https://medium.com/swlh/hiding-an-element-when-there-is-no-enough-space-thanos-snap-technique-8a11e31267c0
max-height: max(0px, calc((100% - 12px)*999));
max-height: max(0px, calc((100% - 12px) * 999));
overflow: hidden;
}
}
Expand All @@ -214,8 +214,8 @@ $resize-width: 3px;
z-index: 2;
background-color: #fff;

&:hover,
&.selected {
&:not(.disabled):hover,
&:not(.disabled).selected {
background-color: #000;
cursor: col-resize;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ $resize-width: 3px;
.scale {
display: flex;
justify-content: space-between;
span{
span {
font-size: 0.6em;
overflow: hidden;
align-self: end;
Expand Down Expand Up @@ -335,10 +335,10 @@ $resize-width: 3px;
height: 50px;
text-align: center;

&:before{
content: "";
&:before {
content: '';
position: absolute;
top: -.2em;
top: -0.2em;
width: 1px;
height: 0.4em;
background-color: black;
Expand All @@ -355,7 +355,6 @@ $resize-width: 3px;
top: 0.75em;
}
}

}
}
}
Expand All @@ -372,7 +371,8 @@ $resize-width: 3px;
z-index: 999;

.linear-metadata-tooltip {
.header, .footer {
.header,
.footer {
display: flex;
flex-direction: row;
justify-content: space-between;
Expand All @@ -396,7 +396,6 @@ $resize-width: 3px;
padding: 1em;

.header {

.btn-toolbar {
width: 100%;
display: flex;
Expand Down
2 changes: 2 additions & 0 deletions front/src/common/IntervalsDataViz/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export interface IntervalItemBaseProps<T> {
* stringValues: each interval has just a category ref, not a continuous value
*/
options?: { resizingScale?: boolean; fullHeightItem?: boolean; showValues?: boolean };

disableDrag?: boolean;
}

export interface OperationalPoint {
Expand Down
Loading

0 comments on commit bea61b1

Please sign in to comment.