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
385 changes: 385 additions & 0 deletions GTFSImportAnforderungsDokument.md

Large diffs are not rendered by default.

1,019 changes: 1,019 additions & 0 deletions documentation/GTFS_IMPORT.md

Large diffs are not rendered by default.

6,528 changes: 3,460 additions & 3,068 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@angular/platform-browser-dynamic": "^19.2.25",
"@angular/router": "^19.2.25",
"@sbb-esta/angular": "^19.1.6",
"@zip.js/zip.js": "^2.8.26",
"angular-oauth2-oidc": "^19.0.0",
"angular-server-side-configuration": "^19.0.1",
"d3": "^5.16.0",
Expand Down
8 changes: 8 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import {SbbBreadcrumbModule} from "@sbb-esta/angular/breadcrumb";
import {SbbButtonModule} from "@sbb-esta/angular/button";
import {SbbCheckboxModule} from "@sbb-esta/angular/checkbox";
import {SbbChipsModule} from "@sbb-esta/angular/chips";
import {SbbDatepickerModule} from "@sbb-esta/angular/datepicker";
import {SbbDialogModule} from "@sbb-esta/angular/dialog";
import {SbbFormFieldModule} from "@sbb-esta/angular/form-field";
import {SbbFileSelectorModule} from "@sbb-esta/angular/file-selector";
import {SbbHeaderLeanModule} from "@sbb-esta/angular/header-lean";
import {SbbIconModule} from "@sbb-esta/angular/icon";
import {SbbInputModule} from "@sbb-esta/angular/input";
import {SbbLoadingIndicatorModule} from "@sbb-esta/angular/loading-indicator";
import {SbbMenuModule} from "@sbb-esta/angular/menu";
import {SbbNotificationToastModule} from "@sbb-esta/angular/notification-toast";
import {SbbPaginationModule} from "@sbb-esta/angular/pagination";
import {SbbRadioButtonModule} from "@sbb-esta/angular/radio-button";
import {SbbSelectModule} from "@sbb-esta/angular/select";
import {SbbSidebarModule} from "@sbb-esta/angular/sidebar";
Expand Down Expand Up @@ -78,6 +81,7 @@ import {EditorEditToolsViewComponent} from "./view/editor-edit-tools-view-compon
import {FilterableLabelFormComponent} from "./view/dialogs/filterable-labels-dialog/filterable-labels-form/filterable-label-form.component";
import {FilterableLabelDialogComponent} from "./view/dialogs/filterable-labels-dialog/filterable-label-dialog.component";
import {EditorToolsViewComponent} from "./view/editor-tools-view-component/editor-tools-view.component";
import {GtfsImportDialogsComponent} from "./view/editor-tools-view-component/gtfs-import-dialogs/gtfs-import-dialogs.component";
import {NoteDialogComponent} from "./view/dialogs/note-dialog/note-dialog.component";
import {NoteFormComponent} from "./view/dialogs/note-dialog/note-form/note-form.component";
import {HtmlEditorComponent} from "./view/dialogs/note-dialog/htmlEditor/html-editor.component";
Expand Down Expand Up @@ -112,6 +116,7 @@ import {TimeStepperComponent} from "./view/dialogs/trainrun-and-section-dialog/t

