Skip to content

Commit

Permalink
enable trainrunSection departure/arrival assymetry at nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Greiner <[email protected]>
  • Loading branch information
louisgreiner committed Mar 6, 2025
1 parent 1dcbd42 commit 7cc63e6
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 50 deletions.
104 changes: 64 additions & 40 deletions src/app/services/data/trainrun-section-times.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,22 @@ export class TrainrunSectionTimesService {
this.roundAllTimes();
this.removeOffsetAndBackTransformTimeStructure();

this.timeStructure.leftArrivalTime = TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftDepartureTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.leftArrivalTime = TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftDepartureTime,
);
}
if (!this.lockStructure.rightLock) {
this.timeStructure.rightArrivalTime =
this.timeStructure.leftDepartureTime +
(this.timeStructure.travelTime % 60);
this.timeStructure.rightArrivalTime %= 60;
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
}
} else if (
!this.lockStructure.travelTimeLock &&
this.lockStructure.rightLock
Expand Down Expand Up @@ -199,20 +203,24 @@ export class TrainrunSectionTimesService {
this.roundAllTimes();
this.removeOffsetAndBackTransformTimeStructure();

this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
}
if (!this.lockStructure.rightLock) {
this.timeStructure.rightDepartureTime =
this.timeStructure.leftArrivalTime -
(this.timeStructure.travelTime % 60);
this.timeStructure.rightDepartureTime +=
this.timeStructure.rightDepartureTime < 0 ? 60 : 0;
this.timeStructure.rightArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightDepartureTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.rightArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightDepartureTime,
);
}
} else if (
!this.lockStructure.travelTimeLock &&
this.lockStructure.rightLock
Expand Down Expand Up @@ -255,21 +263,25 @@ export class TrainrunSectionTimesService {
this.showWarningTwoLocks = false;
this.roundAllTimes();
this.removeOffsetAndBackTransformTimeStructure();
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
}

if (!this.lockStructure.leftLock) {
this.timeStructure.leftDepartureTime =
this.timeStructure.rightArrivalTime -
(this.timeStructure.travelTime % 60);
this.timeStructure.leftDepartureTime +=
this.timeStructure.leftDepartureTime < 0 ? 60 : 0;
this.timeStructure.leftArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftDepartureTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.leftArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftDepartureTime,
);
}
} else if (
!this.lockStructure.travelTimeLock &&
this.lockStructure.leftLock
Expand Down Expand Up @@ -313,19 +325,23 @@ export class TrainrunSectionTimesService {
this.roundAllTimes();
this.removeOffsetAndBackTransformTimeStructure();

this.timeStructure.rightArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightDepartureTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.rightArrivalTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightDepartureTime,
);
}
if (!this.lockStructure.leftLock) {
this.timeStructure.leftArrivalTime =
this.timeStructure.rightDepartureTime +
(this.timeStructure.travelTime % 60);
this.timeStructure.leftArrivalTime %= 60;
this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
}
} else if (
!this.lockStructure.travelTimeLock &&
this.lockStructure.leftLock
Expand Down Expand Up @@ -374,20 +390,24 @@ export class TrainrunSectionTimesService {
this.timeStructure.rightArrivalTime +=
this.timeStructure.rightArrivalTime < 0 ? 60 : 0;
this.timeStructure.rightArrivalTime %= 60;
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.rightDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.rightArrivalTime,
);
}
} else if (!this.lockStructure.leftLock) {
this.timeStructure.leftArrivalTime =
this.timeStructure.rightDepartureTime + this.timeStructure.travelTime;
this.timeStructure.leftArrivalTime +=
this.timeStructure.leftArrivalTime < 0 ? 60 : 0;
this.timeStructure.leftArrivalTime %= 60;
this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure.leftDepartureTime =
TrainrunsectionHelper.getSymmetricTime(
this.timeStructure.leftArrivalTime,
);
}
} else {
this.showWarningTwoLocks = true;
}
Expand Down Expand Up @@ -482,7 +502,11 @@ export class TrainrunSectionTimesService {
this.selectedTrainrunSection,
this.nodesOrdered,
);
this.timeStructure = Object.assign({}, this.originalTimeStructure);

