summaryrefslogtreecommitdiff
path: root/bin/hafas-m
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-11-24 18:11:48 +0100
committerBirte Kristina Friesel <derf@finalrewind.org>2023-11-24 18:11:48 +0100
commit0183a72df72a4a374e31c75f917ca03b9eff2e39 (patch)
tree2824b8ce122b1a1bc8f50663d9078b4640b7e67c /bin/hafas-m
parent757b3f34c87078b14e31ecf5150c03cf68b87323 (diff)
hafas-m stationboard: show (and sort by) real-time data
Diffstat (limited to 'bin/hafas-m')
-rwxr-xr-xbin/hafas-m23
1 files changed, 19 insertions, 4 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index f96365d..d6e5c41 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -412,7 +412,22 @@ for my $m ( $status->messages ) {
}
}
-for my $d ( $status->results ) {
+my @results = map { $_->[1] }
+ sort { $a->[0] <=> $b->[0] }
+ map { [ $_->datetime->epoch, $_ ] } $status->results;
+
+my $delay_len = 0;
+my $occupancy_len = 0;
+for my $d (@results) {
+ if ( $d->delay ) {
+ $delay_len = max( $delay_len, length( $d->delay ) + 1 );
+ }
+ if ( $d->load and ( $d->load->{FIRST} or $d->load->{SECOND} ) ) {
+ $occupancy_len = 2;
+ }
+}
+
+for my $d (@results) {
my $info_line = q{};
@@ -432,10 +447,10 @@ for my $d ( $status->results ) {
push(
@output,
[
- $d->sched_datetime->strftime('%H:%M'),
+ $d->is_cancelled ? '--:--' : $d->datetime->strftime('%H:%M'),
$d->is_cancelled
- ? 'CANCELED'
- : ( $d->delay ? sprintf( '%+d', $d->delay ) : q{} ),
+ ? q{}
+ : format_delay( $d->delay, $delay_len ),
$d->name,
$d->route_end,
( $d->platform // q{} ) . ( $d->is_changed_platform ? ' !' : q{} ),