Skip to content

Commit 871f667

Browse files
committed
fix : calc without temporal dto changes + avoid manual handroll
1 parent 2c6fab2 commit 871f667

File tree

6 files changed

+611
-194
lines changed

6 files changed

+611
-194
lines changed

src/app/services/data/trainrun.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
BackwardTrainrunIterator,
2323
NonStopTrainrunIterator,
2424
TrainrunIterator,
25+
ExpandedTrainrunIterator,
2526
} from "../util/trainrun.iterator";
2627
import {LogService} from "../../logger/log.service";
2728
import {LabelService} from "./label.service";
@@ -799,6 +800,10 @@ export class TrainrunService {
799800
public getBackwardNonStopIterator(node: Node, trainrunSection: TrainrunSection) {
800801
return new BackwardNonStopTrainrunIterator(this.logService, node, trainrunSection);
801802
}
803+
804+
public getExpandedIterator(node: Node, trainrunSection: TrainrunSection) {
805+
return new ExpandedTrainrunIterator(this.logService, node, trainrunSection);
806+
}
802807

803808
// For each trainrun, get iterator from the smallest consecutiveTime.
804809
public getRootIterators(): Map<number, TrainrunIterator> {

src/app/services/data/trainrunsection.service.ts

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,67 +1472,45 @@ export class TrainrunSectionService implements OnDestroy {
14721472

14731473
/**
14741474
* Groups consecutive TrainrunSections that have collapsed nodes between them
1475-
* into chains with start and end nodes. Each chain starts and ends with a non-collapsed node.
1475+
* into chains. Each chain starts and ends with a non-collapsed node.
1476+
* Start and end nodes can be accessed via: sections[0].getSourceNode() and sections[sections.length - 1].getTargetNode()
14761477
* @param trainrunSections List of TrainrunSections to group
1477-
* @returns Array of section groups with start/end nodes
1478+
* @returns Array of section chains
14781479
*/
1479-
groupTrainrunSectionsIntoChains(trainrunSections: TrainrunSection[]): Array<{
1480-
sections: TrainrunSection[];
1481-
startNode: Node;
1482-
endNode: Node;
1483-
}> {
1484-
const groups: Array<{
1485-
sections: TrainrunSection[];
1486-
startNode: Node;
1487-
endNode: Node;
1488-
}> = [];
1480+
groupTrainrunSectionsIntoChains(trainrunSections: TrainrunSection[]): TrainrunSection[][] {
1481+
const groups: TrainrunSection[][] = [];
14891482
const visitedSections = new Set<number>();
14901483

14911484
trainrunSections.forEach((section) => {
14921485
if (visitedSections.has(section.getId())) {
14931486
return;
14941487
}
14951488

1496-
// Start a new group from this section
1489+
// Build chain using TrainrunIterator to leverage existing graph traversal
14971490
const chain: TrainrunSection[] = [];
1498-
let currentSection = section;
1499-
1500-
// Add the first section
1501-
chain.push(currentSection);
1502-
visitedSections.add(currentSection.getId());
1503-
1504-
// Look for consecutive sections with collapsed intermediate nodes
1505-
// eslint-disable-next-line no-constant-condition
1506-
while (true) {
1507-
const targetNode = this.nodeService.getNodeFromId(currentSection.getTargetNodeId());
1508-
if (!targetNode || !targetNode.getIsCollapsed()) {
1509-
break; // End of chain if target node is not collapsed
1491+
const startNode = section.getSourceNode();
1492+
const iterator = this.trainrunService.getIterator(startNode, section);
1493+
1494+
// Traverse the trainrun and collect sections with collapsed intermediate nodes
1495+
while (iterator.hasNext()) {
1496+
const pair = iterator.next();
1497+
1498+
if (visitedSections.has(pair.trainrunSection.getId())) {
1499+
break; // Already processed this section
15101500
}
15111501

1512-
// Find next section starting from this collapsed node
1513-
const nextSection = trainrunSections.find(
1514-
(ts) =>
1515-
ts.getSourceNodeId() === currentSection.getTargetNodeId() &&
1516-
ts.getTrainrunId() === currentSection.getTrainrunId() &&
1517-
!visitedSections.has(ts.getId()),
1518-
);
1519-
if (!nextSection) {
1520-
break; // No further section found, end of chain
1502+
chain.push(pair.trainrunSection);
1503+
visitedSections.add(pair.trainrunSection.getId());
1504+
1505+
// Stop if we reach a non-collapsed node (end of collapsed chain)
1506+
if (!pair.node.getIsCollapsed()) {
1507+
break;
15211508
}
1522-
chain.push(nextSection);
1523-
visitedSections.add(nextSection.getId());
1524-
currentSection = nextSection;
15251509
}
15261510

1527-
// Create group with start and end nodes
1528-
const startNode = this.nodeService.getNodeFromId(chain[0].getSourceNodeId());
1529-
const endNode = this.nodeService.getNodeFromId(chain[chain.length - 1].getTargetNodeId());
1530-
1531-
groups.push({
1532-
sections: chain,
1533-
startNode: startNode,
1534-
endNode: endNode,
1535-
});
1511+
if (chain.length > 0) {
1512+
groups.push(chain);
1513+
}
15361514
});
15371515

15381516
return groups;

src/app/services/util/trainrun.iterator.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,17 @@ export class BackwardNonStopTrainrunIterator extends BackwardTrainrunIterator {
135135
return super.next();
136136
}
137137
}
138+
139+
export class ExpandedTrainrunIterator extends TrainrunIterator {
140+
public next(): TrainrunSectionNodePair {
141+
// Continue traversing only if the current node is collapsed
142+
// Stop when we reach an expanded (non-collapsed) node
143+
if (!this.pointerElement.node.getIsCollapsed()) {
144+
// The trainrun has reached an expanded (non-collapsed) node and break the forward iteration
145+
this.currentElement = Object.assign({}, this.pointerElement);
146+
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);
147+
return this.currentElement;
148+
}
149+
return super.next();
150+
}
151+
}

src/app/view/editor-main-view/data-views/trainrunSectionViewObject.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ export class TrainrunSectionViewObject {
156156
d.getPath().forEach((p) => {
157157
key += p.toString();
158158
});
159+
160+
key += "_SRC_" + d.getSourceNode().getPositionX() + "_" + d.getSourceNode().getPositionY();
161+
key += "_TRG_" + d.getTargetNode().getPositionX() + "_" + d.getTargetNode().getPositionY();
162+
159163
return key;
160164
}
165+
166+
161167
}

0 commit comments

Comments
 (0)