summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-12-12 11:04:40 +0100
committerDaniel Friesel <derf@finalrewind.org>2020-12-12 11:04:40 +0100
commit0be1dba86b51ef679e7a76b702ccf63b33cf5f1e (patch)
treeac8e3dd4e690d4adec1442851812e66ed24300b0 /bin
parent67fffbb4d97e8b353f2696273f62da6087ae2fba (diff)
remove type and wagon order for trains with non-constant type
Diffstat (limited to 'bin')
-rwxr-xr-xbin/db-wagenreihung-to-json29
1 files changed, 27 insertions, 2 deletions
diff --git a/bin/db-wagenreihung-to-json b/bin/db-wagenreihung-to-json
index 9827523..d32d5e7 100755
--- a/bin/db-wagenreihung-to-json
+++ b/bin/db-wagenreihung-to-json
@@ -204,16 +204,41 @@ for my $line (@lines) {
for my $train_number ( keys %map ) {
my $wagon_numbers_ok = 1;
+ my $wagon_types_ok = 1;
+ my %bincount;
+ my %type_by_wagon_number;
for my $wagon ( @{ $wagon_map{$train_number} // [] } ) {
- if ( not $wagon->[1] ) {
+ my ( $wagon_type, $wagon_number ) = @{$wagon};
+ if ( not $wagon_number ) {
$wagon_numbers_ok = 0;
}
+ else {
+ $bincount{$wagon_number}++;
+ push( @{ $type_by_wagon_number{$wagon_number} }, $wagon_type );
+ }
}
if ($wagon_numbers_ok) {
for my $wagon ( @{ $wagon_map{$train_number} // [] } ) {
- $map{$train_number}{wagon}{ $wagon->[1] } = $wagon->[0];
+ my ( $wagon_type, $wagon_number ) = @{$wagon};
+ $map{$train_number}{wagon}{ $wagon->[1] } = $wagon_type;
+ if ( $bincount{$wagon_number} > 1 ) {
+ if ( $type_by_wagon_number{$wagon_number}[0] ne
+ $type_by_wagon_number{$wagon_number}[1] )
+ {
+ $wagon_types_ok = 0;
+ }
+ }
}
}
+ if ( not $wagon_types_ok ) {
+
+ # train type may differ depending on date of week or similar. We don't
+ # parse/handle that yet.
+ delete $map{$train_number}{type};
+ delete $map{$train_number}{short};
+ delete $map{$train_number}{wagon};
+ delete $map{$train_number}{has_wagon};
+ }
}
# use canonical output (i.e., sort hash keys) to allow for easy diffing.