summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller/Traveling.pm
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-04-19 17:40:39 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-04-19 17:40:39 +0200
commit5ce4bc6995da0b49783c15a66075e5e4f1545875 (patch)
treeaeea7da0654d49bf62f9ffb8ba0c2e75159b9087 /lib/Travelynx/Controller/Traveling.pm
parenta3cfa598a6de9e053a5228be3ee5088ea0eabc18 (diff)
improve commute station heuristic
Select top station on work days (Mo .. Fr) with arrival < 13:00 or departure >= 13:00.
Diffstat (limited to 'lib/Travelynx/Controller/Traveling.pm')
-rwxr-xr-xlib/Travelynx/Controller/Traveling.pm27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/Travelynx/Controller/Traveling.pm b/lib/Travelynx/Controller/Traveling.pm
index db70368..1eef0c8 100755
--- a/lib/Travelynx/Controller/Traveling.pm
+++ b/lib/Travelynx/Controller/Traveling.pm
@@ -5,7 +5,7 @@ use DateTime;
use DateTime::Format::Strptime;
use JSON;
use List::Util qw(uniq min max);
-use List::UtilsBy qw(uniq_by);
+use List::UtilsBy qw(max_by uniq_by);
use List::MoreUtils qw(first_index);
use Travel::Status::DE::IRIS::Stations;
@@ -517,22 +517,27 @@ sub commute {
);
my $interval_end = $interval_start->clone->add( years => 1 );
- if ( not $station ) {
- my @top_station_ids = $self->get_top_destinations(
- after => $interval_start,
- before => $interval_end,
- );
- if (@top_station_ids) {
- $station = $top_station_ids[0][1];
- }
- }
-
my @journeys = $self->get_user_travels(
after => $interval_start,
before => $interval_end,
with_datetime => 1,
);
+ if ( not $station ) {
+ my %candidate_count;
+ for my $journey (@journeys) {
+ my $dep = $journey->{rt_departure};
+ my $arr = $journey->{rt_arrival};
+ if ( $arr->dow <= 5 and $arr->hour <= 12 ) {
+ $candidate_count{ $journey->{to_name} }++;
+ }
+ elsif ( $dep->dow <= 5 and $dep->hour > 12 ) {
+ $candidate_count{ $journey->{from_name} }++;
+ }
+ }
+ $station = max_by { $candidate_count{$_} } keys %candidate_count;
+ }
+
my %journeys_by_month;
my %count_by_month;
my $total = 0;