summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/db-wagenreihung-to-json24
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} );