improve commute station heuristic
Select top station on work days (Mo .. Fr) with arrival < 13:00 or departure >= 13:00.
This commit is contained in:
parent
a3cfa598a6
commit
5ce4bc6995
2 changed files with 16 additions and 45 deletions
|
@ -2719,40 +2719,6 @@ 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 desc
|
|
||||||
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(
|
$self->helper(
|
||||||
'get_connection_targets' => sub {
|
'get_connection_targets' => sub {
|
||||||
my ( $self, %opt ) = @_;
|
my ( $self, %opt ) = @_;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use DateTime;
|
||||||
use DateTime::Format::Strptime;
|
use DateTime::Format::Strptime;
|
||||||
use JSON;
|
use JSON;
|
||||||
use List::Util qw(uniq min max);
|
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 List::MoreUtils qw(first_index);
|
||||||
use Travel::Status::DE::IRIS::Stations;
|
use Travel::Status::DE::IRIS::Stations;
|
||||||
|
|
||||||
|
@ -517,22 +517,27 @@ sub commute {
|
||||||
);
|
);
|
||||||
my $interval_end = $interval_start->clone->add( years => 1 );
|
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(
|
my @journeys = $self->get_user_travels(
|
||||||
after => $interval_start,
|
after => $interval_start,
|
||||||
before => $interval_end,
|
before => $interval_end,
|
||||||
with_datetime => 1,
|
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 %journeys_by_month;
|
||||||
my %count_by_month;
|
my %count_by_month;
|
||||||
my $total = 0;
|
my $total = 0;
|
||||||
|
|
Loading…
Reference in a new issue