From cbbe35517e92f6cdf926a42eb167fca566881233 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 4 Dec 2014 12:21:48 +0100 Subject: iris+clean: show and sort by actual (estimated) arr/dep times --- index.pl | 38 +++++++++++++++++++++++++++++++++----- public/default.css | 10 ++++++++++ templates/clean.html.ep | 13 ++++++++++++- templates/layouts/default.html.ep | 8 ++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/index.pl b/index.pl index 1665e4f..2d4eb37 100644 --- a/index.pl +++ b/index.pl @@ -68,11 +68,12 @@ sub handle_request { my @platforms = split( /,/, $self->param('platforms') // q{} ); my @lines = split( /,/, $self->param('lines') // q{} ); - my $template = $self->param('mode') // 'multi'; - my $hide_low_delay = $self->param('hidelowdelay') // 0; - my $hide_opts = $self->param('hide_opts') // 0; - my $backend = $self->param('backend') // 'ris'; - my $admode = $self->param('admode') // 'deparr'; + my $template = $self->param('mode') // 'multi'; + my $hide_low_delay = $self->param('hidelowdelay') // 0; + my $hide_opts = $self->param('hide_opts') // 0; + my $show_realtime = $self->param('show_realtime') // 0; + my $backend = $self->param('backend') // 'ris'; + my $admode = $self->param('admode') // 'deparr'; my $callback = $self->param('callback'); my $api_version @@ -173,6 +174,21 @@ sub handle_request { @results = sort { $a->platform <=> $b->platform } @results; } + if ( $backend eq 'iris' and $show_realtime ) { + if ( $admode eq 'arr' ) { + @results = sort { + ( $a->arrival // $a->departure ) + <=> ( $b->arrival // $b->depearture ) + } @results; + } + else { + @results = sort { + ( $a->departure // $a->arrival ) + <=> ( $b->departure // $b->arrival ) + } @results; + } + } + for my $result (@results) { my $platform = ( split( / /, $result->platform ) )[0]; my $line = $result->line; @@ -259,6 +275,17 @@ sub handle_request { if ( $admode eq 'arr' ) { $time = $result->sched_arrival->strftime('%H:%M'); } + + if ($show_realtime) { + if ( ( $admode eq 'arr' and $result->arrival ) + or not $result->departure ) + { + $time = $result->arrival->strftime('%H:%M'); + } + else { + $time = $result->departure->strftime('%H:%M'); + } + } } if ( $info eq '+0' ) { @@ -324,6 +351,7 @@ sub handle_request { title => "departures for ${station}", refresh_interval => $refresh_interval + 3, hide_opts => $hide_opts, + show_realtime => $show_realtime, ); } } diff --git a/public/default.css b/public/default.css index 350db27..edcb82a 100644 --- a/public/default.css +++ b/public/default.css @@ -155,6 +155,12 @@ div.displayclean li .countdown .delay { padding-right:7px; } +div.displayclean li .countdown .delaynorm { + font-size:0.9em; + color:#BB3333; + padding-right:7px; +} + div.displayclean li .countdown .platform { font-weight: bold; } @@ -168,6 +174,10 @@ div.displayclean li .time { top:5px; } +div.displayclean span.delayed { + color: #ff0000; +} + div.displaymulti { border: 0.2em solid #000066; width: 55em; diff --git a/templates/clean.html.ep b/templates/clean.html.ep index 21750d5..f073c2e 100644 --- a/templates/clean.html.ep +++ b/templates/clean.html.ep @@ -58,15 +58,26 @@ % if ($departure->{delay} and not $departure->{is_cancelled}) { +% if ($show_realtime) { +(+<%= $departure->{delay} %>) +% } +% else { (+<%= $departure->{delay} %>) % } +% } %= $departure->{platform} - + +% if ($show_realtime and $departure->{delay} and not $departure->{is_cancelled}) { + +% } %= $departure->{time} +% if ($show_realtime and $departure->{delay} and not $departure->{is_cancelled}) { + +% }