show exit direction on kopfgleis platforms

This commit is contained in:
Daniel Friesel 2019-06-22 17:02:04 +02:00
parent 75aa4a961a
commit b3b0823829
2 changed files with 123 additions and 45 deletions

View file

@ -1537,6 +1537,39 @@ sub startup {
} }
); );
$self->helper(
'get_dbdb_station_p' => sub {
my ( $self, $ds100 ) = @_;
my $url = "https://lib.finalrewind.org/dbdb/s/${ds100}.json";
my $cache = $self->app->cache_iris_main;
my $promise = Mojo::Promise->new;
if ( my $content = $cache->thaw($url) ) {
$promise->resolve($content);
return $promise;
}
$self->ua->request_timeout(5)->get_p($url)->then(
sub {
my ($tx) = @_;
my $body = decode( 'utf-8', $tx->res->body );
my $json = JSON->new->decode($body);
$cache->freeze( $url, $json );
$promise->resolve($json);
}
)->catch(
sub {
my ($err) = @_;
$promise->reject($err);
}
)->wait;
return $promise;
}
);
$self->helper( $self->helper(
'get_wagonorder_p' => sub { 'get_wagonorder_p' => sub {
my ( $self, $ts, $train_no ) = @_; my ( $self, $ts, $train_no ) = @_;
@ -1688,14 +1721,18 @@ sub startup {
my $db = $self->pg->db; my $db = $self->pg->db;
my $journey my $journey = $db->select(
= $db->select( 'in_transit', ['route'], { user_id => $uid } ) 'in_transit_str',
->expand->hash; [ 'arr_ds100', 'route' ],
{ user_id => $uid }
)->expand->hash;
if ( not $journey ) { if ( not $journey ) {
return; return;
} }
my ($platform) = ( ( $train->platform // 0 ) =~ m{(\d+)} );
my $route = $journey->{route}; my $route = $journey->{route};
my $base my $base
@ -1706,14 +1743,6 @@ sub startup {
$self->app->log->debug("add_route_timestamps"); $self->app->log->debug("add_route_timestamps");
my $extra_data = {
delay_msg => [
map { [ $_->[0]->epoch, $_->[1] ] } $train->delay_messages
],
qos_msg =>
[ map { [ $_->[0]->epoch, $_->[1] ] } $train->qos_messages ],
};
my ( $trainlink, $route_data ); my ( $trainlink, $route_data );
$self->get_hafas_json_p( $self->get_hafas_json_p(
@ -1803,49 +1832,76 @@ sub startup {
= $route_data->{ $station->[0] }; = $route_data->{ $station->[0] };
} }
$extra_data->{him_msg} = $traininfo2->{messages}; my $res = $db->select( 'in_transit', ['data'],
{ user_id => $uid } );
my $res_h = $res->expand->hash;
my $data = $res_h->{data} // {};
#my $res = $db->select( 'in_transit', ['data'], $data->{delay_msg} = [ map { [ $_->[0]->epoch, $_->[1] ] }
# { user_id => $uid } ); $train->delay_messages ];
#my $res_h = $res->expand->hash; $data->{qos_msg} = [ map { [ $_->[0]->epoch, $_->[1] ] }
#if ( $res_h $train->qos_messages ];
# and $res_h->{data}
# and $res_h->{data}{wagonorder} )
#{
# $extra_data->{wagonorder} = $res_h->{data}{wagonorder};
#}
return $db->update_p( $data->{him_msg} = $traininfo2->{messages};
$db->update(
'in_transit', 'in_transit',
{ {
route => JSON->new->encode($route), route => JSON->new->encode($route),
data => JSON->new->encode($extra_data) data => JSON->new->encode($data)
}, },
{ user_id => $uid } { user_id => $uid }
); );
} }
#)->then(
# sub {
# if ($is_departure) {
# return $self->get_wagonorder_p( $train->sched_departure,
# $train->train_no );
# }
# return Mojo::Promise->reject;
# }
#)->then(
# sub {
# my ($wagonorder) = @_;
# $extra_data->{wagonorder} = $wagonorder;
# $db->update(
# 'in_transit',
# { data => JSON->new->encode($extra_data) },
# { user_id => $uid }
# );
# }
)->wait; )->wait;
if ( $train->type =~ m{[EI]C} and $train->sched_departure ) {
$self->get_wagonorder_p( $train->sched_departure,
$train->train_no )->then(
sub {
my ($wagonorder) = @_;
my $res = $db->select( 'in_transit', ['data'],
{ user_id => $uid } );
my $res_h = $res->expand->hash;
my $data = $res_h->{data} // {};
if ($is_departure) {
$data->{wagonorder_dep} = $wagonorder;
}
else {
$data->{wagonorder_arr} = $wagonorder;
}
$db->update(
'in_transit',
{ data => JSON->new->encode($data) },
{ user_id => $uid }
);
}
)->wait;
}
if ( $journey->{arr_ds100} and not $is_departure ) {
$self->get_dbdb_station_p( $journey->{arr_ds100} )->then(
sub {
my ($station_info) = @_;
my $res = $db->select( 'in_transit', ['data'],
{ user_id => $uid } );
my $res_h = $res->expand->hash;
my $data = $res_h->{data} // {};
$data->{stationinfo_arr} = $station_info;
$db->update(
'in_transit',
{ data => JSON->new->encode($data) },
{ user_id => $uid }
);
}
)->wait;
}
} }
); );
@ -2307,6 +2363,20 @@ sub startup {
elsif ( $ret->{journey_completion} < 0 ) { elsif ( $ret->{journey_completion} < 0 ) {
$ret->{journey_completion} = 0; $ret->{journey_completion} = 0;
} }
my ($arr_platform_number)
= ( ( $ret->{arr_platform} // 0 ) =~ m{(\d+)} );
if ( $arr_platform_number
and exists $in_transit->{data}{stationinfo_arr}
{$arr_platform_number} )
{
my $platform_info = $in_transit->{data}{stationinfo_arr}
{$arr_platform_number};
if ( $platform_info->{kopfgleis} ) {
$ret->{arr_direction} = $platform_info->{direction};
}
}
} }
else { else {
$ret->{arrival_countdown} = undef; $ret->{arrival_countdown} = undef;

View file

@ -27,7 +27,15 @@
Ziel erreicht Ziel erreicht
% } % }
% if ($journey->{arrival_countdown} < (60 * 15) and $journey->{arr_platform}) { % if ($journey->{arrival_countdown} < (60 * 15) and $journey->{arr_platform}) {
<br/>auf Gleis <%= $journey->{arr_platform} %> % if ($journey->{arr_direction} and $journey->{arr_direction} eq 'r') {
<br/>Gleis <%= $journey->{arr_platform} %> ▶
% }
% elsif ($journey->{arr_direction} and $journey->{arr_direction} eq 'l') {
<br/>◀ Gleis <%= $journey->{arr_platform} %>
% }
% else {
<br/>auf Gleis <%= $journey->{arr_platform} %>
% }
% } % }
% } % }
% elsif ($journey->{arr_name}) { % elsif ($journey->{arr_name}) {