summaryrefslogtreecommitdiff
path: root/bin
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 /bin
parent9c0d9035d1ec339da1c4fa885b1f7ffaff0d9f59 (diff)
parse train attributes
Diffstat (limited to 'bin')
-rwxr-xr-xbin/db-zugbildung-to-json47
1 files changed, 47 insertions, 0 deletions
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;