From b255c541c539398414df9af152bb85bfaa8cd5fc Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Dec 2020 18:37:18 +0100 Subject: attr: translate DS100 to ordinary station name --- README.md | 5 +++-- bin/db-zugbildung-to-json | 19 +++++++++++++++++-- schema.yml | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0376efe..d18a4a4 100644 --- a/README.md +++ b/README.md @@ -202,13 +202,14 @@ passenger service. Station names may be surrounded by brackets. "brakingPercentage": 177, "length": 402, "series": "406", - "station": "FF", + "station": "Basel SBB", "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. +identical in each variant. *station* is translated from DS100 to a station +name; its meaning is unknown. #### schedules diff --git a/bin/db-zugbildung-to-json b/bin/db-zugbildung-to-json index 09bd3c5..a98af93 100755 --- a/bin/db-zugbildung-to-json +++ b/bin/db-zugbildung-to-json @@ -13,6 +13,7 @@ use File::Slurp qw(write_file); use IPC::Run3; use JSON; use List::Util qw(uniq); +use Travel::Status::DE::IRIS::Stations; sub show_usage { my ($exit_code) = @_; @@ -32,6 +33,12 @@ my %month = map { ( $months[$_] => $_ ) } ( 0 .. $#months ); my ( $valid, $valid_from, $valid_through ); my $year; +my %ds100_to_name; + +for my $station ( Travel::Status::DE::IRIS::Stations::get_stations() ) { + $ds100_to_name{ $station->[0] } = $station->[1]; +} + sub parse_weekday_range { my ($range) = @_; my $ret = [ ( \0 ) x 7 ]; @@ -577,8 +584,16 @@ for my $train ( values %map ) { $setup{length} = 0 + $1; } if ( %setup and $line =~ m{ ^ \s* ([+]? [A-Z ]{1,7}) }x ) { - $setup{station} = $1; - $setup{station} =~ s{\s+$}{}; + my $station = $1; + $station =~ s{\s+$}{}; + my $special = ( $station =~ s{^[+]}{} ); + if ( $ds100_to_name{$station} ) { + $station = $ds100_to_name{$station}; + } + if ($special) { + $station = "+${station}"; + } + $setup{station} = $station; } push( @setups, {%setup} ); } diff --git a/schema.yml b/schema.yml index 3fc21ec..187fb0a 100644 --- a/schema.yml +++ b/schema.yml @@ -120,8 +120,8 @@ components: description: series of second powercar (if present) station: type: string - example: "FF" - description: DS100 station code, details unknown + example: "Basel SBB" + description: station name, details unknown vmax: type: integer example: 300 -- cgit v1.2.3