Skip to content

Commit

Permalink
feat: migrate originDestination connectionPenalty to netzgrafikDto (#314
Browse files Browse the repository at this point in the history
)

* feat: migrate originDestination connectionPenalty to netzgrafixDto

* fixup! feat: migrate originDestination connectionPenalty to netzgrafixDto
  • Loading branch information
shenriotpro authored Oct 17, 2024
1 parent d67445a commit ce3f90d
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 4 deletions.
23 changes: 22 additions & 1 deletion documentation/DATA_MODEL_JSON.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ More details about TimeLock
"netzgrafikColors": [],
"trainrunCategories": [],
"trainrunFrequencies": [],
"trainrunTimeCategories": []
"trainrunTimeCategories": [],
"analyticsSettings": {}
}
```

Expand Down Expand Up @@ -600,6 +601,26 @@ Define the dayTimeIntervalElement
```
- **from** : interval starts at time (include), in minute : numeric
- **to** : interval ends at time (include), in minute : numeric
</details>

<details>
<summary>
analyticsSettings: Contains settings for analytics features, such as originDestination matrix.
</summary>


```JSON
"analyticsSettings": {
"originDestinationSettings": {
"connectionPenalty": 5
},
}
```

- **connectionPenalty**: Cost to add for each connection, in minute : numeric



</details>

---
Expand Down
10 changes: 10 additions & 0 deletions src/app/data-structures/business.data.structures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,15 @@ export interface Haltezeit {
no_halt: boolean; // no halt per default
}

export interface OriginDestinationSettingsDto {
// TODO: we may want a UI to display/edit this.
connectionPenalty: number; // the cost to add for each connection, in minutes
}

export interface AnalyticsSettingsDto {
originDestinationSettings: OriginDestinationSettingsDto;
}

/**
* Groups Meta data in exported JSON / internal data structure (global properties for a project)
*/
Expand All @@ -260,6 +269,7 @@ export interface MetadataDto {
trainrunFrequencies: TrainrunFrequency[];
trainrunTimeCategories: TrainrunTimeCategory[];
netzgrafikColors: NetzgrafikColorDto[];
analyticsSettings: AnalyticsSettingsDto;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/app/sample-netzgrafik/netzgrafik.default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ export class NetzgrafikDefault {
trainruns: [],
resources: [],
metadata: {
analyticsSettings: {
originDestinationSettings: {
connectionPenalty: 5,
}
},
trainrunCategories: [
{
id: 0,
Expand Down
5 changes: 5 additions & 0 deletions src/app/utils/data-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export class DataMigration {
NetzgrafikDefault.getDefaultNetzgrafik().metadata.netzgrafikColors;
}

if (netzgrafikDto.metadata.analyticsSettings === undefined) {
netzgrafikDto.metadata.analyticsSettings =
NetzgrafikDefault.getDefaultNetzgrafik().metadata.analyticsSettings;
}

if (netzgrafikDto.freeFloatingTexts === undefined) {
netzgrafikDto.freeFloatingTexts =
NetzgrafikDefault.getDefaultNetzgrafik().freeFloatingTexts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,6 @@ export class EditorToolsViewComponent {
// Split trainruns are not supported at the moment:
// https://github.com/SchweizerischeBundesbahnen/netzgrafik-editor-frontend/issues/285
private convertToOriginDestinationCSV(): string {
// The cost to add for each connection.
// TODO: this may belong to the grafix metadata.
const connectionPenalty = 5;
// Duration of the schedule to consider (in minutes).
// TODO: ideally this would be 24 hours, but performance is a concern.
const timeLimit = 10*60;
Expand All @@ -514,6 +511,9 @@ export class EditorToolsViewComponent {
headers.push($localize`:@@app.view.editor-side-view.editor-tools-view-component.connections:Connections`);
headers.push($localize`:@@app.view.editor-side-view.editor-tools-view-component.totalCost:Total cost`);

const metadata = this.dataService.getNetzgrafikDto().metadata;
// The cost to add for each connection.
const connectionPenalty = metadata.analyticsSettings.originDestinationSettings.connectionPenalty;
const nodes = this.nodeService.getNodes();
const selectedNodes = this.nodeService.getSelectedNodes();
const odNodes = selectedNodes.length > 0 ? selectedNodes : this.nodeService.getVisibleNodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ export class NetzgrafikUnitTestingReconnectTrainrunSection {
},
],
metadata: {
analyticsSettings: {
originDestinationSettings: {
connectionPenalty: 5,
}
},
trainrunCategories: [
{
id: 0,
Expand Down
5 changes: 5 additions & 0 deletions src/integration-testing/netzgrafik.unit.testing.od.matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,11 @@ export class NetzgrafikUnitTestingOdMatrix {
}
],
"metadata": {
"analyticsSettings": {
"originDestinationSettings": {
"connectionPenalty": 5,
}
},
"trainrunCategories": [
{
"id": 0,
Expand Down
5 changes: 5 additions & 0 deletions src/integration-testing/netzgrafik.unit.testing.transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,11 @@ export class NetzgrafikUnitTestingTransition {
},
],
metadata: {
analyticsSettings: {
originDestinationSettings: {
connectionPenalty: 5,
}
},
trainrunCategories: [
{
id: 0,
Expand Down
5 changes: 5 additions & 0 deletions src/integration-testing/netzgrafik.unit.testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@ export class NetzgrafikUnitTesting {
],
resources: [],
metadata: {
analyticsSettings: {
originDestinationSettings: {
connectionPenalty: 5,
}
},
trainrunCategories: [
{
id: 0,
Expand Down

0 comments on commit ce3f90d

Please sign in to comment.