checked in: Show QoS messages before departure and HIM messages at all times
This commit is contained in:
parent
d90c44ccff
commit
7be3a4219e
3 changed files with 81 additions and 4 deletions
|
@ -646,6 +646,7 @@ sub startup {
|
||||||
= $db->select( 'in_transit', '*', { user_id => $uid } )->hash;
|
= $db->select( 'in_transit', '*', { user_id => $uid } )->hash;
|
||||||
|
|
||||||
if ( $has_arrived or $force ) {
|
if ( $has_arrived or $force ) {
|
||||||
|
delete $journey->{data};
|
||||||
$journey->{edited} = 0;
|
$journey->{edited} = 0;
|
||||||
$journey->{checkout_time} = $now;
|
$journey->{checkout_time} = $now;
|
||||||
$db->insert( 'journeys', $journey );
|
$db->insert( 'journeys', $journey );
|
||||||
|
@ -1592,11 +1593,12 @@ sub startup {
|
||||||
|
|
||||||
my $traininfo = {
|
my $traininfo = {
|
||||||
station => {},
|
station => {},
|
||||||
|
messages => [],
|
||||||
};
|
};
|
||||||
|
|
||||||
# <SDay text="... > ..."> is invalid HTML, but present in
|
# <SDay text="... > ..."> is invalid HTML, but present in
|
||||||
# regardless. As it is the last tag, we just throw it away.
|
# regardless. As it is the last tag, we just throw it away.
|
||||||
$body =~ s{<SDay .*}{</Journey>}s;
|
$body =~ s{<SDay [^>]*/>}{}s;
|
||||||
eval { $tree = XML::LibXML->load_xml( string => $body ) };
|
eval { $tree = XML::LibXML->load_xml( string => $body ) };
|
||||||
if ($@) {
|
if ($@) {
|
||||||
$self->app->log->warning("load_xml($url): $@");
|
$self->app->log->warning("load_xml($url): $@");
|
||||||
|
@ -1615,6 +1617,21 @@ sub startup {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for my $message ( $tree->findnodes('/Journey/HIMMessage') )
|
||||||
|
{
|
||||||
|
my $header = $message->getAttribute('header');
|
||||||
|
my $lead = $message->getAttribute('lead');
|
||||||
|
my $display = $message->getAttribute('display');
|
||||||
|
push(
|
||||||
|
@{ $traininfo->{messages} },
|
||||||
|
{
|
||||||
|
header => $header,
|
||||||
|
lead => $lead,
|
||||||
|
display => $display
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$cache->freeze( $url, $traininfo );
|
$cache->freeze( $url, $traininfo );
|
||||||
$promise->resolve($traininfo);
|
$promise->resolve($traininfo);
|
||||||
}
|
}
|
||||||
|
@ -1655,6 +1672,14 @@ 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(
|
||||||
|
@ -1743,9 +1768,15 @@ sub startup {
|
||||||
$station->[1]
|
$station->[1]
|
||||||
= $route_data->{ $station->[0] };
|
= $route_data->{ $station->[0] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$extra_data->{him_msg} = $traininfo2->{messages};
|
||||||
|
|
||||||
$db->update(
|
$db->update(
|
||||||
'in_transit',
|
'in_transit',
|
||||||
{ route => JSON->new->encode($route) },
|
{
|
||||||
|
route => JSON->new->encode($route),
|
||||||
|
data => JSON->new->encode($extra_data)
|
||||||
|
},
|
||||||
{ user_id => $uid }
|
{ user_id => $uid }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2139,6 +2170,7 @@ sub startup {
|
||||||
arr_platform => $in_transit->{arr_platform},
|
arr_platform => $in_transit->{arr_platform},
|
||||||
route_after => \@route_after,
|
route_after => \@route_after,
|
||||||
messages => $in_transit->{messages},
|
messages => $in_transit->{messages},
|
||||||
|
extra_data => $in_transit->{data},
|
||||||
};
|
};
|
||||||
|
|
||||||
my @parsed_messages;
|
my @parsed_messages;
|
||||||
|
@ -2148,6 +2180,13 @@ sub startup {
|
||||||
}
|
}
|
||||||
$ret->{messages} = [ reverse @parsed_messages ];
|
$ret->{messages} = [ reverse @parsed_messages ];
|
||||||
|
|
||||||
|
@parsed_messages = ();
|
||||||
|
for my $message ( @{ $ret->{extra_data}{qos_msg} // [] } ) {
|
||||||
|
my ( $ts, $msg ) = @{$message};
|
||||||
|
push( @parsed_messages, [ epoch_to_dt($ts), $msg ] );
|
||||||
|
}
|
||||||
|
$ret->{extra_data}{qos_msg} = [@parsed_messages];
|
||||||
|
|
||||||
for my $station (@route_after) {
|
for my $station (@route_after) {
|
||||||
if ( @{$station} > 1 ) {
|
if ( @{$station} > 1 ) {
|
||||||
my $times = $station->[1];
|
my $times = $station->[1];
|
||||||
|
|
|
@ -659,6 +659,36 @@ my @migrations = (
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# v14 -> v15
|
||||||
|
sub {
|
||||||
|
my ($db) = @_;
|
||||||
|
$db->query(
|
||||||
|
qq{
|
||||||
|
alter table in_transit add column data jsonb;
|
||||||
|
create or replace view in_transit_str as select
|
||||||
|
user_id,
|
||||||
|
train_type, train_line, train_no, train_id,
|
||||||
|
extract(epoch from checkin_time) as checkin_ts,
|
||||||
|
extract(epoch from sched_departure) as sched_dep_ts,
|
||||||
|
extract(epoch from real_departure) as real_dep_ts,
|
||||||
|
dep_stations.ds100 as dep_ds100,
|
||||||
|
dep_stations.name as dep_name,
|
||||||
|
extract(epoch from checkout_time) as checkout_ts,
|
||||||
|
extract(epoch from sched_arrival) as sched_arr_ts,
|
||||||
|
extract(epoch from real_arrival) as real_arr_ts,
|
||||||
|
arr_stations.ds100 as arr_ds100,
|
||||||
|
arr_stations.name as arr_name,
|
||||||
|
cancelled, route, messages,
|
||||||
|
dep_platform, arr_platform, data
|
||||||
|
from in_transit
|
||||||
|
join stations as dep_stations on dep_stations.id = checkin_station_id
|
||||||
|
left join stations as arr_stations on arr_stations.id = checkout_station_id
|
||||||
|
;
|
||||||
|
update schema_version set version = 15;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
sub setup_db {
|
sub setup_db {
|
||||||
|
|
|
@ -114,7 +114,7 @@
|
||||||
</div>
|
</div>
|
||||||
</p>
|
</p>
|
||||||
% }
|
% }
|
||||||
% if (@{$journey->{messages} // []} > 0 and $journey->{messages}[0]) {
|
% if (@{$journey->{messages} // []} or @{$journey->{extra_data}{him_msg} // []} or @{$journey->{extra_data}{qos_msg} // []}) {
|
||||||
<p style="margin-bottom: 2ex;">
|
<p style="margin-bottom: 2ex;">
|
||||||
<ul>
|
<ul>
|
||||||
% for my $message (reverse @{$journey->{messages} // []}) {
|
% for my $message (reverse @{$journey->{messages} // []}) {
|
||||||
|
@ -122,6 +122,14 @@
|
||||||
<li> <i class="material-icons tiny">warning</i> <%= $message->[0]->strftime('%H:%M') %>: <%= $message->[1] %></li>
|
<li> <i class="material-icons tiny">warning</i> <%= $message->[0]->strftime('%H:%M') %>: <%= $message->[1] %></li>
|
||||||
% }
|
% }
|
||||||
% }
|
% }
|
||||||
|
% if ($journey->{departure_countdown} > 0) {
|
||||||
|
% for my $message (@{$journey->{extra_data}{qos_msg} // []}) {
|
||||||
|
<li> <i class="material-icons tiny">info</i> <%= $message->[0]->strftime('%H:%M') %>: <%= $message->[1] %></li>
|
||||||
|
% }
|
||||||
|
% }
|
||||||
|
% for my $message (@{$journey->{extra_data}{him_msg} // []}) {
|
||||||
|
<li> <i class="material-icons tiny">info</i> <%= $message->{header} %> <%= $message->{lead} %></li>
|
||||||
|
% }
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
% }
|
% }
|
||||||
|
|
Loading…
Reference in a new issue