Skip to content

Commit 4db03c6

Browse files
authored
867 error in oneway with freq 120 where the train path contains a b a c pattern (#868)
* fix: One‑Way with Freq. 120 & A → B → A → C Pattern * refactor: simplified to improve readability (review finding)
1 parent 9bc89e4 commit 4db03c6

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

src/app/models/node.model.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,16 @@ export class Node {
787787
.getTrainrunSection();
788788
}
789789

790+
getEndingTrainrunSection(trainrun: Trainrun): TrainrunSection {
791+
return this.ports
792+
.find(
793+
(port) =>
794+
port.getTrainrunSection().getTrainrunId() === trainrun.getId() &&
795+
this.isEndNode(port.getTrainrunSection()),
796+
)
797+
.getTrainrunSection();
798+
}
799+
790800
getPorts(): Port[] {
791801
return this.ports;
792802
}

src/app/view/dialogs/trainrun-and-section-dialog/trainrunsection-card/trainrun-section-card.component.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
139139
}
140140

141141
private getEdgeLineTextOddOffsetClass(n: Node, timeSelector: "Departure" | "Arrival") {
142-
const tr = this.trainrunService.getSelectedTrainrun();
143-
const trainrunSection = n.getTrainrunSection(tr);
142+
const selectedTrainrun = this.trainrunService.getSelectedTrainrun();
143+
if (!selectedTrainrun) {
144+
return "";
145+
}
146+
const trainrunSection = n.getEndingTrainrunSection(selectedTrainrun);
144147
if (timeSelector === "Departure") {
145148
return TrainrunSectionsView.getTrainrunSectionTimeElementOddOffsetTag(
146149
trainrunSection.getTargetNodeId() === n.getId()
@@ -208,43 +211,30 @@ export class TrainrunSectionCardComponent implements OnInit, AfterViewInit, OnDe
208211
return undefined;
209212
}
210213
const selectedTrainrunId = selectedTrainrun.getId();
211-
const trainrunSections =
212-
this.trainrunSectionService.getAllTrainrunSectionsForTrainrun(selectedTrainrunId);
213214
const [startNode, endNode] = [
214215
this.trainrunService.getLeftOrTopNodeWithTrainrunId(selectedTrainrunId),
215216
this.trainrunService.getRightOrBottomNodeWithTrainrunId(selectedTrainrunId),
216217
];
217218

218-
// Try to find startNode → endNode
219-
let firstTrainrunSection = trainrunSections.find(
220-
(ts) => ts.getSourceNodeId() === startNode.getId(),
221-
);
222-
let lastTrainrunSection = [...trainrunSections]
223-
.reverse()
224-
.find((ts) => ts.getTargetNodeId() === endNode.getId());
225-
226-
// If not found, swap first and last sections (and source and target nodes)
227-
if (!firstTrainrunSection && !lastTrainrunSection) {
228-
firstTrainrunSection = trainrunSections.find(
229-
(ts) => ts.getSourceNodeId() === endNode.getId(),
230-
);
231-
lastTrainrunSection = [...trainrunSections]
232-
.reverse()
233-
.find((ts) => ts.getTargetNodeId() === startNode.getId());
234-
[firstTrainrunSection, lastTrainrunSection] = [lastTrainrunSection, firstTrainrunSection];
235-
return {
236-
leftDepartureTime: firstTrainrunSection.getTargetDeparture(),
237-
leftArrivalTime: firstTrainrunSection.getTargetArrival(),
238-
rightDepartureTime: lastTrainrunSection.getSourceDeparture(),
239-
rightArrivalTime: lastTrainrunSection.getSourceArrival(),
240-
};
241-
}
219+
const firstTrainrunSection = startNode.getEndingTrainrunSection(selectedTrainrun);
220+
const lastTrainrunSection = endNode.getEndingTrainrunSection(selectedTrainrun);
221+
222+
const isFirstSectionAtSourceNode = firstTrainrunSection.getSourceNodeId() === startNode.getId();
223+
const isLastSectionAtSourceNode = lastTrainrunSection.getSourceNodeId() === endNode.getId();
242224

243225
return {
244-
leftDepartureTime: firstTrainrunSection.getSourceDeparture(),
245-
leftArrivalTime: firstTrainrunSection.getSourceArrival(),
246-
rightDepartureTime: lastTrainrunSection.getTargetDeparture(),
247-
rightArrivalTime: lastTrainrunSection.getTargetArrival(),
226+
leftDepartureTime: isFirstSectionAtSourceNode
227+
? firstTrainrunSection.getSourceDeparture()
228+
: firstTrainrunSection.getTargetDeparture(),
229+
leftArrivalTime: isFirstSectionAtSourceNode
230+
? firstTrainrunSection.getSourceArrival()
231+
: firstTrainrunSection.getTargetArrival(),
232+
rightDepartureTime: isLastSectionAtSourceNode
233+
? lastTrainrunSection.getSourceDeparture()
234+
: lastTrainrunSection.getTargetDeparture(),
235+
rightArrivalTime: isLastSectionAtSourceNode
236+
? lastTrainrunSection.getSourceArrival()
237+
: lastTrainrunSection.getTargetArrival(),
248238
};
249239
}
250240
}

0 commit comments

Comments
 (0)