Skip to content

Commit

Permalink
hack: allow times to be unset
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Aug 8, 2024
1 parent fc8e10d commit c259448
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/app/data-structures/technical.data.structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/app/models/trainrunsection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ export class PerlenketteSectionComponent
}

getTravelTime() {
if (this.trainrunSectionTimesService.getTimeStructure().travelTime === null) {
return null;
}
if (
TrainrunSectionsView.getNode(this.trainrunSection, true).isNonStop(
this.trainrunSection,
Expand Down Expand Up @@ -921,6 +924,9 @@ export class PerlenketteSectionComponent
}

roundTime(time: number) {
if (time === null) {
return time;
}
return MathUtils.round(time, this.filterService.getTimeDisplayPrecision());
}

Expand Down
40 changes: 17 additions & 23 deletions src/app/services/data/trainrun-section-times.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/util/trainrunsection.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class TrainrunsectionHelper {
leftArrivalTime: lastLeftNode.getArrivalTime(leftTrainrunSection),
rightDepartureTime: lastRightNode.getDepartureTime(rightTrainrunSection),
rightArrivalTime: lastRightNode.getArrivalTime(rightTrainrunSection),
travelTime: cumulativeTravelTime,
travelTime: cumulativeTravelTime || null,
};
}

Expand Down

0 comments on commit c259448

Please sign in to comment.