From 2accf39cfec2fb023796a07f3de264b1ffc5a96f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 21 Dec 2020 13:57:06 +0100 Subject: remove wagon list if it contains duplicate wagon numbers --- bin/db-zugbildung-to-json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/db-zugbildung-to-json b/bin/db-zugbildung-to-json index d6a3832..f5439d1 100755 --- a/bin/db-zugbildung-to-json +++ b/bin/db-zugbildung-to-json @@ -552,6 +552,7 @@ for my $train ( values %map ) { for my $train_number ( keys %map ) { my $wagon_numbers_ok = 1; my $wagon_types_ok = 1; + my $wagon_list_ok = 1; my %bincount; my %type_by_wagon_number; for my $wagon ( @{ $wagon_map{$train_number} // [] } ) { @@ -580,13 +581,12 @@ for my $train_number ( keys %map ) { } if ( $bincount{$wagon_number} > 1 ) { + $wagon_list_ok = 0; if ( $type_by_wagon_number{$wagon_number}[0] ne $type_by_wagon_number{$wagon_number}[1] ) { $wagon_types_ok = 0; } - - # TODO else -> wagon_list_ok = 0 ? } } } @@ -599,6 +599,12 @@ for my $train_number ( keys %map ) { delete $map{$train_number}{wagons}; delete $map{$train_number}{hasWagon}; } + elsif ( not $wagon_list_ok ) { + + # train type appears to be correct, but the list contains duplicates + # (e.g. due to unhandled schedule variants) + delete $map{$train_number}{wagons}; + } } # Cleanup -- cgit v1.2.3