summaryrefslogtreecommitdiff
path: root/bin/umlauf-to-dot
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2021-01-12 17:13:41 +0100
committerDaniel Friesel <derf@finalrewind.org>2021-01-12 17:13:41 +0100
commit5490500350ebc9f4fd362767ac5eed011a6531f7 (patch)
treecc7b63ed786989638a966e2674f8b3bc70919def /bin/umlauf-to-dot
parentde4660a30682a19f697d9bbcd4be1875abe625aa (diff)
parent985001e8b4fff4b2c7dcf3ebd8d26a178e1cf561 (diff)
Merge branch 'main' of git.finalrewind.org:var/git_root/db-zugbildung-to-json
Diffstat (limited to 'bin/umlauf-to-dot')
-rwxr-xr-xbin/umlauf-to-dot78
1 files changed, 51 insertions, 27 deletions
diff --git a/bin/umlauf-to-dot b/bin/umlauf-to-dot
index 69472d8..47a766c 100755
--- a/bin/umlauf-to-dot
+++ b/bin/umlauf-to-dot
@@ -52,9 +52,10 @@ my $json = JSON->new->utf8->decode($file_content);
my $map = $json->{train};
-my @train_numbers;
-if ($line) {
+sub build_cycle {
+ my ( $line, $cycle_id ) = @_;
my @queue = ( [ $line, 0 ] );
+ my @train_numbers;
while (@queue) {
my ( $train_number, $distance ) = @{ pop @queue };
@@ -65,8 +66,12 @@ if ($line) {
}
my @candidates;
- push( @candidates, @{ $map->{$train_number}{cycle}{from} // [] } );
- push( @candidates, @{ $map->{$train_number}{cycle}{to} // [] } );
+
+ my $train = $map->{$train_number};
+ if ( my $c = $train->{cycle}{$cycle_id} ) {
+ push( @candidates, @{ $c->{from} // [] } );
+ push( @candidates, @{ $c->{to} // [] } );
+ }
@candidates = uniq @candidates;
@candidates
@@ -79,32 +84,51 @@ if ($line) {
push( @queue, map { [ $_, $distance + 1 ] } @candidates );
}
-}
-else {
- @train_numbers = keys %{$map};
-}
-my @output;
-
-for my $train_number (@train_numbers) {
- for my $from ( @{ $map->{$train_number}{cycle}{from} } ) {
- push(
- @output,
- sprintf( "%s -> %s;",
- format_train( $from, $map->{$from} ),
- format_train( $train_number, $map->{$train_number} ) )
- );
- }
- for my $to ( @{ $map->{$train_number}{cycle}{to} } ) {
- push(
- @output,
- sprintf( "%s -> %s;",
- format_train( $train_number, $map->{$train_number} ),
- format_train( $to, $map->{$to} ) )
- );
+ my @output;
+
+ for my $train_number (@train_numbers) {
+ 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} ) )
+ );
+ }
}
+
+ return @output;
}
+my @cycle_ids;
+
+push( @cycle_ids, keys %{ $map->{$line}{cycle} // {} } );
+
say "digraph Umlauf {";
-say join( "\n", uniq @output );
+
+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} ) );
+
say "}"