From 985001e8b4fff4b2c7dcf3ebd8d26a178e1cf561 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 11 Jan 2021 22:09:32 +0100 Subject: filter train duplicates by valid date range --- bin/umlauf-to-dot | 60 ++++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'bin/umlauf-to-dot') diff --git a/bin/umlauf-to-dot b/bin/umlauf-to-dot index 860c962..47a766c 100755 --- a/bin/umlauf-to-dot +++ b/bin/umlauf-to-dot @@ -67,11 +67,10 @@ sub build_cycle { my @candidates; - for my $train ( @{ $map->{$train_number} } ) { - if ( my $c = $train->{cycle}{$cycle_id} ) { - push( @candidates, @{ $c->{from} // [] } ); - push( @candidates, @{ $c->{to} // [] } ); - } + my $train = $map->{$train_number}; + if ( my $c = $train->{cycle}{$cycle_id} ) { + push( @candidates, @{ $c->{from} // [] } ); + push( @candidates, @{ $c->{to} // [] } ); } @candidates = uniq @candidates; @@ -89,39 +88,30 @@ sub build_cycle { my @output; for my $train_number (@train_numbers) { - for my $train ( @{ $map->{$train_number} } ) { - if ( my $c = $train->{cycle}{$cycle_id} ) { - for my $from ( @{ $c->{from} // [] } ) { - push( - @output, - sprintf( - "%s -> %s;", - format_train( $from, $map->{$from}[0] ), - format_train( - $train_number, $map->{$train_number}[0] - ) - ) - ); - } - for my $to ( @{ $c->{to} // [] } ) { - push( - @output, - sprintf( - "%s -> %s;", - format_train( - $train_number, $map->{$train_number}[0] - ), - format_train( $to, $map->{$to}[0] ) - ) - ); - } + my $train = $map->{$train_number}; + if ( my $c = $train->{cycle}{$cycle_id} ) { + for my $from ( @{ $c->{from} // [] } ) { + push( + @output, + sprintf( "%s -> %s;", + format_train( $from, $map->{$from} ), + format_train( $train_number, $map->{$train_number} ) ) + ); + } + for my $to ( @{ $c->{to} // [] } ) { + push( + @output, + sprintf( "%s -> %s;", + format_train( $train_number, $map->{$train_number} ), + format_train( $to, $map->{$to} ) ) + ); } } if ( $train_number != $line ) { push( @output, sprintf( "%s [shape=box];", - format_train( $train_number, $map->{$train_number}[0] ) ) + format_train( $train_number, $map->{$train_number} ) ) ); } } @@ -131,9 +121,7 @@ sub build_cycle { my @cycle_ids; -for my $train ( @{ $map->{$line} } ) { - push( @cycle_ids, keys %{ $train->{cycle} // {} } ); -} +push( @cycle_ids, keys %{ $map->{$line}{cycle} // {} } ); say "digraph Umlauf {"; @@ -141,6 +129,6 @@ for my $cycle_id (@cycle_ids) { say join( "\n", uniq build_cycle( $line, $cycle_id ) ); } -printf( "%s [style=bold];\n", format_train( $line, $map->{$line}[0] ) ); +printf( "%s [style=bold];\n", format_train( $line, $map->{$line} ) ); say "}" -- cgit v1.2.3