summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Model/Journeys.pm
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-08-16 19:17:16 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-08-16 19:17:16 +0200
commite97f7892a6d1a74e729dc676fb90db8afc408db5 (patch)
tree651a4693106dca62750d91f9660eba00ec5a0e97 /lib/Travelynx/Model/Journeys.pm
parent7d37905add82ce990c69e598f919edbf51c345bf (diff)
backend selection: show frequently used backends2.16.6
Closes #288
Diffstat (limited to 'lib/Travelynx/Model/Journeys.pm')
-rwxr-xr-xlib/Travelynx/Model/Journeys.pm30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/Travelynx/Model/Journeys.pm b/lib/Travelynx/Model/Journeys.pm
index 9efa365..8e83374 100755
--- a/lib/Travelynx/Model/Journeys.pm
+++ b/lib/Travelynx/Model/Journeys.pm
@@ -1943,6 +1943,36 @@ sub get_latest_dest_ids {
);
}
+sub get_frequent_backend_ids {
+ my ( $self, %opt ) = @_;
+
+ my $uid = $opt{uid};
+ my $threshold = $opt{threshold}
+ // DateTime->now( time_zone => 'Europe/Berlin' )->subtract( months => 4 );
+ my $limit = $opt{limit} // 5;
+ my $db = $opt{db} //= $self->{pg}->db;
+
+ my $res = $db->select(
+ 'journeys',
+ 'count(*) as count, backend_id',
+ {
+ user_id => $uid,
+ real_departure => { '>', $threshold },
+ },
+ {
+ group_by => ['backend_id'],
+ order_by => { -desc => 'count' },
+ limit => $limit,
+ }
+ );
+
+ my @backend_ids = $res->hashes->map( sub { shift->{backend_id} } )->each;
+
+ say join( ' ', @backend_ids );
+
+ return @backend_ids;
+}
+
# Returns a listref of {eva, name} hashrefs for the specified backend.
sub get_connection_targets {
my ( $self, %opt ) = @_;