store related stations; respect them when looking up connections
This commit is contained in:
parent
2638dd36fb
commit
aaeb81a5d2
4 changed files with 69 additions and 14 deletions
|
@ -1929,6 +1929,23 @@ my @migrations = (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# v50 -> v51
|
||||||
|
# store related HAFAS stations
|
||||||
|
sub {
|
||||||
|
my ($db) = @_;
|
||||||
|
$db->query(
|
||||||
|
qq{
|
||||||
|
create table related_stations (
|
||||||
|
eva integer not null,
|
||||||
|
meta integer not null,
|
||||||
|
unique (eva, meta)
|
||||||
|
);
|
||||||
|
create index rel_eva on related_stations (eva);
|
||||||
|
update schema_version set version = 51;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
sub sync_stations {
|
sub sync_stations {
|
||||||
|
|
|
@ -960,6 +960,10 @@ sub station {
|
||||||
( $_->datetime // $_->sched_datetime )->epoch
|
( $_->datetime // $_->sched_datetime )->epoch
|
||||||
< $now + 30 * 60
|
< $now + 30 * 60
|
||||||
} $status->results;
|
} $status->results;
|
||||||
|
$self->stations->add_meta(
|
||||||
|
eva => $status->station->{eva},
|
||||||
|
meta => $status->station->{evas}
|
||||||
|
);
|
||||||
$status = {
|
$status = {
|
||||||
station_eva => $status->station->{eva},
|
station_eva => $status->station->{eva},
|
||||||
station_name => (
|
station_name => (
|
||||||
|
|
|
@ -1735,21 +1735,20 @@ sub get_connection_targets {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $res = $db->query(
|
my $dest_ids = [ $dest_id, $self->{stations}->get_meta( eva => $dest_id ) ];
|
||||||
qq{
|
|
||||||
select
|
my $res = $db->select(
|
||||||
count(checkout_station_id) as count,
|
'journeys',
|
||||||
checkout_station_id as dest
|
'count(checkout_station_id) as count, checkout_station_id as dest',
|
||||||
from journeys
|
{
|
||||||
where user_id = ?
|
user_id => $uid,
|
||||||
and checkin_station_id = ?
|
checkin_station_id => $dest_ids,
|
||||||
and real_departure > ?
|
real_departure => { '>', $threshold }
|
||||||
group by checkout_station_id
|
|
||||||
order by count desc;
|
|
||||||
},
|
},
|
||||||
$uid,
|
{
|
||||||
$dest_id,
|
group_by => ['checkout_station_id'],
|
||||||
$threshold
|
order_by => { -desc => 'count' }
|
||||||
|
}
|
||||||
);
|
);
|
||||||
my @destinations
|
my @destinations
|
||||||
= $res->hashes->grep( sub { shift->{count} >= $min_count } )
|
= $res->hashes->grep( sub { shift->{count} >= $min_count } )
|
||||||
|
|
|
@ -50,6 +50,41 @@ sub add_or_update {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub add_meta {
|
||||||
|
my ( $self, %opt ) = @_;
|
||||||
|
my $db = $opt{db} // $self->{pg}->db;
|
||||||
|
my $eva = $opt{eva};
|
||||||
|
my @meta = @{ $opt{meta} };
|
||||||
|
|
||||||
|
for my $meta (@meta) {
|
||||||
|
if ( $meta != $eva ) {
|
||||||
|
$db->insert(
|
||||||
|
'related_stations',
|
||||||
|
{
|
||||||
|
eva => $eva,
|
||||||
|
meta => $meta
|
||||||
|
},
|
||||||
|
{ on_conflict => undef }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub get_meta {
|
||||||
|
my ( $self, %opt ) = @_;
|
||||||
|
my $db = $opt{db} // $self->{pg}->db;
|
||||||
|
my $eva = $opt{eva};
|
||||||
|
|
||||||
|
my $res = $db->select( 'related_stations', ['meta'], { eva => $eva } );
|
||||||
|
my @ret;
|
||||||
|
|
||||||
|
while ( my $row = $res->hash ) {
|
||||||
|
push( @ret, $row->{meta} );
|
||||||
|
}
|
||||||
|
|
||||||
|
return @ret;
|
||||||
|
}
|
||||||
|
|
||||||
sub get_for_autocomplete {
|
sub get_for_autocomplete {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue