Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/models/trainrunsection.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {TrainrunSectionValidator} from "../services/util/trainrunsection.validat
import {formatDate} from "@angular/common";

export class TrainrunSection {
static MIN_TRAVEL_TIME = 0.01; // 1 / 100 minute = 0.6 second - defined min. travel time

private static currentId = 0;

private id: number;
Expand Down Expand Up @@ -386,8 +388,8 @@ export class TrainrunSection {
}

setTravelTime(time: number) {
this.travelTime.time = time;
TrainrunSectionValidator.validateTravelTime(this, 1); // TODO: I don't think this should be done here
this.travelTime.time = Math.max(time, TrainrunSection.MIN_TRAVEL_TIME);
TrainrunSectionValidator.validateTravelTime(this);
}

setSourceDeparture(time: number) {
Expand Down
5 changes: 5 additions & 0 deletions src/app/services/data/trainrun-section-times.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ export class TrainrunSectionTimesService {
this.roundAllTimes();
this.removeOffsetAndBackTransformTimeStructure();

this.timeStructure.travelTime = Math.max(
this.timeStructure.travelTime,
TrainrunSection.MIN_TRAVEL_TIME,
);

if (!this.lockStructure.rightLock) {
this.timeStructure.rightArrivalTime = MathUtils.mod60(
this.timeStructure.leftDepartureTime + this.timeStructure.travelTime,
Expand Down
5 changes: 1 addition & 4 deletions src/app/services/data/trainrunsection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ export class TrainrunSectionService implements OnDestroy {

this.trainrunSectionsStore.trainrunSections.forEach((trainrunSection) => {
TrainrunSectionValidator.validateOneSection(trainrunSection);
TrainrunSectionValidator.validateTravelTime(
trainrunSection,
this.filterService.getTimeDisplayPrecision(),
);
TrainrunSectionValidator.validateTravelTime(trainrunSection);
});
}

Expand Down
9 changes: 4 additions & 5 deletions src/app/services/util/trainrunsection.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ export class TrainrunSectionValidator {
}
}

static validateTravelTime(trainrunSection: TrainrunSection, timeDisplayPrecision: number = 1) {
const minimumTravelTime = 1 / Math.pow(10, timeDisplayPrecision);
if (trainrunSection.getTravelTime() < minimumTravelTime) {
static validateTravelTime(trainrunSection: TrainrunSection) {
if (trainrunSection.getTravelTime() < TrainrunSection.MIN_TRAVEL_TIME) {
trainrunSection.setTravelTimeWarning(
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.title:Travel Time less than ${minimumTravelTime}:minimumTravelTime:`,
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.description:Travel time must be greater than or equal to ${minimumTravelTime}:minimumTravelTime:`,
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.title:Travel Time less than ${TrainrunSection.MIN_TRAVEL_TIME}:minimumTravelTime:`,
$localize`:@@app.services.util.trainrunsection-validator.travel-time-less-than-1.description:Travel time must be greater than or equal to ${TrainrunSection.MIN_TRAVEL_TIME}:minimumTravelTime:`,
);
} else {
trainrunSection.resetTravelTimeWarning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ export class EditorToolsViewComponent {
// step(6) Validate all trainrun sections
this.trainrunSectionService.getTrainrunSections().forEach((ts) => {
TrainrunSectionValidator.validateOneSection(ts);
TrainrunSectionValidator.validateTravelTime(ts, this.filterService.getTimeDisplayPrecision());
TrainrunSectionValidator.validateTravelTime(ts);
});
}

Expand Down