summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/Travelynx.pm45
-rw-r--r--lib/Travelynx/Command/database.pm30
-rw-r--r--templates/_checked_in.html.ep10
3 files changed, 81 insertions, 4 deletions
diff --git a/lib/Travelynx.pm b/lib/Travelynx.pm
index 76b4b7f..7a4b6ca 100755
--- a/lib/Travelynx.pm
+++ b/lib/Travelynx.pm
@@ -646,6 +646,7 @@ sub startup {
= $db->select( 'in_transit', '*', { user_id => $uid } )->hash;
if ( $has_arrived or $force ) {
+ delete $journey->{data};
$journey->{edited} = 0;
$journey->{checkout_time} = $now;
$db->insert( 'journeys', $journey );
@@ -1591,12 +1592,13 @@ sub startup {
my $tree;
my $traininfo = {
- station => {},
+ station => {},
+ messages => [],
};
# <SDay text="... &gt; ..."> is invalid HTML, but present in
# 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 ) };
if ($@) {
$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 );
$promise->resolve($traininfo);
}
@@ -1655,6 +1672,14 @@ sub startup {
$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 );
$self->get_hafas_json_p(
@@ -1743,9 +1768,15 @@ sub startup {
$station->[1]
= $route_data->{ $station->[0] };
}
+
+ $extra_data->{him_msg} = $traininfo2->{messages};
+
$db->update(
'in_transit',
- { route => JSON->new->encode($route) },
+ {
+ route => JSON->new->encode($route),
+ data => JSON->new->encode($extra_data)
+ },
{ user_id => $uid }
);
}
@@ -2139,6 +2170,7 @@ sub startup {
arr_platform => $in_transit->{arr_platform},
route_after => \@route_after,
messages => $in_transit->{messages},
+ extra_data => $in_transit->{data},
};
my @parsed_messages;
@@ -2148,6 +2180,13 @@ sub startup {
}
$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) {
if ( @{$station} > 1 ) {
my $times = $station->[1];
diff --git a/lib/Travelynx/Command/database.pm b/lib/Travelynx/Command/database.pm
index fab5fa7..e561373 100644
--- a/lib/Travelynx/Command/database.pm
+++ b/lib/Travelynx/Command/database.pm
@@ -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 {
diff --git a/templates/_checked_in.html.ep b/templates/_checked_in.html.ep
index df5d260..184b11a 100644
--- a/templates/_checked_in.html.ep
+++ b/templates/_checked_in.html.ep
@@ -114,7 +114,7 @@
</div>
</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;">
<ul>
% 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>
% }
% }
+ % 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>
</p>
% }