Skip to content

Commit

Permalink
front: adapt simulation results for trainschedule v2
Browse files Browse the repository at this point in the history
  • Loading branch information
SharglutDev committed May 31, 2024
1 parent 3203aa3 commit 625d185
Show file tree
Hide file tree
Showing 65 changed files with 5,534 additions and 722 deletions.
556 changes: 556 additions & 0 deletions front/src/applications/operationalStudies/__tests__/sampleData.ts

Large diffs are not rendered by default.

111 changes: 111 additions & 0 deletions front/src/applications/operationalStudies/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import {
formatElectrificationRanges,
formatPowerRestrictionRanges,
formatPowerRestrictionRangesWithHandled,
transformBoundariesDataToPositionDataArray,
transformBoundariesDataToRangesData,
} from 'applications/operationalStudies/utils';

import {
boundariesDataWithElectrificalProfile,
boundariesDataWithElectrification,
boundariesDataWithNumber,
effortCurves,
electricalProfileRangesData,
electricalProfileRangesDataShort,
electrificationRanges,
electrificationRangesData,
electrificationRangesDataLarge,
electrificationRangesForPowerRestrictions,
electrificationRangesLarge,
formattedPowerRestrictionRanges,
getExpectedResultDataNumber,
pathLength,
powerRestriction,
powerRestrictionRanges,
powerRestrictionRangesWithHandled,
stepPath,
stepPathPositions,
} from './sampleData';

describe('transformBoundariesDataToPositionDataArray', () => {
it('should transform boundaries data to position data array for gradient', () => {
const result = transformBoundariesDataToPositionDataArray(
boundariesDataWithNumber,
pathLength,
'gradient'
);

expect(result).toEqual(getExpectedResultDataNumber('gradient'));
});

it('should transform boundaries data to position data array for radius', () => {
const result = transformBoundariesDataToPositionDataArray(
boundariesDataWithNumber,
pathLength,
'radius'
);

expect(result).toEqual(getExpectedResultDataNumber('radius'));
});
});

describe('transformBoundariesDataToRangesData', () => {
it('should transform boundaries data to ranges data for electrification', () => {
const result = transformBoundariesDataToRangesData(
boundariesDataWithElectrification,
pathLength
);

expect(result).toEqual(electrificationRangesData);
});

it('should transform boundaries data to ranges data for electrical profile', () => {
const result = transformBoundariesDataToRangesData(
boundariesDataWithElectrificalProfile,
pathLength
);

expect(result).toEqual(electricalProfileRangesData);
});
});

describe('formatElectrificationRanges', () => {
it('should properly format electrification ranges if both parameters have same length', () => {
const result = formatElectrificationRanges(
electrificationRangesData,
electricalProfileRangesData
);

expect(result).toEqual(electrificationRanges);
});

it('should properly format electrification ranges if electrification is longer than electrical profiles', () => {
const result = formatElectrificationRanges(
electrificationRangesDataLarge,
electricalProfileRangesDataShort
);

expect(result).toEqual(electrificationRangesLarge);
});
});

describe('formatPowerRestrictionRanges', () => {
it('should properly format power restrictions ranges', () => {
const result = formatPowerRestrictionRanges(powerRestriction, stepPath, stepPathPositions);

expect(result).toEqual(formattedPowerRestrictionRanges);
});
});

describe('formatPowerRestrictionRangesWithHandled', () => {
it('should properly format power restrictions ranges with handled property', () => {
const result = formatPowerRestrictionRangesWithHandled(
powerRestrictionRanges,
electrificationRangesForPowerRestrictions,
effortCurves
);

expect(result).toEqual(powerRestrictionRangesWithHandled);
});
});
80 changes: 6 additions & 74 deletions front/src/applications/operationalStudies/consts.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import type { Position } from 'geojson';

import type {
ElectrificationRange,
ElectrificationUsage,
SimulationPowerRestrictionRange,
} from 'common/api/osrdEditoastApi';
import type { ElectrificationRange, ElectrificationUsage } from 'common/api/osrdEditoastApi';
import type { LinearMetadataItem } from 'common/IntervalsDataViz/types';
import i18n from 'i18n';
import type { Mode } from 'modules/simulationResult/components/SpeedSpaceChart/types';
import type { HeightPosition } from 'reducers/osrdsimulation/types';

export const BLOCKTYPES = [
Expand Down Expand Up @@ -140,6 +137,7 @@ interface Profile {
export const DRAWING_KEYS: (keyof HeightPosition)[] = ['position', 'height'];
export type DrawingKeys = typeof DRAWING_KEYS;

// TODO DROP V1: remove this
export interface ElectricalConditionSegment {
position_start: number;
position_end: number;
Expand All @@ -160,32 +158,7 @@ export interface ElectricalConditionSegment {
isIncompatiblePowerRestriction: boolean;
}

interface AC {
'25000V': string;
'22500V': string;
'20000V': string;
}
interface DC {
O: string;
A: string;
A1: string;
B: string;
B1: string;
C: string;
D: string;
E: string;
F: string;
G: string;
}

interface Mode {
'25000V': AC | string;
'1500V': DC | string;
thermal: string;
'15000V': string;
'3000V': string;
}

// TODO DROP V1: remove this
const electricalProfileColorsWithProfile: Mode = {
'25000V': { '25000V': '#6E1E78', '22500V': '#A453AD', '20000V': '#DD87E5' },
'1500V': {
Expand All @@ -205,6 +178,7 @@ const electricalProfileColorsWithProfile: Mode = {
'3000V': '#1FBE00',
};

// TODO DROP V1: remove this
const electricalProfileColorsWithoutProfile: Mode = {
'25000V': '#6E1E78',
'1500V': '#FF0037',
Expand All @@ -230,6 +204,7 @@ export const legend: Profile[] = [
},
];

// TODO DROP V1: remove this
export const createProfileSegment = (
fullElectrificationRange: ElectrificationRange[],
electrificationRange: ElectrificationRange
Expand Down Expand Up @@ -298,46 +273,3 @@ export const createProfileSegment = (

return segment;
};

export interface PowerRestrictionSegment {
position_start: number;
position_end: number;
position_middle: number;
lastPosition: number;
height_start: number;
height_end: number;
height_middle: number;
seenRestriction: string;
usedRestriction: boolean;
isStriped: boolean;
isRestriction: boolean;
isIncompatiblePowerRestriction: boolean;
}

export const createPowerRestrictionSegment = (
fullPowerRestrictionRange: SimulationPowerRestrictionRange[],
powerRestrictionRange: SimulationPowerRestrictionRange
) => {
// figure out if the power restriction is incompatible or missing
const isRestriction = powerRestrictionRange.handled;
const isIncompatiblePowerRestriction =
!!powerRestrictionRange.code && !powerRestrictionRange.handled;
const isStriped = !!powerRestrictionRange.code && !powerRestrictionRange.handled;

const segment: PowerRestrictionSegment = {
position_start: powerRestrictionRange.start,
position_end: powerRestrictionRange.stop,
position_middle: (powerRestrictionRange.start + powerRestrictionRange.stop) / 2,
lastPosition: fullPowerRestrictionRange.slice(-1)[0].stop,
height_start: 4,
height_end: 24,
height_middle: 14,
seenRestriction: powerRestrictionRange.code || '',
usedRestriction: powerRestrictionRange.handled,
isStriped,
isRestriction,
isIncompatiblePowerRestriction,
};

return segment;
};
Loading

0 comments on commit 625d185

Please sign in to comment.