diff options
-rw-r--r-- | README.md | 32 | ||||
-rwxr-xr-x | bin/db-zugbildung-to-json | 47 | ||||
-rw-r--r-- | schema.yml | 32 |
3 files changed, 105 insertions, 6 deletions
@@ -83,13 +83,15 @@ as noted in the PDF file. "10": { "rawType": "ICE-W", "type": "ICE 3", - "shortType": "3" /* optional */, - "name": "ICE International", /* optional */ + "shortType": "3", + "name": "ICE International", "route": { /* scheduled route */ }, - "schedules": [ /* scheduled service days and route deviations */ ] /* optional */, - "cycle": { /* cycle ("Umlauf") data */ } /* optional */, - "hasWagon": { /* wagon type map */ } /* optional */, - "wagons": [ /* wagon list */ ] /* optional */, + "commonAttr": { /* train/powercar attributes */ }, + "attrVariants": [ { /* train/powercar attributes */ } /* ... */ ], + "schedules": [ /* scheduled service days and route deviations */ ], + "cycle": { /* cycle ("Umlauf") data */ }, + "hasWagon": { /* wagon type map */ }, + "wagons": [ /* wagon list */ ], } } ``` @@ -99,6 +101,9 @@ long-distance trains, but may be used by other european operators as well. For instance, the IC services Amsterdam – Berlin and Koebenhavns – Aarhus often use identical three-letter numbers. +rawType, type, and route are always present. The remaining properties are +optional. + #### rawType The train type as specified in the PDF file, e.g. **ICE-A**, **IC**, or @@ -190,6 +195,21 @@ names used in iris-tts or HAFAS. A missing preStart / postEnd entry does not imply that the train is prepared / parked at the first / last station with passenger service. Station names may be surrounded by brackets. +#### train/powercar attributes + +```js +{ + "brakingPercentage": 177, + "length": 402, + "series": "406", + "station": "FF", + "vmax": 300 +} +``` + +Taken as-is from the PDF file. commonAttr contains only properties which are +identical in each variant. *station* is a DS100 identifier with unknown meaning. + #### schedules *work in progress* diff --git a/bin/db-zugbildung-to-json b/bin/db-zugbildung-to-json index 849d685..09bd3c5 100755 --- a/bin/db-zugbildung-to-json +++ b/bin/db-zugbildung-to-json @@ -549,6 +549,53 @@ for my $train ( values %map ) { } } +for my $train ( values %map ) { + + if ( not $train->{details} ) { + next; + } + + my @details = @{ $train->{details} // [] }; + my %common_setup; + my @setups; + + for my $line (@details) { + my %setup; + if ( $line =~ m{ Tfz1:(\d+) }x ) { + $setup{series} = $1; + } + if ( $line =~ m{ Tfz2:(\d+) }x ) { + $setup{series2} = $1; + } + if ( $line =~ m{ Hg(\d+) }x ) { + $setup{vmax} = 0 + $1; + } + if ( $line =~ m{ BrH(\d+) }x ) { + $setup{brakingPercentage} = 0 + $1; + } + if ( $line =~ m{ (\d+)m }x ) { + $setup{length} = 0 + $1; + } + if ( %setup and $line =~ m{ ^ \s* ([+]? [A-Z ]{1,7}) }x ) { + $setup{station} = $1; + $setup{station} =~ s{\s+$}{}; + } + push( @setups, {%setup} ); + } + + for my $key (qw(brakingPercentage length series series2 vmax)) { + if ( ( my @uniq = uniq grep { $_ } map { $_->{$key} } @setups ) == 1 ) { + $common_setup{$key} = $key eq 'series' ? $uniq[0] : 0 + $uniq[0]; + } + } + + delete $train->{details}; + if (%common_setup) { + $train->{commonAttr} = {%common_setup}; + } + $train->{attrVariants} = [@setups]; +} + for my $train_number ( keys %map ) { my $wagon_numbers_ok = 1; my $wagon_types_ok = 1; @@ -66,6 +66,12 @@ components: description: true if this is an empty train without passenger service ("Leerfahrt") route: $ref: '#/components/schemas/route' + commonAttr: + $ref: '#/components/schemas/trainAttr' + attrVariants: + type: array + items: + $ref: '#/components/schemas/trainAttr' cycle: $ref: '#/components/schemas/cycle' hasWagon: @@ -94,6 +100,32 @@ components: postEnd: type: string description: station where the train is parked + trainAttr: + type: object + properties: + brakingPercentage: + type: integer + example: 177 + description: Bremshundertstel + length: + type: integer + example: 402 + description: train length (including powercar) + series: + type: string + example: "406" + description: powercar series + series2: + type: string + description: series of second powercar (if present) + station: + type: string + example: "FF" + description: DS100 station code, details unknown + vmax: + type: integer + example: 300 + description: rated maximum speed in km/h cycle: type: object properties: |