diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-12-11 22:51:56 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-12-11 22:51:56 +0100 |
commit | 840e56fa13a76b46935ce34cd5e5fba0d9373772 (patch) | |
tree | f4f24b755b2a83b9c09c5a3a71490215e32a1268 | |
parent | e6b65a276baffc6910568f095a54069c20ee8014 (diff) |
add wagon number->type map; fix station names being detected a wagon types
-rwxr-xr-x | bin/db-wagenreihung-to-json | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/bin/db-wagenreihung-to-json b/bin/db-wagenreihung-to-json index ef71aa0..f61e5bc 100755 --- a/bin/db-wagenreihung-to-json +++ b/bin/db-wagenreihung-to-json @@ -54,6 +54,7 @@ my @lines = split( qr{\n}, $wr_txt ); my ( $type, $number ); my %map; +my %wagon_map; for my $line (@lines) { @@ -153,10 +154,31 @@ for my $line (@lines) { } } - if ( $number and $line =~ m{^\d*\s+(D?(A|AB|B|W)R?D?[impvw]\S*)} ) { + if ( $number + and $line + =~ m{ ^ \d* \s{1,10} (?<type> D? (A|AB|B|W) R? D? [aeimpvw] \S* ) \s* (?<number> \d+ )? (?: $ | \s{6} ) }x + ) + { + push( @{ $wagon_map{$number} }, [ $+{type}, $+{number} ] ); + + #$map{$number}{has_wagon}{$1} = \1; $map{$number}{wagons}{$1} = \1; } } +for my $train_number ( keys %map ) { + my $wagon_numbers_ok = 1; + for my $wagon ( @{ $wagon_map{$train_number} // [] } ) { + if ( not $wagon->[1] ) { + $wagon_numbers_ok = 0; + } + } + if ($wagon_numbers_ok) { + for my $wagon ( @{ $wagon_map{$train_number} // [] } ) { + $map{$train_number}{wagon}{ $wagon->[1] } = $wagon->[0]; + } + } +} + # use canonical output (i.e., sort hash keys) to allow for easy diffing. say JSON->new->utf8->canonical->encode( {%map} ); |