diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-04-01 20:28:06 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-04-01 20:28:06 +0200 |
commit | 335ab8209f3fae82df196ca97170ddcfe9f41fcd (patch) | |
tree | 924ecbd29057e0758c207c4af7af7aeab818b5f5 | |
parent | 8d843dc43200e65a7b37d2efa8f73fc1c3b7cc29 (diff) |
statistics: Add interchange wait time and journey count
-rwxr-xr-x | lib/Travelynx.pm | 45 | ||||
-rw-r--r-- | templates/history.html.ep | 8 |
2 files changed, 38 insertions, 15 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm index 4487898..234f1b8 100755 --- a/lib/Travelynx.pm +++ b/lib/Travelynx.pm @@ -900,7 +900,7 @@ qq{select * from pending_mails where email = ? and num_tries > 1;} if ( $opt{checkout_id} ) { $query = $self->app->get_journey_actions_query; - $query->execute( $uid, $opt{checkout_id}); + $query->execute( $uid, $opt{checkout_id} ); } elsif ( $opt{after} and $opt{before} ) { @@ -956,11 +956,8 @@ qq{select * from pending_mails where email = ? and num_tries > 1;} $raw_messages ) = @row; - if ( - $action == $match_actions[0] - or - ( $opt{checkout_id} and not @travels ) - ) + if ( $action == $match_actions[0] + or ( $opt{checkout_id} and not @travels ) ) { push( @travels, @@ -1167,12 +1164,14 @@ qq{select * from pending_mails where email = ? and num_tries > 1;} my $min_travel_real = 0; my $delay_dep = 0; my $delay_arr = 0; + my $interchange_real = 0; my $num_trains = 0; my $num_journeys = 0; + my $next_departure = 0; + for my $journey (@journeys) { $num_trains++; - $num_journeys++; $km_route += $journey->{km_route}; $km_beeline += $journey->{km_beeline}; if ( $journey->{sched_duration} > 0 ) { @@ -1192,16 +1191,32 @@ qq{select * from pending_mails where email = ? and num_tries > 1;} += ( $journey->{rt_arrival}->epoch - $journey->{sched_arrival}->epoch ) / 60; } + + # Note that journeys are sorted from recent to older entries + if ( $journey->{rt_arrival} + and $next_departure + and $next_departure - $journey->{rt_arrival}->epoch + < ( 60 * 60 ) ) + { + $interchange_real + += ( $next_departure - $journey->{rt_arrival}->epoch ) + / 60; + } + else { + $num_journeys++; + } + $next_departure = $journey->{rt_departure}->epoch; } return { - km_route => $km_route, - km_beeline => $km_beeline, - num_trains => $num_trains, - num_journeys => $num_journeys, - min_travel_sched => $min_travel_sched, - min_travel_real => $min_travel_real, - delay_dep => $delay_dep, - delay_arr => $delay_arr, + km_route => $km_route, + km_beeline => $km_beeline, + num_trains => $num_trains, + num_journeys => $num_journeys, + min_travel_sched => $min_travel_sched, + min_travel_real => $min_travel_real, + min_interchange_real => $interchange_real, + delay_dep => $delay_dep, + delay_arr => $delay_arr, }; } ); diff --git a/templates/history.html.ep b/templates/history.html.ep index 8f63296..1e565e6 100644 --- a/templates/history.html.ep +++ b/templates/history.html.ep @@ -22,6 +22,10 @@ <table class="striped"> <tr> <th scope="row">Fahrten</th> + <td><%= $stats->{num_journeys} %></td> + </tr> + <tr> + <th scope="row">Züge</th> <td><%= $stats->{num_trains} %></td> </tr> <tr> @@ -35,6 +39,10 @@ (nach Fahrplan: <%= sprintf('%02d:%02d', $stats->{min_travel_sched} / 60, $stats->{min_travel_sched} % 60) %>)<td> </tr> <tr> + <th scope="row">Wartezeit (nur Umstiege)</th> + <td><%= sprintf('%02d:%02d', $stats->{min_interchange_real} / 60, $stats->{min_interchange_real} % 60) %> Stunden + </tr> + <tr> <th scope="row">Kumulierte Verspätung</th> <td>Bei Abfahrt: <%= sprintf('%02d:%02d', $stats->{delay_dep} / 60, $stats->{delay_dep} % 60) %> Stunden<br/> Bei Ankunft: <%= sprintf('%02d:%02d', $stats->{delay_arr} / 60, $stats->{delay_arr} % 60) %> Stunden</td> |