@NgModule({
declarations: [
GtfsImportDialogsComponent,
AppComponent,
EditorMainViewComponent,
ColumnLayoutComponent,
Expand Down Expand Up @@ -244,6 +249,9 @@ import {TimeStepperComponent} from "./view/dialogs/trainrun-and-section-dialog/t
SbbTooltipModule,
SbbBreadcrumbModule,
SbbAutocompleteModule,
SbbDatepickerModule,
SbbFormFieldModule,
SbbPaginationModule,
I18nModule,
],
providers: [
Expand Down
11 changes: 5 additions & 6 deletions src/app/core/i18n/i18n.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgModule, LOCALE_ID, inject, provideAppInitializer} from "@angular/core";
import {NgModule, LOCALE_ID, provideAppInitializer, inject} from "@angular/core";
import {CommonModule} from "@angular/common";
import {TranslatePipe} from "./translate.pipe";
import {I18nService} from "./i18n.service";
Expand All @@ -9,11 +9,10 @@ import {I18nService} from "./i18n.service";
providers: [
I18nService,
provideAppInitializer(() => {
const initializerFn = (
(i18nService: I18nService) => () =>
i18nService.setLanguage()
)(inject(I18nService));
return initializerFn();
const dep0 = inject(I18nService);
const initializerFactory = (i18nService: I18nService) => () => i18nService.setLanguage();
const initializer = initializerFactory(dep0);
return typeof initializer === "function" ? initializer() : initializer;
}),
{
// Set the runtime locale for the app
Expand Down
174 changes: 174 additions & 0 deletions src/app/services/data/gtfs-converter.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import {GTFSConverterService} from "./gtfs-converter.service";
import {TrainrunSectionDto} from "../../data-structures/business.data.structures";
import {TrainrunSectionText} from "../../data-structures/technical.data.structures";

describe("GTFSConverterService topology consolidation", () => {
let service: GTFSConverterService;

beforeEach(() => {
service = new GTFSConverterService();
});

it("replaces all sections of one undirected basis edge atomically", () => {
const trainrunSections: TrainrunSectionDto[] = [
createSection(1, 1, 2, 1, 1),
createSection(2, 2, 3, 1, 2),
createSection(3, 3, 4, 1, 3),
createSection(4, 1, 4, 5, 10),
createSection(5, 4, 1, 5, 11),
];

const result = (service as any).applyTopologyConsolidationToTrainrunSections(
trainrunSections,
[],
{
topologyDetourPercent: 50,
topologyDetourAbsoluteMinutes: 0,
topologyMinEdgeTravelTime: 1,
topologyMaxIterations: 10,
},
);

expect(result.graphChanged).toBeTrue();
expect(result.consolidatedEdges).toBe(1);
expect(result.replacedSections).toBe(2);
expect(result.insertedSections).toBe(4);
expect(trainrunSections.length).toBe(9);

const trainrun10Sections = trainrunSections.filter((section) => section.trainrunId === 10);
expect(trainrun10Sections.map(toEdge)).toEqual(["1→2", "2→3", "3→4"]);
expect(trainrun10Sections.map((section) => section.numberOfStops)).toEqual([1, 1, 1]);
expect(trainrun10Sections.map((section) => section.travelTime.time)).toEqual([2, 2, 1]);

const trainrun11Sections = trainrunSections.filter((section) => section.trainrunId === 11);
expect(trainrun11Sections.map(toEdge)).toEqual(["4→3", "3→2", "2→1"]);
expect(trainrun11Sections.map((section) => section.numberOfStops)).toEqual([1, 1, 1]);
expect(trainrun11Sections.map((section) => section.travelTime.time)).toEqual([2, 2, 1]);

const remainingDirectSections = trainrunSections.filter(
(section) =>
(section.sourceNodeId === 1 && section.targetNodeId === 4) ||
(section.sourceNodeId === 4 && section.targetNodeId === 1),
);
expect(remainingDirectSections.length).toBe(0);
});

it("does not replace a section when minimum edge travel time A makes interpolation impossible", () => {
const trainrunSections: TrainrunSectionDto[] = [
createSection(1, 1, 2, 1, 1),
createSection(2, 2, 3, 1, 2),
createSection(3, 3, 4, 1, 3),
createSection(4, 1, 4, 5, 10),
];

const result = (service as any).applyTopologyConsolidationToTrainrunSections(
trainrunSections,
[],
{
topologyDetourPercent: 200,
topologyDetourAbsoluteMinutes: 10,
topologyMinEdgeTravelTime: 2,
topologyMaxIterations: 10,
},
);

expect(result.graphChanged).toBeFalse();
expect(result.consolidatedEdges).toBe(0);
expect(result.replacedSections).toBe(0);
expect(trainrunSections.map(toEdge)).toEqual(["1→2", "2→3", "3→4", "1→4"]);
expect(trainrunSections.find((section) => section.id === 4)?.travelTime.time).toBe(5);
});

it("does not replace a section through an intermediate node already used elsewhere in the same trainrun", () => {
const trainrunSections: TrainrunSectionDto[] = [
createSection(1, 1, 2, 2, 20),
createSection(2, 2, 3, 2, 20),
createSection(3, 3, 4, 4, 20),
createSection(4, 2, 5, 1, 30),
createSection(5, 5, 4, 1, 31),
];

const result = (service as any).applyTopologyConsolidationToTrainrunSections(
trainrunSections,
[],
{
topologyDetourPercent: 100,
topologyDetourAbsoluteMinutes: 0,
topologyMinEdgeTravelTime: 1,
topologyMaxIterations: 10,
},
);

expect(result.graphChanged).toBeFalse();
expect(result.consolidatedEdges).toBe(0);
expect(trainrunSections.filter((section) => section.trainrunId === 20).map(toEdge)).toEqual([
"1→2",
"2→3",
"3→4",
]);
});
});

function createSection(
id: number,
sourceNodeId: number,
targetNodeId: number,
travelTime: number,
trainrunId: number,
): TrainrunSectionDto {
const sourceDeparture = 0;
const targetArrival = travelTime % 60;

return {
id,
sourceNodeId,
sourcePortId: 0,
targetNodeId,
targetPortId: 0,
sourceSymmetry: false,
targetSymmetry: false,
sourceArrival: createTimeLock((60 - sourceDeparture) % 60),
sourceDeparture: createTimeLock(sourceDeparture),
targetArrival: createTimeLock(targetArrival),
targetDeparture: createTimeLock((60 - targetArrival) % 60),
travelTime: createTimeLock(travelTime),
backwardTravelTime: createTimeLock(travelTime),
numberOfStops: 0,
trainrunId,
resourceId: 0,
specificTrainrunSectionFrequencyId: null,
path: {
path: [],
textPositions: createTextPositions(),
},
warnings: [],
};
}

function createTimeLock(time: number) {
return {
time,
consecutiveTime: 0,
lock: false,
warning: undefined,
timeFormatter: undefined,
};
}

function createTextPositions() {
const point = {x: 0, y: 0};
return {
[TrainrunSectionText.SourceArrival]: point,
[TrainrunSectionText.SourceDeparture]: point,
[TrainrunSectionText.TargetArrival]: point,
[TrainrunSectionText.TargetDeparture]: point,
[TrainrunSectionText.TrainrunSectionName]: point,
[TrainrunSectionText.TrainrunSectionTravelTime]: point,
[TrainrunSectionText.TrainrunSectionBackwardTravelTime]: point,
[TrainrunSectionText.TrainrunSectionNumberOfStops]: point,
};
}

function toEdge(section: TrainrunSectionDto): string {
return `${section.sourceNodeId}→${section.targetNodeId}`;
}
Loading