summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-21 18:27:36 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-21 18:27:36 +0100
commit0a89a0a4938b369a75ddbae16fc530cc8cb7c7f9 (patch)
treee2c0f09dd061515dbf936cb8ab5c9378ba7e342a
parent9c0d9035d1ec339da1c4fa885b1f7ffaff0d9f59 (diff)
parse train attributes
-rw-r--r--README.md32
-rwxr-xr-xbin/db-zugbildung-to-json47
-rw-r--r--schema.yml32
3 files changed, 105 insertions, 6 deletions
diff --git a/README.md b/README.md
index d7e142f..0376efe 100644
--- a/README.md
+++ b/README.md
@@ -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;
diff --git a/schema.yml b/schema.yml
index 87746aa..3fc21ec 100644
--- a/schema.yml
+++ b/schema.yml
@@ -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: