review: hide blocks without data

This commit is contained in:
Daniel Friesel 2022-12-27 17:56:44 +01:00
parent ed63cae012
commit 9dfe1c60ab
No known key found for this signature in database
GPG key ID: 100D5BFB5166E005
2 changed files with 137 additions and 107 deletions

View file

@ -67,18 +67,19 @@ sub min_to_human {
push( @ret, "$minutes Minuten" ); push( @ret, "$minutes Minuten" );
} }
elsif ($minutes) { elsif ($minutes) {
push( @ret, "1 Minute" ); push( @ret, '1 Minute' );
}
if ( @ret == 0 ) {
return '0 Minuten';
} }
if ( @ret == 1 ) { if ( @ret == 1 ) {
return $ret[0]; return $ret[0];
} }
if ( @ret > 2 ) { my $last = pop(@ret);
my $last = pop(@ret); return join( ', ', @ret ) . " und $last";
return join( ', ', @ret ) . " und $last";
}
return "$ret[0] und $ret[1]";
} }
sub new { sub new {
@ -1062,10 +1063,6 @@ sub compute_review {
my %review; my %review;
my $trains_per_journey = $stats->{num_trains} / $stats->{num_journeys};
my $avg_change_count = sprintf( '%.1f', $trains_per_journey - 1 );
my $min_total = $stats->{min_travel_real} + $stats->{min_interchange_real};
for my $journey (@journeys) { for my $journey (@journeys) {
if ( $journey->{cancelled} ) { if ( $journey->{cancelled} ) {
$num_cancelled += 1; $num_cancelled += 1;
@ -1192,6 +1189,7 @@ sub compute_review {
$review{km_circle_h} =~ tr{.}{,}; $review{km_circle_h} =~ tr{.}{,};
$review{km_diag_h} =~ tr{.}{,}; $review{km_diag_h} =~ tr{.}{,};
my $min_total = $stats->{min_travel_real} + $stats->{min_interchange_real};
$review{traveling_min_total} = $min_total; $review{traveling_min_total} = $min_total;
$review{traveling_percentage_year} $review{traveling_percentage_year}
= sprintf( "%.1f%%", $min_total * 100 / 525948.77 ); = sprintf( "%.1f%%", $min_total * 100 / 525948.77 );
@ -1224,73 +1222,95 @@ sub compute_review {
= sprintf( '%.0f', $stats->{delay_arr} / $stats->{num_trains} ); = sprintf( '%.0f', $stats->{delay_arr} / $stats->{num_trains} );
$review{typical_delay_arr_h} = min_to_human( $review{typical_delay_arr} ); $review{typical_delay_arr_h} = min_to_human( $review{typical_delay_arr} );
$review{longest_t_time} = min_to_human( $longest_t->{rt_duration} / 60 ); if ($longest_t) {
$review{longest_t_type} = $longest_t->{type}; $review{longest_t_time}
$review{longest_t_lineno} = $longest_t->{line} // $longest_t->{no}; = min_to_human( $longest_t->{rt_duration} / 60 );
$review{longest_t_from} = $longest_t->{from_name}; $review{longest_t_type} = $longest_t->{type};
$review{longest_t_to} = $longest_t->{to_name}; $review{longest_t_lineno} = $longest_t->{line} // $longest_t->{no};
$review{longest_t_id} = $longest_t->{id}; $review{longest_t_from} = $longest_t->{from_name};
$review{longest_t_to} = $longest_t->{to_name};
$review{longest_t_id} = $longest_t->{id};
}
$review{longest_km_km} = sprintf( '%.0f', $longest_km->{km_route} ); if ($longest_km) {
$review{longest_km_type} = $longest_km->{type}; $review{longest_km_km} = sprintf( '%.0f', $longest_km->{km_route} );
$review{longest_km_lineno} = $longest_km->{line} // $longest_km->{no}; $review{longest_km_type} = $longest_km->{type};
$review{longest_km_from} = $longest_km->{from_name}; $review{longest_km_lineno} = $longest_km->{line} // $longest_km->{no};
$review{longest_km_to} = $longest_km->{to_name}; $review{longest_km_from} = $longest_km->{from_name};
$review{longest_km_id} = $longest_km->{id}; $review{longest_km_to} = $longest_km->{to_name};
$review{longest_km_id} = $longest_km->{id};
}
$review{shortest_t_time} = min_to_human( $shortest_t->{rt_duration} / 60 ); if ($shortest_t) {
$review{shortest_t_type} = $shortest_t->{type}; $review{shortest_t_time}
$review{shortest_t_lineno} = $shortest_t->{line} // $shortest_t->{no}; = min_to_human( $shortest_t->{rt_duration} / 60 );
$review{shortest_t_from} = $shortest_t->{from_name}; $review{shortest_t_type} = $shortest_t->{type};
$review{shortest_t_to} = $shortest_t->{to_name}; $review{shortest_t_lineno} = $shortest_t->{line} // $shortest_t->{no};
$review{shortest_t_id} = $shortest_t->{id}; $review{shortest_t_from} = $shortest_t->{from_name};
$review{shortest_t_to} = $shortest_t->{to_name};
$review{shortest_t_id} = $shortest_t->{id};
}
$review{shortest_km_m} = sprintf( '%.0f', $shortest_km->{km_route} * 1000 ); if ($shortest_km) {
$review{shortest_km_type} = $shortest_km->{type}; $review{shortest_km_m}
$review{shortest_km_lineno} = $shortest_km->{line} // $shortest_km->{no}; = sprintf( '%.0f', $shortest_km->{km_route} * 1000 );
$review{shortest_km_from} = $shortest_km->{from_name}; $review{shortest_km_type} = $shortest_km->{type};
$review{shortest_km_to} = $shortest_km->{to_name}; $review{shortest_km_lineno} = $shortest_km->{line}
$review{shortest_km_id} = $shortest_km->{id}; // $shortest_km->{no};
$review{shortest_km_from} = $shortest_km->{from_name};
$review{shortest_km_to} = $shortest_km->{to_name};
$review{shortest_km_id} = $shortest_km->{id};
}
$review{most_delayed_type} = $most_delayed->{type}; if ($most_delayed) {
$review{most_delayed_delay_dep} $review{most_delayed_type} = $most_delayed->{type};
= min_to_human( $most_delayed->{delay_dep} ); $review{most_delayed_delay_dep}
$review{most_delayed_delay_arr} = min_to_human( $most_delayed->{delay_dep} );
= min_to_human( $most_delayed->{delay_arr} ); $review{most_delayed_delay_arr}
$review{most_delayed_lineno} = $most_delayed->{line} // $most_delayed->{no}; = min_to_human( $most_delayed->{delay_arr} );
$review{most_delayed_from} = $most_delayed->{from_name}; $review{most_delayed_lineno} = $most_delayed->{line}
$review{most_delayed_to} = $most_delayed->{to_name}; // $most_delayed->{no};
$review{most_delayed_id} = $most_delayed->{id}; $review{most_delayed_from} = $most_delayed->{from_name};
$review{most_delayed_to} = $most_delayed->{to_name};
$review{most_delayed_id} = $most_delayed->{id};
}
$review{most_delay_type} = $most_delay->{type}; if ($most_delay) {
$review{most_delay_delay_dep} = $most_delay->{delay_dep}; $review{most_delay_type} = $most_delay->{type};
$review{most_delay_delay_arr} = $most_delay->{delay_arr}; $review{most_delay_delay_dep} = $most_delay->{delay_dep};
$review{most_delay_sched_time} $review{most_delay_delay_arr} = $most_delay->{delay_arr};
= min_to_human( $most_delay->{sched_duration} / 60 ); $review{most_delay_sched_time}
$review{most_delay_real_time} = min_to_human( $most_delay->{sched_duration} / 60 );
= min_to_human( $most_delay->{rt_duration} / 60 ); $review{most_delay_real_time}
$review{most_delay_delta} = min_to_human( = min_to_human( $most_delay->{rt_duration} / 60 );
( $most_delay->{rt_duration} - $most_delay->{sched_duration} ) / 60 ); $review{most_delay_delta}
$review{most_delay_lineno} = $most_delay->{line} // $most_delay->{no}; = min_to_human(
$review{most_delay_from} = $most_delay->{from_name}; ( $most_delay->{rt_duration} - $most_delay->{sched_duration} )
$review{most_delay_to} = $most_delay->{to_name}; / 60 );
$review{most_delay_id} = $most_delay->{id}; $review{most_delay_lineno} = $most_delay->{line} // $most_delay->{no};
$review{most_delay_from} = $most_delay->{from_name};
$review{most_delay_to} = $most_delay->{to_name};
$review{most_delay_id} = $most_delay->{id};
}
$review{most_undelay_type} = $most_undelay->{type}; if ($most_undelay) {
$review{most_undelay_delay_dep} = $most_undelay->{delay_dep}; $review{most_undelay_type} = $most_undelay->{type};
$review{most_undelay_delay_arr} = $most_undelay->{delay_arr}; $review{most_undelay_delay_dep} = $most_undelay->{delay_dep};
$review{most_undelay_sched_time} $review{most_undelay_delay_arr} = $most_undelay->{delay_arr};
= min_to_human( $most_undelay->{sched_duration} / 60 ); $review{most_undelay_sched_time}
$review{most_undelay_real_time} = min_to_human( $most_undelay->{sched_duration} / 60 );
= min_to_human( $most_undelay->{rt_duration} / 60 ); $review{most_undelay_real_time}
$review{most_undelay_delta} = min_to_human( $most_undelay->{rt_duration} / 60 );
= min_to_human( $review{most_undelay_delta}
( $most_undelay->{sched_duration} - $most_undelay->{rt_duration} ) = min_to_human(
/ 60 ); ( $most_undelay->{sched_duration} - $most_undelay->{rt_duration} )
$review{most_undelay_lineno} = $most_undelay->{line} // $most_undelay->{no}; / 60 );
$review{most_undelay_from} = $most_undelay->{from_name}; $review{most_undelay_lineno} = $most_undelay->{line}
$review{most_undelay_to} = $most_undelay->{to_name}; // $most_undelay->{no};
$review{most_undelay_id} = $most_undelay->{id}; $review{most_undelay_from} = $most_undelay->{from_name};
$review{most_undelay_to} = $most_undelay->{to_name};
$review{most_undelay_id} = $most_undelay->{id};
}
$review{issue_percent} $review{issue_percent}
= sprintf( '%.0f%%', $message_count * 100 / $stats->{num_trains} ); = sprintf( '%.0f%%', $message_count * 100 / $stats->{num_trains} );

View file

@ -52,7 +52,7 @@
Im Mittel benötigte sie <strong><%= $review->{typical_time} %></strong> für eine Entfernung von ca. <strong><%= $review->{typical_km} %> km</strong> (<%= $review->{typical_kmh} %> km/h). Im Mittel benötigte sie <strong><%= $review->{typical_time} %></strong> für eine Entfernung von ca. <strong><%= $review->{typical_km} %> km</strong> (<%= $review->{typical_kmh} %> km/h).
</p> </p>
% if ($review->{typical_delay_dep} == 0 and $review->{typical_delay_arr} == 0) { % if ($review->{typical_delay_dep} == 0 and $review->{typical_delay_arr} == 0) {
<p>Außerdem war sie <strong>komplett pünktlich</strong> (wtf).</p> <p>Außerdem war sie <strong>komplett pünktlich</strong>. Beeindruckend!</p>
% } % }
% elsif ($review->{typical_delay_dep} > 0 and $review->{typical_delay_arr} > 0) { % elsif ($review->{typical_delay_dep} > 0 and $review->{typical_delay_arr} > 0) {
<p>Sie fuhr <strong><%= $review->{typical_delay_dep_h} %></strong> zu spät <p>Sie fuhr <strong><%= $review->{typical_delay_dep_h} %></strong> zu spät
@ -61,7 +61,7 @@
Ihr Ziel erreichte sie nur noch <strong><%= $review->{typical_delay_arr_h} %></strong> später als vorgesehen. Ihr Ziel erreichte sie nur noch <strong><%= $review->{typical_delay_arr_h} %></strong> später als vorgesehen.
% } % }
% elsif ($review->{typical_delay_arr} == $review->{typical_delay_dep}) { % elsif ($review->{typical_delay_arr} == $review->{typical_delay_dep}) {
ab und kam ebenso <strong><%= $review->{typical_delay_arr_h} %></strong> zu spät am Ziel an. ab und kam mit der gleichen Verspätung am Ziel an.
% } % }
% else { % else {
ab und schlich mit <strong>+<%= $review->{typical_delay_arr} %></strong> ins Ziel. ab und schlich mit <strong>+<%= $review->{typical_delay_arr} %></strong> ins Ziel.
@ -70,28 +70,32 @@
</div> </div>
<div class="carousel-item" href="#three"> <div class="carousel-item" href="#three">
<h2>High Scores</h2> <h2>High Scores</h2>
<p><a href="/journey/<%= $review->{longest_t_id} %>">Längste Zugfahrt</a>: % if ($review->{longest_t_id}) {
<strong><%= $review->{longest_t_time} %></strong> mit <strong><%= $review->{longest_t_type} %> <%= $review->{longest_t_lineno} %></strong> von <%= $review->{longest_t_from} %> nach <%= $review->{longest_t_to} %>.</p> <p><a href="/journey/<%= $review->{longest_t_id} %>">Längste Zugfahrt</a>:
% if ($review->{longest_km_id} == $review->{longest_t_id}) { <strong><%= $review->{longest_t_time} %></strong> mit <strong><%= $review->{longest_t_type} %> <%= $review->{longest_t_lineno} %></strong> von <%= $review->{longest_t_from} %> nach <%= $review->{longest_t_to} %>.</p>
<p>Mit <strong><%= $review->{longest_km_km} %> km</strong> war sie gleichzeitig deine weiteste Fahrt.</p> % if ($review->{longest_km_id} == $review->{longest_t_id}) {
<p>Mit <strong><%= $review->{longest_km_km} %> km</strong> war sie gleichzeitig deine weiteste Fahrt.</p>
% }
% } % }
% else { % if ($review->{longest_km_id} and $review->{longest_km_id} != $review->{longest_t_id}) {
<p><a href="/journey/<%= $review->{longest_km_id} %>">Größte Entfernung</a>: <p><a href="/journey/<%= $review->{longest_km_id} %>">Größte Entfernung</a>:
<strong><%= $review->{longest_km_km} %> km</strong> mit <strong><%= $review->{longest_km_type} %> <%= $review->{longest_km_lineno} %></strong> von <%= $review->{longest_km_from} %> nach <%= $review->{longest_km_to} %>.</p> <strong><%= $review->{longest_km_km} %> km</strong> mit <strong><%= $review->{longest_km_type} %> <%= $review->{longest_km_lineno} %></strong> von <%= $review->{longest_km_from} %> nach <%= $review->{longest_km_to} %>.</p>
% } % }
<p><a href="/journey/<%= $review->{shortest_t_id} %>">Kürzeste Zugfahrt</a>: % if ($review->{shortest_t_id}) {
<strong><%= $review->{shortest_t_time} %></strong> mit <strong><%= $review->{shortest_t_type} %> <%= $review->{shortest_t_lineno} %></strong> von <%= $review->{shortest_t_from} %> nach <%= $review->{shortest_t_to} %>.</p> <p><a href="/journey/<%= $review->{shortest_t_id} %>">Kürzeste Zugfahrt</a>:
% if ($review->{shortest_km_id} == $review->{shortest_t_id}) { <strong><%= $review->{shortest_t_time} %></strong> mit <strong><%= $review->{shortest_t_type} %> <%= $review->{shortest_t_lineno} %></strong> von <%= $review->{shortest_t_from} %> nach <%= $review->{shortest_t_to} %>.</p>
<p>Mit <strong><%= $review->{shortest_km_m} %> m</strong> war sie gleichzeitig dein kleinster Katzensprung.</p> % if ($review->{shortest_km_id} == $review->{shortest_t_id}) {
<p>Mit <strong><%= $review->{shortest_km_m} %> m</strong> war sie gleichzeitig dein kleinster Katzensprung.</p>
% }
% } % }
% else { % if ($review->{shortest_km_id} and $review->{shortest_km_id} != $review->{shortest_t_id}) {
<p><a href="/journey/<%= $review->{shortest_km_id} %>">Kleinster Katzensprung</a>: <p><a href="/journey/<%= $review->{shortest_km_id} %>">Kleinster Katzensprung</a>:
<strong><%= $review->{shortest_km_m} %> m</strong> mit <strong><%= $review->{shortest_km_type} %> <%= $review->{shortest_km_lineno} %></strong> von <%= $review->{shortest_km_from} %> nach <%= $review->{shortest_km_to} %>.</p> <strong><%= $review->{shortest_km_m} %> m</strong> mit <strong><%= $review->{shortest_km_type} %> <%= $review->{shortest_km_lineno} %></strong> von <%= $review->{shortest_km_from} %> nach <%= $review->{shortest_km_to} %>.</p>
% } % }
</div> </div>
% if ($review->{issue1_count}) { <div class="carousel-item" href="#four">
<div class="carousel-item" href="#four"> <h2>Oepsie Woepsie</h2>
<h2>Oepsie Woepsie</h2> % if ($review->{issue1_count}) {
<p><strong><%= $review->{issue_percent} %></strong> aller Fahrten liefen nicht wie vorgesehen ab.</p> <p><strong><%= $review->{issue_percent} %></strong> aller Fahrten liefen nicht wie vorgesehen ab.</p>
<p>Die häufigsten Anmerkungen waren:</p> <p>Die häufigsten Anmerkungen waren:</p>
% for my $i (1 .. 3) { % for my $i (1 .. 3) {
@ -99,9 +103,9 @@
<p><strong><%= $review->{"issue${i}_count"} %>×</strong> „<%= $review->{"issue${i}_text"} %>“</p> <p><strong><%= $review->{"issue${i}_count"} %>×</strong> „<%= $review->{"issue${i}_text"} %>“</p>
% } % }
% } % }
<p>Lediglich <strong><%= $review->{punctual_percent_h} %></strong> der Züge waren pünktlich auf die Minute.</p> % }
</div> <p>Lediglich <strong><%= $review->{punctual_percent_h} %></strong> der Züge waren pünktlich auf die Minute.</p>
% } </div>
<div class="carousel-item" href="#five"> <div class="carousel-item" href="#five">
<h2>De trein is stukkie wukkie</h2> <h2>De trein is stukkie wukkie</h2>
<p> <p>
@ -117,20 +121,26 @@
% } % }
% } % }
</p> </p>
<p> % if ($review->{most_delayed_id}) {
Mit <strong><%= $review->{most_delayed_delay_arr} %></strong> hatte <a href="/journey/<%= $review->{most_delayed_id} %>"><%= $review->{most_delayed_type} %> <%= $review->{most_delayed_lineno} %></a> <%= $review->{most_delayed_from} %> → <%= $review->{most_delayed_to} %> die größte Verspätung. <p>
</p> Mit <strong><%= $review->{most_delayed_delay_arr} %></strong> hatte <a href="/journey/<%= $review->{most_delayed_id} %>"><%= $review->{most_delayed_type} %> <%= $review->{most_delayed_lineno} %></a> <%= $review->{most_delayed_from} %> → <%= $review->{most_delayed_to} %> die größte Verspätung.
<p> </p>
Die Fahrt mit <a href="/journey/<%= $review->{most_delay_id} %>"><%= $review->{most_delay_type} %> <%= $review->{most_delay_lineno} %></a> % }
von <%= $review->{most_delay_from} %> nach <%= $review->{most_delay_to} %> verlief besonders gemächlich: % if ($review->{most_delay_id}) {
sie dauerte <strong><%= $review->{most_delay_delta} %></strong> länger als geplant. <p>
</p> Die Fahrt mit <a href="/journey/<%= $review->{most_delay_id} %>"><%= $review->{most_delay_type} %> <%= $review->{most_delay_lineno} %></a>
<p> von <%= $review->{most_delay_from} %> nach <%= $review->{most_delay_to} %> verlief besonders gemächlich:
In <a href="/journey/<%= $review->{most_undelay_id} %>"><%= $review->{most_undelay_type} %> <%= $review->{most_undelay_lineno} %></a> sie dauerte <strong><%= $review->{most_delay_delta} %></strong> länger als geplant.
wurde hingegen Vmax ausgereizt und die Strecke von </p>
<%= $review->{most_undelay_from} %> nach <%= $review->{most_undelay_to} %> % }
<strong><%= $review->{most_undelay_delta} %></strong> schneller absolviert als vorgesehen. % if ($review->{most_undelay_id}) {
</p> <p>
In <a href="/journey/<%= $review->{most_undelay_id} %>"><%= $review->{most_undelay_type} %> <%= $review->{most_undelay_lineno} %></a>
wurde hingegen Vmax ausgereizt und die Strecke von
<%= $review->{most_undelay_from} %> nach <%= $review->{most_undelay_to} %>
<strong><%= $review->{most_undelay_delta} %></strong> schneller absolviert als vorgesehen.
</p>
% }
</div> </div>
<div class="carousel-item" href="#six"> <div class="carousel-item" href="#six">
<h2>Last, but not least</h2> <h2>Last, but not least</h2>