summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2022-10-27 18:30:14 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2022-10-27 18:30:14 +0200
commit9317d6e3bef2d3e018ad4c9ee5f32f40c0c2df09 (patch)
tree9700639a2c7dc2921e4be643577caa0df0c578f8
parent8acf974d48f1aac5c98e3995bb61b4a179ca09db (diff)
parse load/occupancy data
-rwxr-xr-xbin/hafas-m37
-rw-r--r--lib/Travel/Status/DE/HAFAS/Journey.pm8
2 files changed, 42 insertions, 3 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 509ebf5..0e9c8b4 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -203,6 +203,27 @@ sub display_result {
return;
}
+sub display_occupancy {
+ my ($occupancy) = @_;
+
+ if ( not $occupancy ) {
+ return q{ };
+ }
+ if ( $occupancy == 1 ) {
+ return q{.};
+ }
+ if ( $occupancy == 2 ) {
+ return q{o};
+ }
+ if ( $occupancy == 3 ) {
+ return q{*};
+ }
+ if ( $occupancy == 4 ) {
+ return q{!};
+ }
+ return q{?};
+}
+
if ( my $err = $status->errstr ) {
say STDERR "Request error: ${err}";
if ( $status->errcode
@@ -216,16 +237,26 @@ if ( my $err = $status->errstr ) {
if ( $opt{journey} ) {
my $result = $status->result;
- printf( "%s → %s\n", $result->line, $result->destination );
+ printf( "%s → %s", $result->name, $result->route_end );
+ if ( $result->number ) {
+ printf( " | Zug %s", $result->number );
+ }
+ if ( $result->line ) {
+ printf( " | Linie %s", $result->line );
+ }
+ say q{};
for my $stop ( $result->route ) {
printf(
- "%5s %s %5s %5s %s\n",
+ "%5s %s %5s %5s %1s%1s %s%s\n",
$stop->{arr} ? $stop->{arr}->strftime('%H:%M') : q{},
( $stop->{arr} and $stop->{dep} ) ? '→' : q{ },
$stop->{dep} ? $stop->{dep}->strftime('%H:%M') : q{},
$stop->{delay} ? sprintf( '(%+d)', $stop->{delay} ) : q{},
- $stop->{name}
+ display_occupancy( $stop->{load}{FIRST} ),
+ display_occupancy( $stop->{load}{SECOND} ),
+ $stop->{name},
+ $stop->{direction} ? sprintf( ' → %s', $stop->{direction} ) : q{}
);
}
diff --git a/lib/Travel/Status/DE/HAFAS/Journey.pm b/lib/Travel/Status/DE/HAFAS/Journey.pm
index 1c0962f..750d1e8 100644
--- a/lib/Travel/Status/DE/HAFAS/Journey.pm
+++ b/lib/Travel/Status/DE/HAFAS/Journey.pm
@@ -28,6 +28,7 @@ sub new {
my @prodL = @{ $opt{common}{prodL} // [] };
my @opL = @{ $opt{common}{opL} // [] };
my @icoL = @{ $opt{common}{icoL} // [] };
+ my @tcocL = @{ $opt{common}{tcocL} // [] };
my @remL = @{ $opt{common}{remL} // [] };
my @himL = @{ $opt{common}{himL} // [] };
@@ -120,6 +121,12 @@ sub new {
? ( $rt_dep->epoch - $sched_dep->epoch ) / 60
: undef;
+ my $tco = {};
+ for my $tco_id ( @{ $stop->{dTrnCmpSX}{tcocX} // [] } ) {
+ my $tco_kv = $tcocL[$tco_id];
+ $tco->{ $tco_kv->{c} } = $tco_kv->{r};
+ }
+
push(
@stops,
{
@@ -137,6 +144,7 @@ sub new {
dep_delay => $dep_delay,
delay => $dep_delay // $arr_delay,
direction => $stop->{dDirTxt},
+ load => $tco,
}
);
}