// TODO: not sure if it's important to keep this, but it breaks the assymetry
if (this.selectedTrainrunSection.getTrainrun().getIsSymmetric()) {
this.timeStructure = Object.assign({}, this.originalTimeStructure);
}

const maxMinutes = 7 * 24 * 60;
if (
Expand Down
6 changes: 6 additions & 0 deletions src/app/services/data/trainrun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ export class TrainrunService {
this.operation.emit(new TrainrunOperation(OperationType.update, trainrun));
}

updateIsSymmetric(trainrun: Trainrun, isSymmetric: boolean) {
this.getTrainrunFromId(trainrun.getId()).setIsSymmetric(isSymmetric);
this.trainrunsUpdated();
this.operation.emit(new TrainrunOperation(OperationType.update, trainrun));
}

getTrainruns(): Trainrun[] {
return Object.assign({}, this.trainrunsStore).trainruns;
}
Expand Down
8 changes: 8 additions & 0 deletions src/app/services/util/trainrunsection.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export class TrainrunsectionValidator {
}

static validateTravelTimeOneSection(trainrunSection: TrainrunSection) {
// if (trainrunSection.getTrainrun().getIsSymmetric()) { // TODO: not working
if (true) {

Check failure on line 15 in src/app/services/util/trainrunsection.validator.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected constant condition
return;
}
const calculatedTargetArrivalTime =
(trainrunSection.getSourceDeparture() + trainrunSection.getTravelTime()) % 60;
if (Math.abs(calculatedTargetArrivalTime - trainrunSection.getTargetArrival()) > 1 / 60) {
Expand All @@ -35,6 +39,10 @@ export class TrainrunsectionValidator {
}

static validateUnsymmetricTimesOneSection(trainrunSection: TrainrunSection) {
// if (trainrunSection.getTrainrun().getIsSymmetric()) { // TODO: not working
if (true) {

Check failure on line 43 in src/app/services/util/trainrunsection.validator.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected constant condition
return;
}
// check for broken symmetry (times)
trainrunSection.resetSourceDepartureWarning();
trainrunSection.resetTargetDepartureWarning();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
<div class="column" style="float: left; width: auto">
<div class="sbb-checkbox-group-vertical">
<sbb-checkbox
[(ngModel)]="getIsSymmetric"
(change)="setIsSymmetric()"
[(ngModel)]="isSymmetric"
(change)="onIsSymmetricChanged()"
style="padding-top: 10px;"
>
{{ 'app.view.dialogs.trainrun-and-section-dialog.trainrun-tab.enableSymmetry' | translate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class TrainrunTabComponent implements OnDestroy {
public selectedCategory: TrainrunCategory;
public selectedTimeCategory: TrainrunTimeCategory;
public trainrunTitle: string;
public isSymmetric: boolean;

private destroyed = new Subject<void>();

Expand Down Expand Up @@ -165,6 +166,10 @@ export class TrainrunTabComponent implements OnDestroy {
}
}

onIsSymmetricChanged() {
this.trainrunService.updateIsSymmetric(this.selectedTrainrun, this.isSymmetric);
}

makeButtonLabel(label: string): string {
if (label.length > 4) {
return label.substring(0, 3) + "...";
Expand Down Expand Up @@ -196,14 +201,6 @@ export class TrainrunTabComponent implements OnDestroy {
this.initializeWithCurrentSelectedTrainrun();
}

getIsSymmetric(): boolean {
return this.selectedTrainrun.getIsSymmetric();
}

setIsSymmetric() {
this.selectedTrainrun.setIsSymmetric(!this.selectedTrainrun.getIsSymmetric());
}

private initializeWithCurrentSelectedTrainrun() {
this.selectedTrainrun = this.trainrunService.getSelectedTrainrun();
if (this.selectedTrainrun !== null) {
Expand All @@ -212,6 +209,7 @@ export class TrainrunTabComponent implements OnDestroy {
this.selectedTimeCategory =
this.selectedTrainrun.getTrainrunTimeCategory();
this.trainrunTitle = this.selectedTrainrun.getTitle();
this.isSymmetric = this.selectedTrainrun.getIsSymmetric();
}
}
}

0 comments on commit 7cc63e6

Please sign in to comment.