summaryrefslogtreecommitdiff
path: root/lib/Travelynx.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-04-01 20:28:06 +0200
committerDaniel Friesel <derf@finalrewind.org>2019-04-01 20:28:06 +0200
commit335ab8209f3fae82df196ca97170ddcfe9f41fcd (patch)
tree924ecbd29057e0758c207c4af7af7aeab818b5f5 /lib/Travelynx.pm
parent8d843dc43200e65a7b37d2efa8f73fc1c3b7cc29 (diff)
statistics: Add interchange wait time and journey count
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-xlib/Travelynx.pm45
1 files changed, 30 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,
};
}
);