Skip to content

Commit

Permalink
front: add default trainrun categories/freqs to NGE
Browse files Browse the repository at this point in the history
Fixes errors when adding a new trainrun.
  • Loading branch information
emersion committed Jul 15, 2024
1 parent 9316989 commit 63797b4
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { osrdEditoastApi } from 'common/api/osrdEditoastApi';
import type { SearchResultItemOperationalPoint, SearchPayload } from 'common/api/osrdEditoastApi';
import type { AppDispatch } from 'store';

import type { Node, NetzgrafikDto } from './types';
import type {
Node,
TrainrunCategory,
TrainrunFrequency,
TrainrunTimeCategory,
NetzgrafikDto,
} from './types';

// TODO: make this optional in NGE since it's SBB-specific
const TRAINRUN_CATEGORY_HALTEZEITEN = {
Expand Down Expand Up @@ -33,6 +39,40 @@ const EMPTY_DTO: NetzgrafikDto = {
},
};

const DEFAULT_TRAINRUN_CATEGORY: TrainrunCategory = {
id: 1, // In NGE, Trainrun.DEFAULT_TRAINRUN_CATEGORY
order: 0,
name: 'Default',
shortName: 'D',
fachCategory: 'HaltezeitUncategorized',
colorRef: 'EC',
minimalTurnaroundTime: 0,
nodeHeadwayStop: 0,
nodeHeadwayNonStop: 0,
sectionHeadway: 0,
};

const DEFAULT_TRAINRUN_FREQUENCY: TrainrunFrequency = {
id: 3, // In NGE, Trainrun.DEFAULT_TRAINRUN_FREQUENCY
order: 0,
frequency: 60,
offset: 0,
name: 'Default',
/** Short name, needs to be unique */
shortName: 'D',
linePatternRef: '60',
};

const DEFAULT_TRAINRUN_TIME_CATEGORY: TrainrunTimeCategory = {
id: 0, // In NGE, Trainrun.DEFAULT_TRAINRUN_TIME_CATEGORY
order: 0,
name: 'Default',
shortName: '7/24',
dayTimeInterval: [],
weekday: [1, 2, 3, 4, 5, 6, 7],
linePatternRef: '7/24',
};

const convertGeoCoords = (nodes: Node[]) => {
const xCoords = nodes.map((node) => node.positionX);
const yCoords = nodes.map((node) => node.positionY);
Expand Down Expand Up @@ -160,6 +200,12 @@ const importTimetable = async (
return {
...EMPTY_DTO,
resources: [resource],
metadata: {
netzgrafikColors: [],
trainrunCategories: [DEFAULT_TRAINRUN_CATEGORY],
trainrunFrequencies: [DEFAULT_TRAINRUN_FREQUENCY],
trainrunTimeCategories: [DEFAULT_TRAINRUN_TIME_CATEGORY],
},
nodes,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,42 @@ export type TrainrunSection = {
warnings: unknown[];
};

export type TrainrunCategory = {
id: number;
order: number;
name: string;
/** Short name, needs to be unique */
shortName: string;
fachCategory: string;
colorRef: string;
minimalTurnaroundTime: number;
nodeHeadwayStop: number;
nodeHeadwayNonStop: number;
sectionHeadway: number;
};

export type TrainrunFrequency = {
id: number;
order: number;
frequency: number;
offset: number;
name: string;
/** Short name, needs to be unique */
shortName: string;
linePatternRef: string;
};

export type TrainrunTimeCategory = {
id: number;
order: number;
name: string;
/** Short name, needs to be unique */
shortName: string;
dayTimeInterval: unknown[];
weekday: number[];
linePatternRef: string;
};

export type Resource = {
id: number;
capacity: number;
Expand All @@ -79,9 +115,9 @@ export type NetzgrafikDto = {
resources: Resource[];
metadata: {
netzgrafikColors: unknown[];
trainrunCategories: unknown[];
trainrunFrequencies: unknown[];
trainrunTimeCategories: unknown[];
trainrunCategories: TrainrunCategory[];
trainrunFrequencies: TrainrunFrequency[];
trainrunTimeCategories: TrainrunTimeCategory[];
};
freeFloatingTexts: unknown[];
labels: unknown[];
Expand Down

0 comments on commit 63797b4

Please sign in to comment.