summaryrefslogtreecommitdiff
path: root/bin/umlauf-to-dot
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-01-11 22:09:32 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-01-11 22:09:32 +0100
commit985001e8b4fff4b2c7dcf3ebd8d26a178e1cf561 (patch)
tree63ea196307cd6b01a7a19ca71eff5207c0860817 /bin/umlauf-to-dot
parentaaee1881495d0e5bae0e4027b48d2d62d6d5c0f1 (diff)
filter train duplicates by valid date range
Diffstat (limited to 'bin/umlauf-to-dot')
-rwxr-xr-xbin/umlauf-to-dot60
1 files changed, 24 insertions, 36 deletions
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 "}"