Skip to content

Commit

Permalink
front: fix macro trainruns frequencies
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Jan 22, 2025
1 parent 8affe7b commit 9eefc97
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,37 @@ export const loadAndIndexNge = async (
const getNgeTrainruns = (state: MacroEditorState, labels: LabelDto[]) =>
state.trainSchedules
.filter((trainSchedule) => trainSchedule.path.length >= 2)
.map((trainSchedule) => ({
id: trainSchedule.id,
name: trainSchedule.train_name,
categoryId: DEFAULT_TRAINRUN_CATEGORY.id,
frequencyId: DEFAULT_TRAINRUN_FREQUENCY.id,
trainrunTimeCategoryId: DEFAULT_TRAINRUN_TIME_CATEGORY.id,
labelIds: (trainSchedule.labels || []).map((l) =>
labels.findIndex((e) => e.label === l && e.labelGroupId === TRAINRUN_LABEL_GROUP.id)
),
}));
.map((trainSchedule) => {
// NGE trainrun frequency is stored as OSRD labels ('frequency::30' or 'frequency::120')
let trainrunFrequency: TrainrunFrequency | undefined;
if (trainSchedule.labels) {
trainSchedule.labels.forEach((label) => {
if (label.includes('frequency')) {
const frequency = parseInt(label.split('::')[1], 10);
const trainrunFrequencyFound = DEFAULT_TRAINRUN_FREQUENCIES.find(
(freq) => freq.frequency === frequency
);
if (
trainrunFrequencyFound &&
(!trainrunFrequency || trainrunFrequencyFound.frequency < trainrunFrequency.frequency)
) {
trainrunFrequency = trainrunFrequencyFound;
}
}
});
}

return {
id: trainSchedule.id,
name: trainSchedule.train_name,
categoryId: DEFAULT_TRAINRUN_CATEGORY.id,
frequencyId: trainrunFrequency?.id || DEFAULT_TRAINRUN_FREQUENCY.id,
trainrunTimeCategoryId: DEFAULT_TRAINRUN_TIME_CATEGORY.id,
labelIds: (trainSchedule.labels || []).map((l) =>
labels.findIndex((e) => e.label === l && e.labelGroupId === TRAINRUN_LABEL_GROUP.id)
),
};
});

/**
* Translate the train schedule in NGE "trainrunSection" & "nodes".
Expand Down Expand Up @@ -494,7 +515,7 @@ export const getNgeDto = (state: MacroEditorState): NetzgrafikDto => {
metadata: {
netzgrafikColors: [],
trainrunCategories: [DEFAULT_TRAINRUN_CATEGORY],
trainrunFrequencies: [DEFAULT_TRAINRUN_FREQUENCY],
trainrunFrequencies: DEFAULT_TRAINRUN_FREQUENCIES,
trainrunTimeCategories: [DEFAULT_TRAINRUN_TIME_CATEGORY],
},
trainruns: getNgeTrainruns(state, labels),
Expand Down

0 comments on commit 9eefc97

Please sign in to comment.