journey: show average speed

This commit is contained in:
Daniel Friesel 2019-03-20 18:33:51 +01:00
parent 2366b193fe
commit 0a9d2e4c88
2 changed files with 38 additions and 8 deletions

View file

@ -877,6 +877,31 @@ helper 'get_user_travels' => sub {
push( @parsed_messages, [ epoch_to_dt($ts), $msg ] ); push( @parsed_messages, [ epoch_to_dt($ts), $msg ] );
} }
$ref->{messages} = [ reverse @parsed_messages ]; $ref->{messages} = [ reverse @parsed_messages ];
$ref->{sched_duration}
= $ref->{sched_arrival}
? $ref->{sched_arrival}->epoch
- $ref->{sched_departure}->epoch
: undef;
$ref->{rt_duration}
= $ref->{rt_arrival}
? $ref->{rt_arrival}->epoch - $ref->{rt_departure}->epoch
: undef;
$ref->{km_route}
= $self->get_travel_distance( $ref->{from_name},
$ref->{to_name}, $ref->{route} );
$ref->{km_beeline}
= $self->get_travel_distance( $ref->{from_name},
$ref->{to_name}, [ $ref->{from_name}, $ref->{to_name} ] );
$ref->{kmh_route}
= $ref->{km_route}
/ (
( $ref->{rt_duration} // $ref->{sched_duration} // 999999 )
/ 3600 );
$ref->{kmh_beeline}
= $ref->{km_beeline}
/ (
( $ref->{rt_duration} // $ref->{sched_duration} // 999999 )
/ 3600 );
} }
if ( $opt{checkin_epoch} if ( $opt{checkin_epoch}
and $action == $action_type{cancelled_from} ) and $action == $action_type{cancelled_from} )
@ -1117,9 +1142,9 @@ get '/api/v0/:action/:token' => sub {
line => $status->{train_line}, line => $status->{train_line},
no => $status->{train_no}, no => $status->{train_no},
}, },
actionTime => $status->{timestamp}->epoch, actionTime => $status->{timestamp}->epoch,
scheduledTime => $status->{sched_ts}->epoch, scheduledTime => $status->{sched_ts}->epoch,
realTime => $status->{real_ts}->epoch, realTime => $status->{real_ts}->epoch,
}, },
); );
} }

View file

@ -78,12 +78,17 @@
<tr> <tr>
<th scope="row">Entfernung</th> <th scope="row">Entfernung</th>
<td> <td>
% my $distance = get_travel_distance($journey->{from_name}, $journey->{to_name}, $journey->{route}); % if ($journey->{km_route} > 0.1) {
% my $beeline = get_travel_distance($journey->{from_name}, $journey->{to_name}, [$journey->{from_name}, $journey->{to_name}]); ca. <%= sprintf('%.f', $journey->{km_route}) %> km
% if ($distance > 0.1) {
ca. <%= sprintf('%.f', $distance) %> km
% } % }
(Luftlinie: <%= sprintf('%.f', $beeline) %> km) (Luftlinie: <%= sprintf('%.f', $journey->{km_beeline}) %> km)
</td>
</tr>
<tr>
<th scope="row">Geschwindigkeit</th>
<td>
∅ <%= sprintf('%.f', $journey->{kmh_route}) %> km/h
(<%= sprintf('%.f', $journey->{kmh_beeline}) %> km/h)
</td> </td>
</tr> </tr>
<tr> <tr>