Skip to content

Commit d2c3f1c

Browse files
committed
hack: allow times to be unset
1 parent 5ff7fd9 commit d2c3f1c

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

src/app/data-structures/technical.data.structures.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export interface TimeFormatter {
9898
* Represents the time data in TrainrunSectionDto.
9999
*/
100100
export interface TimeLockDto {
101-
time: number; // minutes [0..60]
101+
time: number | null; // minutes [0..60]
102102
consecutiveTime: number; // automatically updated after any data changes in the application
103103
lock: boolean; // used to stop the time propagation (forward/backward)
104104
warning: WarningDto; // warning - if business logic detects an issue -> set human-readable warning

src/app/models/trainrunsection.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ export class TrainrunSection {
175175
}
176176

177177
private static formatDisplayText(time: TimeLockDto, offset: number): string {
178+
if (time.time === null) {
179+
return "?";
180+
}
178181
if (!time?.timeFormatter?.stylePattern) {
179182
return undefined;
180183
}

src/app/perlenkette/perlenkette-section/perlenkette-section.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ export class PerlenketteSectionComponent
610610
}
611611

612612
getTravelTime() {
613+
if (this.trainrunSectionTimesService.getTimeStructure().travelTime === null) {
614+
return null;
615+
}
613616
if (
614617
TrainrunSectionsView.getNode(this.trainrunSection, true).isNonStop(
615618
this.trainrunSection,
@@ -921,6 +924,9 @@ export class PerlenketteSectionComponent
921924
}
922925

923926
roundTime(time: number) {
927+
if (time === null) {
928+
return time;
929+
}
924930
return MathUtils.round(time, this.filterService.getTimeDisplayPrecision());
925931
}
926932

src/app/services/data/trainrun-section-times.service.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -491,22 +491,22 @@ export class TrainrunSectionTimesService {
491491
this.initialLeftAndRightElement ===
492492
LeftAndRightElement.LeftRightTrainrunName
493493
) {
494-
this.timeStructure.leftDepartureTime =
494+
this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null :
495495
(this.timeStructure.leftDepartureTime + this.offset) % 60;
496-
this.timeStructure.rightArrivalTime =
496+
this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null :
497497
(this.timeStructure.rightArrivalTime + this.offset) % 60;
498-
this.timeStructure.leftArrivalTime =
498+
this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null :
499499
(maxMinutes + this.timeStructure.leftArrivalTime - this.offset) % 60;
500-
this.timeStructure.rightDepartureTime =
500+
this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null :
501501
(maxMinutes + this.timeStructure.rightDepartureTime - this.offset) % 60;
502502
} else {
503-
this.timeStructure.leftDepartureTime =
503+
this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null :
504504
(maxMinutes + this.timeStructure.leftDepartureTime - this.offset) % 60;
505-
this.timeStructure.rightArrivalTime =
505+
this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null :
506506
(maxMinutes + this.timeStructure.rightArrivalTime - this.offset) % 60;
507-
this.timeStructure.leftArrivalTime =
507+
this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null :
508508
(this.timeStructure.leftArrivalTime + this.offset) % 60;
509-
this.timeStructure.rightDepartureTime =
509+
this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null :
510510
(this.timeStructure.rightDepartureTime + this.offset) % 60;
511511
}
512512
this.offsetTransformationActive = true;
@@ -569,25 +569,26 @@ export class TrainrunSectionTimesService {
569569
this.timeStructure.travelTime,
570570
timeDisplayPrecision,
571571
);
572+
// Populate travel time here, otherwise it'll be up to
573+
// setTimeStructureToTrainrunSections() and it may overwrite values entered
574+
// by the user
575+
const minTravelTime = 1.0 / Math.pow(10, this.filterService.getTimeDisplayPrecision());
576+
if (this.timeStructure.travelTime < 0.1) {
577+
this.timeStructure.travelTime = 0.1;
578+
}
572579
}
573580

574581
private fixAllTimesPrecision() {
575582
const timeDisplayPrecision = 1000;
576-
this.timeStructure.leftArrivalTime =
577-
Math.round(this.timeStructure.leftArrivalTime * timeDisplayPrecision) /
578-
timeDisplayPrecision;
579-
this.timeStructure.leftDepartureTime =
580-
Math.round(this.timeStructure.leftDepartureTime * timeDisplayPrecision) /
581-
timeDisplayPrecision;
582-
this.timeStructure.rightArrivalTime =
583-
Math.round(this.timeStructure.rightArrivalTime * timeDisplayPrecision) /
584-
timeDisplayPrecision;
585-
this.timeStructure.rightDepartureTime =
586-
Math.round(this.timeStructure.rightDepartureTime * timeDisplayPrecision) /
587-
timeDisplayPrecision;
588-
this.timeStructure.travelTime =
589-
Math.round(this.timeStructure.travelTime * timeDisplayPrecision) /
590-
timeDisplayPrecision;
583+
const fixPrecision = (time) => {
584+
if (time === null) return null;
585+
return Math.round(time * timeDisplayPrecision) / timeDisplayPrecision;
586+
};
587+
this.timeStructure.leftArrivalTime = fixPrecision(this.timeStructure.leftArrivalTime);
588+
this.timeStructure.leftDepartureTime = fixPrecision(this.timeStructure.leftDepartureTime);
589+
this.timeStructure.rightArrivalTime = fixPrecision(this.timeStructure.rightArrivalTime);
590+
this.timeStructure.rightDepartureTime = fixPrecision(this.timeStructure.rightDepartureTime);
591+
this.timeStructure.travelTime = fixPrecision(this.timeStructure.travelTime);
591592
}
592593

593594
private updateTrainrunSectionTime() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ export class TrainrunSectionService implements OnDestroy {
934934

935935
const oldTotalTravelTime =
936936
this.trainrunService.getCumulativeTravelTime(trainrunSection);
937-
const travelTimeFactor = newTotalTravelTime / oldTotalTravelTime;
937+
const travelTimeFactor = newTotalTravelTime / (oldTotalTravelTime || 1);
938938

939939
// prepare data structure for the first trainrunsection
940940
const bothLastNonStopNodes =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export class TrainrunsectionHelper {
303303
leftArrivalTime: lastLeftNode.getArrivalTime(leftTrainrunSection),
304304
rightDepartureTime: lastRightNode.getDepartureTime(rightTrainrunSection),
305305
rightArrivalTime: lastRightNode.getArrivalTime(rightTrainrunSection),
306-
travelTime: cumulativeTravelTime,
306+
travelTime: cumulativeTravelTime || null,
307307
};
308308
}
309309

0 commit comments

Comments
 (0)