diff options
-rwxr-xr-x | lib/Travelynx/Model/Journeys.pm | 174 | ||||
-rw-r--r-- | templates/year_in_review.html.ep | 82 |
2 files changed, 143 insertions, 113 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm index 42d5ec4..093aa1f 100755 --- a/lib/Travelynx/Model/Journeys.pm +++ b/lib/Travelynx/Model/Journeys.pm @@ -67,18 +67,19 @@ sub min_to_human { push( @ret, "$minutes Minuten" ); } elsif ($minutes) { - push( @ret, "1 Minute" ); + push( @ret, '1 Minute' ); + } + + if ( @ret == 0 ) { + return '0 Minuten'; } if ( @ret == 1 ) { return $ret[0]; } - if ( @ret > 2 ) { - my $last = pop(@ret); - return join( ', ', @ret ) . " und $last"; - } - return "$ret[0] und $ret[1]"; + my $last = pop(@ret); + return join( ', ', @ret ) . " und $last"; } sub new { @@ -1062,10 +1063,6 @@ sub compute_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) { if ( $journey->{cancelled} ) { $num_cancelled += 1; @@ -1192,6 +1189,7 @@ sub compute_review { $review{km_circle_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_percentage_year} = sprintf( "%.1f%%", $min_total * 100 / 525948.77 ); @@ -1224,73 +1222,95 @@ sub compute_review { = sprintf( '%.0f', $stats->{delay_arr} / $stats->{num_trains} ); $review{typical_delay_arr_h} = min_to_human( $review{typical_delay_arr} ); - $review{longest_t_time} = min_to_human( $longest_t->{rt_duration} / 60 ); - $review{longest_t_type} = $longest_t->{type}; - $review{longest_t_lineno} = $longest_t->{line} // $longest_t->{no}; - $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} ); - $review{longest_km_type} = $longest_km->{type}; - $review{longest_km_lineno} = $longest_km->{line} // $longest_km->{no}; - $review{longest_km_from} = $longest_km->{from_name}; - $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 ); - $review{shortest_t_type} = $shortest_t->{type}; - $review{shortest_t_lineno} = $shortest_t->{line} // $shortest_t->{no}; - $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 ); - $review{shortest_km_type} = $shortest_km->{type}; - $review{shortest_km_lineno} = $shortest_km->{line} // $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}; - $review{most_delayed_delay_dep} - = min_to_human( $most_delayed->{delay_dep} ); - $review{most_delayed_delay_arr} - = min_to_human( $most_delayed->{delay_arr} ); - $review{most_delayed_lineno} = $most_delayed->{line} // $most_delayed->{no}; - $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}; - $review{most_delay_delay_dep} = $most_delay->{delay_dep}; - $review{most_delay_delay_arr} = $most_delay->{delay_arr}; - $review{most_delay_sched_time} - = min_to_human( $most_delay->{sched_duration} / 60 ); - $review{most_delay_real_time} - = min_to_human( $most_delay->{rt_duration} / 60 ); - $review{most_delay_delta} = min_to_human( - ( $most_delay->{rt_duration} - $most_delay->{sched_duration} ) / 60 ); - $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}; - $review{most_undelay_delay_dep} = $most_undelay->{delay_dep}; - $review{most_undelay_delay_arr} = $most_undelay->{delay_arr}; - $review{most_undelay_sched_time} - = min_to_human( $most_undelay->{sched_duration} / 60 ); - $review{most_undelay_real_time} - = min_to_human( $most_undelay->{rt_duration} / 60 ); - $review{most_undelay_delta} - = min_to_human( - ( $most_undelay->{sched_duration} - $most_undelay->{rt_duration} ) - / 60 ); - $review{most_undelay_lineno} = $most_undelay->{line} // $most_undelay->{no}; - $review{most_undelay_from} = $most_undelay->{from_name}; - $review{most_undelay_to} = $most_undelay->{to_name}; - $review{most_undelay_id} = $most_undelay->{id}; + if ($longest_t) { + $review{longest_t_time} + = min_to_human( $longest_t->{rt_duration} / 60 ); + $review{longest_t_type} = $longest_t->{type}; + $review{longest_t_lineno} = $longest_t->{line} // $longest_t->{no}; + $review{longest_t_from} = $longest_t->{from_name}; + $review{longest_t_to} = $longest_t->{to_name}; + $review{longest_t_id} = $longest_t->{id}; + } + + if ($longest_km) { + $review{longest_km_km} = sprintf( '%.0f', $longest_km->{km_route} ); + $review{longest_km_type} = $longest_km->{type}; + $review{longest_km_lineno} = $longest_km->{line} // $longest_km->{no}; + $review{longest_km_from} = $longest_km->{from_name}; + $review{longest_km_to} = $longest_km->{to_name}; + $review{longest_km_id} = $longest_km->{id}; + } + + if ($shortest_t) { + $review{shortest_t_time} + = min_to_human( $shortest_t->{rt_duration} / 60 ); + $review{shortest_t_type} = $shortest_t->{type}; + $review{shortest_t_lineno} = $shortest_t->{line} // $shortest_t->{no}; + $review{shortest_t_from} = $shortest_t->{from_name}; + $review{shortest_t_to} = $shortest_t->{to_name}; + $review{shortest_t_id} = $shortest_t->{id}; + } + + if ($shortest_km) { + $review{shortest_km_m} + = sprintf( '%.0f', $shortest_km->{km_route} * 1000 ); + $review{shortest_km_type} = $shortest_km->{type}; + $review{shortest_km_lineno} = $shortest_km->{line} + // $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}; + } + + if ($most_delayed) { + $review{most_delayed_type} = $most_delayed->{type}; + $review{most_delayed_delay_dep} + = min_to_human( $most_delayed->{delay_dep} ); + $review{most_delayed_delay_arr} + = min_to_human( $most_delayed->{delay_arr} ); + $review{most_delayed_lineno} = $most_delayed->{line} + // $most_delayed->{no}; + $review{most_delayed_from} = $most_delayed->{from_name}; + $review{most_delayed_to} = $most_delayed->{to_name}; + $review{most_delayed_id} = $most_delayed->{id}; + } + + if ($most_delay) { + $review{most_delay_type} = $most_delay->{type}; + $review{most_delay_delay_dep} = $most_delay->{delay_dep}; + $review{most_delay_delay_arr} = $most_delay->{delay_arr}; + $review{most_delay_sched_time} + = min_to_human( $most_delay->{sched_duration} / 60 ); + $review{most_delay_real_time} + = min_to_human( $most_delay->{rt_duration} / 60 ); + $review{most_delay_delta} + = min_to_human( + ( $most_delay->{rt_duration} - $most_delay->{sched_duration} ) + / 60 ); + $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}; + } + + if ($most_undelay) { + $review{most_undelay_type} = $most_undelay->{type}; + $review{most_undelay_delay_dep} = $most_undelay->{delay_dep}; + $review{most_undelay_delay_arr} = $most_undelay->{delay_arr}; + $review{most_undelay_sched_time} + = min_to_human( $most_undelay->{sched_duration} / 60 ); + $review{most_undelay_real_time} + = min_to_human( $most_undelay->{rt_duration} / 60 ); + $review{most_undelay_delta} + = min_to_human( + ( $most_undelay->{sched_duration} - $most_undelay->{rt_duration} ) + / 60 ); + $review{most_undelay_lineno} = $most_undelay->{line} + // $most_undelay->{no}; + $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} = sprintf( '%.0f%%', $message_count * 100 / $stats->{num_trains} ); diff --git a/templates/year_in_review.html.ep b/templates/year_in_review.html.ep index 55d80fb..548245e 100644 --- a/templates/year_in_review.html.ep +++ b/templates/year_in_review.html.ep @@ -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). </p> % 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) { <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. % } % 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 { ab und schlich mit <strong>+<%= $review->{typical_delay_arr} %></strong> ins Ziel. @@ -70,28 +70,32 @@ </div> <div class="carousel-item" href="#three"> <h2>High Scores</h2> - <p><a href="/journey/<%= $review->{longest_t_id} %>">Längste Zugfahrt</a>: - <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> - % 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> + % if ($review->{longest_t_id}) { + <p><a href="/journey/<%= $review->{longest_t_id} %>">Längste Zugfahrt</a>: + <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> + % 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 { - <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> + % 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>: + <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>: - <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> - % 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> + % if ($review->{shortest_t_id}) { + <p><a href="/journey/<%= $review->{shortest_t_id} %>">Kürzeste Zugfahrt</a>: + <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> + % 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 { - <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> + % 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>: + <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> - % if ($review->{issue1_count}) { - <div class="carousel-item" href="#four"> - <h2>Oepsie Woepsie</h2> + <div class="carousel-item" href="#four"> + <h2>Oepsie Woepsie</h2> + % if ($review->{issue1_count}) { <p><strong><%= $review->{issue_percent} %></strong> aller Fahrten liefen nicht wie vorgesehen ab.</p> <p>Die häufigsten Anmerkungen waren:</p> % for my $i (1 .. 3) { @@ -99,9 +103,9 @@ <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"> <h2>De trein is stukkie wukkie</h2> <p> @@ -117,20 +121,26 @@ % } % } </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: - sie dauerte <strong><%= $review->{most_delay_delta} %></strong> länger als geplant. - </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> + % if ($review->{most_delayed_id}) { + <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> + % } + % if ($review->{most_delay_id}) { + <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: + sie dauerte <strong><%= $review->{most_delay_delta} %></strong> länger als geplant. + </p> + % } + % if ($review->{most_undelay_id}) { + <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 class="carousel-item" href="#six"> <h2>Last, but not least</h2> |