Skip to content

Commit 14aff1d

Browse files
committed
wip: handle times updates when some node are reduced
Signed-off-by: Clara Ni <[email protected]>
1 parent 7536578 commit 14aff1d

File tree

6 files changed

+45
-31
lines changed

6 files changed

+45
-31
lines changed

src/app/models/node.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class Node {
322322
return currentMaxIndex;
323323
}
324324

325-
getIsCollapsed(): boolean {
325+
collapsed(): boolean {
326326
return this.isCollapsed;
327327
}
328328

src/app/sample-netzgrafik/netzgrafik_default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@
214214
},
215215
"symmetryAxis": null,
216216
"warnings": null,
217-
"labelIds": []
217+
"labelIds": [ ],
218+
"isCollapsed": true
218219
},
219220
{
220221
"id": 9,

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -879,18 +879,32 @@ export class TrainrunSectionService implements OnDestroy {
879879
let summedTravelTime = 0;
880880

881881
const iterator = this.trainrunService.getNonStopIterator(leftNode, trs);
882+
let prevInitialTargetArrival: number = null;
883+
let stopTime: number;
882884
while (iterator.hasNext()) {
885+
883886
const nextPair = iterator.next();
884887

885-
const isRightNodeNonStop = nextPair.node.isNonStop(nextPair.trainrunSection);
886-
trsTimeStructure.travelTime = TrainrunsectionHelper.getTravelTime(
888+
if (prevInitialTargetArrival !== null) {
889+
// gérer les modulo 60 et positif
890+
stopTime = (nextPair.trainrunSection.getSourceDeparture() - prevInitialTargetArrival) % 60;
891+
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime + stopTime;
892+
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime + stopTime;
893+
}
894+
prevInitialTargetArrival = nextPair.trainrunSection.getTargetArrival();
895+
896+
const isFinalRightNode = !nextPair.node.isNonStop(nextPair.trainrunSection) && !nextPair.node.collapsed();
897+
trsTimeStructure.travelTime = isFinalRightNode ?
898+
TrainrunsectionHelper.getLastSectionTravelTime(
887899
newTotalTravelTime,
888900
summedTravelTime,
889-
travelTimeFactor,
901+
precision,
902+
) : TrainrunsectionHelper.getSectionTravelTime(
890903
nextPair.trainrunSection.getTravelTime(),
891-
isRightNodeNonStop,
904+
travelTimeFactor,
892905
precision,
893906
);
907+
894908
trsTimeStructure.rightArrivalTime = TrainrunsectionHelper.getRightArrivalTime(
895909
trsTimeStructure,
896910
precision,
@@ -910,8 +924,6 @@ export class TrainrunSectionService implements OnDestroy {
910924
trsTimeStructure.travelTime,
911925
);
912926

913-
trsTimeStructure.leftDepartureTime = trsTimeStructure.rightArrivalTime;
914-
trsTimeStructure.leftArrivalTime = trsTimeStructure.rightDepartureTime;
915927
summedTravelTime += trsTimeStructure.travelTime;
916928
}
917929

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class TrainrunIterator {
7575

7676
export class NonStopTrainrunIterator extends TrainrunIterator {
7777
public next(): TrainrunSectionNodePair {
78-
if (!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection)) {
78+
if (!this.pointerElement.node.isNonStop(this.pointerElement.trainrunSection) && !this.pointerElement.node.collapsed()) {
7979
// The trainrun has a stop and break the forward iteration
8080
this.currentElement = Object.assign({}, this.pointerElement);
8181
this.pointerElement = new TrainrunSectionNodePair(undefined, undefined);

src/app/services/util/trainrunsection.helper.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,22 +99,22 @@ describe("TrainrunsectionHelper", () => {
9999
});
100100

101101
it("getTravelTime -- 001", () => {
102-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, false, 0);
102+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, false, 0);
103103
expect(tt).toBe(1);
104104
});
105105

106106
it("getTravelTime -- 002", () => {
107-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, true, 0);
107+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, true, 0);
108108
expect(tt).toBe(12);
109109
});
110110

111111
it("getTravelTime -- 003", () => {
112-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, false, 0);
112+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, false, 0);
113113
expect(tt).toBe(1);
114114
});
115115

116116
it("getTravelTime -- 004", () => {
117-
const tt = TrainrunsectionHelper.getTravelTime(8, 10, 2, 12, false, 0);
117+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(8, 10, 2, 12, false, 0);
118118
expect(tt).toBe(1);
119119
});
120120

@@ -217,22 +217,22 @@ describe("TrainrunsectionHelper", () => {
217217
});
218218

219219
it("getTravelTime -- 2 -- 001", () => {
220-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, false, 0);
220+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, false, 0);
221221
expect(tt).toBe(1);
222222
});
223223

224224
it("getTravelTime -- 2 -- 002", () => {
225-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, true, 0);
225+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, true, 0);
226226
expect(tt).toBe(12);
227227
});
228228

229229
it("getTravelTime -- 2 -- 003", () => {
230-
const tt = TrainrunsectionHelper.getTravelTime(10, 10, 1, 12, false, 0);
230+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(10, 10, 1, 12, false, 0);
231231
expect(tt).toBe(1);
232232
});
233233

234234
it("getTravelTime -- 2 -- 004", () => {
235-
const tt = TrainrunsectionHelper.getTravelTime(8, 10, 2, 12, false, 0);
235+
const tt = TrainrunsectionHelper.getLastSectionTravelTime(8, 10, 2, 12, false, 0);
236236
expect(tt).toBe(1);
237237
});
238238

src/app/services/util/trainrunsection.helper.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,26 @@ export class TrainrunsectionHelper {
3939
};
4040
}
4141

42-
static getTravelTime(
42+
static getLastSectionTravelTime(
4343
totalTravelTime: number,
4444
summedTravelTime: number,
45-
travelTimeFactor: number,
45+
precision = TrainrunSectionService.TIME_PRECISION,
46+
): number {
47+
return Math.max(
48+
MathUtils.round(totalTravelTime - summedTravelTime, precision),
49+
1.0 / Math.pow(10, precision),
50+
);
51+
}
52+
53+
static getSectionTravelTime(
4654
trsTravelTime: number,
47-
isRightNodeNonStopTransit: boolean,
55+
travelTimeFactor: number,
4856
precision = TrainrunSectionService.TIME_PRECISION,
4957
): number {
50-
if (isRightNodeNonStopTransit) {
51-
return Math.max(
52-
MathUtils.round(trsTravelTime * travelTimeFactor, precision),
53-
1.0 / Math.pow(10, precision),
54-
);
55-
} else {
56-
return Math.max(
57-
MathUtils.round(totalTravelTime - summedTravelTime, precision),
58-
1.0 / Math.pow(10, precision),
59-
);
60-
}
58+
return Math.max(
59+
MathUtils.round(trsTravelTime * travelTimeFactor, precision),
60+
1.0 / Math.pow(10, precision),
61+
);
6162
}
6263

6364
static getRightArrivalTime(

0 commit comments

Comments
 (0)