From 3c6234b5a0c10c82601bfde898fa7f8564cbd301 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 7 Aug 2024 15:46:07 +0200 Subject: [PATCH] hack: allow times to be unset --- .../technical.data.structures.ts | 2 +- src/app/models/trainrunsection.model.ts | 3 ++ .../data/trainrun-section-times.service.ts | 40 ++++++++----------- .../services/util/trainrunsection.helper.ts | 2 +- 4 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/app/data-structures/technical.data.structures.ts b/src/app/data-structures/technical.data.structures.ts index 51abe079..e2465c89 100644 --- a/src/app/data-structures/technical.data.structures.ts +++ b/src/app/data-structures/technical.data.structures.ts @@ -98,7 +98,7 @@ export interface TimeFormatter { * Represents the time data in TrainrunSectionDto. */ export interface TimeLockDto { - time: number; // minutes [0..60] + time: number | null; // minutes [0..60] consecutiveTime: number; // automatically updated after any data changes in the application lock: boolean; // used to stop the time propagation (forward/backward) warning: WarningDto; // warning - if business logic detects an issue -> set human-readable warning diff --git a/src/app/models/trainrunsection.model.ts b/src/app/models/trainrunsection.model.ts index 0460aee7..02e15e72 100644 --- a/src/app/models/trainrunsection.model.ts +++ b/src/app/models/trainrunsection.model.ts @@ -175,6 +175,9 @@ export class TrainrunSection { } private static formatDisplayText(time: TimeLockDto, offset: number): string { + if (time.time === null) { + return "?"; + } if (!time?.timeFormatter?.stylePattern) { return undefined; } diff --git a/src/app/services/data/trainrun-section-times.service.ts b/src/app/services/data/trainrun-section-times.service.ts index afb821a5..c00f066b 100644 --- a/src/app/services/data/trainrun-section-times.service.ts +++ b/src/app/services/data/trainrun-section-times.service.ts @@ -491,22 +491,22 @@ export class TrainrunSectionTimesService { this.initialLeftAndRightElement === LeftAndRightElement.LeftRightTrainrunName ) { - this.timeStructure.leftDepartureTime = + this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null : (this.timeStructure.leftDepartureTime + this.offset) % 60; - this.timeStructure.rightArrivalTime = + this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null : (this.timeStructure.rightArrivalTime + this.offset) % 60; - this.timeStructure.leftArrivalTime = + this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null : (maxMinutes + this.timeStructure.leftArrivalTime - this.offset) % 60; - this.timeStructure.rightDepartureTime = + this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null : (maxMinutes + this.timeStructure.rightDepartureTime - this.offset) % 60; } else { - this.timeStructure.leftDepartureTime = + this.timeStructure.leftDepartureTime = this.timeStructure.leftDepartureTime === null ? null : (maxMinutes + this.timeStructure.leftDepartureTime - this.offset) % 60; - this.timeStructure.rightArrivalTime = + this.timeStructure.rightArrivalTime = this.timeStructure.rightArrivalTime === null ? null : (maxMinutes + this.timeStructure.rightArrivalTime - this.offset) % 60; - this.timeStructure.leftArrivalTime = + this.timeStructure.leftArrivalTime = this.timeStructure.leftArrivalTime === null ? null : (this.timeStructure.leftArrivalTime + this.offset) % 60; - this.timeStructure.rightDepartureTime = + this.timeStructure.rightDepartureTime = this.timeStructure.rightDepartureTime === null ? null : (this.timeStructure.rightDepartureTime + this.offset) % 60; } this.offsetTransformationActive = true; @@ -573,21 +573,15 @@ export class TrainrunSectionTimesService { private fixAllTimesPrecision() { const timeDisplayPrecision = 1000; - this.timeStructure.leftArrivalTime = - Math.round(this.timeStructure.leftArrivalTime * timeDisplayPrecision) / - timeDisplayPrecision; - this.timeStructure.leftDepartureTime = - Math.round(this.timeStructure.leftDepartureTime * timeDisplayPrecision) / - timeDisplayPrecision; - this.timeStructure.rightArrivalTime = - Math.round(this.timeStructure.rightArrivalTime * timeDisplayPrecision) / - timeDisplayPrecision; - this.timeStructure.rightDepartureTime = - Math.round(this.timeStructure.rightDepartureTime * timeDisplayPrecision) / - timeDisplayPrecision; - this.timeStructure.travelTime = - Math.round(this.timeStructure.travelTime * timeDisplayPrecision) / - timeDisplayPrecision; + const fixPrecision = (time) => { + if (time === null) return null; + return Math.round(time * timeDisplayPrecision) / timeDisplayPrecision; + }; + this.timeStructure.leftArrivalTime = fixPrecision(this.timeStructure.leftArrivalTime); + this.timeStructure.leftDepartureTime = fixPrecision(this.timeStructure.leftDepartureTime); + this.timeStructure.rightArrivalTime = fixPrecision(this.timeStructure.rightArrivalTime); + this.timeStructure.rightDepartureTime = fixPrecision(this.timeStructure.rightDepartureTime); + this.timeStructure.travelTime = fixPrecision(this.timeStructure.travelTime); } private updateTrainrunSectionTime() { diff --git a/src/app/services/util/trainrunsection.helper.ts b/src/app/services/util/trainrunsection.helper.ts index 01cae421..416e7242 100644 --- a/src/app/services/util/trainrunsection.helper.ts +++ b/src/app/services/util/trainrunsection.helper.ts @@ -303,7 +303,7 @@ export class TrainrunsectionHelper { leftArrivalTime: lastLeftNode.getArrivalTime(leftTrainrunSection), rightDepartureTime: lastRightNode.getDepartureTime(rightTrainrunSection), rightArrivalTime: lastRightNode.getArrivalTime(rightTrainrunSection), - travelTime: cumulativeTravelTime, + travelTime: cumulativeTravelTime || null, }; }