summaryrefslogtreecommitdiff
path: root/lib/Travelynx.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-04-19 16:49:31 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-04-19 16:49:31 +0200
commit94932c410290081461eecb2819bc187335452672 (patch)
treec73dd31b3e8b20ef0ff035aa5a2fa44d69090f71 /lib/Travelynx.pm
parent50d8256f6f0bb05416d67c4910d014eb1d91677f (diff)
add commute stats. not linked from nav yet.
Diffstat (limited to 'lib/Travelynx.pm')
-rwxr-xr-xlib/Travelynx.pm35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index d5dca3f..36a3998 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -2719,6 +2719,40 @@ sub startup {
);
$self->helper(
+ 'get_top_destinations' => sub {
+ my ( $self, %opt ) = @_;
+ my $uid = $opt{uid} //= $self->current_user->{id};
+ my $db = $opt{db} //= $self->pg->db;
+
+ my @stations;
+
+ my $res = $db->query(
+ qq{
+ select arr_eva, count(arr_eva) as count
+ from journeys_str
+ where user_id = ?
+ and real_dep_ts between ? and ?
+ group by arr_eva
+ order by count
+ limit 5
+ }, $uid, $opt{after}->epoch, $opt{before}->epoch
+ );
+
+ for my $dest ( $res->hashes->each ) {
+ $self->app->log->debug( $dest->{arr_eva} );
+ $self->app->log->debug( $dest->{count} );
+ if ( my $station
+ = $self->app->station_by_eva->{ $dest->{arr_eva} } )
+ {
+ push( @stations, $station );
+ }
+ }
+
+ return @stations;
+ }
+ );
+
+ $self->helper(
'get_connection_targets' => sub {
my ( $self, %opt ) = @_;
@@ -4043,6 +4077,7 @@ sub startup {
$authed_r->get('/export.json')->to('account#json_export');
$authed_r->get('/history.json')->to('traveling#json_history');
$authed_r->get('/history')->to('traveling#history');
+ $authed_r->get('/history/commute')->to('traveling#commute');
$authed_r->get('/history/map')->to('traveling#map_history');
$authed_r->get('/history/:year')->to('traveling#yearly_history');
$authed_r->get('/history/:year/:month')->to('traveling#monthly_history');