summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/dbris55
-rw-r--r--lib/Travel/Routing/DE/DBRIS/Connection.pm15
-rw-r--r--lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm6
3 files changed, 61 insertions, 15 deletions
diff --git a/bin/dbris b/bin/dbris
index ac11832..879bd96 100755
--- a/bin/dbris
+++ b/bin/dbris
@@ -35,6 +35,18 @@ for my $arg (@ARGV) {
my $output_bold = -t STDOUT ? "\033[1m" : q{};
my $output_reset = -t STDOUT ? "\033[0m" : q{};
+my $output_fyi = -t STDOUT ? "\033[40;36m" : q{};
+my $output_unknown = -t STDOUT ? "\033[40;35m" : q{};
+my $output_good = -t STDOUT ? "\033[40;32m" : q{};
+my $output_warning = -t STDOUT ? "\033[40;33m" : q{};
+my $output_critical = -t STDOUT ? "\033[40;31m" : q{};
+
+my $output_bold_fyi = -t STDOUT ? "\033[1;40;36m" : q{};
+my $output_bold_unknown = -t STDOUT ? "\033[1;40;35m" : q{};
+my $output_bold_good = -t STDOUT ? "\033[1;40;32m" : q{};
+my $output_bold_warning = -t STDOUT ? "\033[1;40;33m" : q{};
+my $output_bold_critical = -t STDOUT ? "\033[1;40;31m" : q{};
+
GetOptions(
'd|date=s' => \$date,
'h|help' => sub { show_help(0) },
@@ -276,6 +288,27 @@ if ($json_output) {
for my $connection ( $ris->connections ) {
my $header = q{};
+ my $format = $output_bold;
+
+ if ( $connection->is_unlikely ) {
+ if ( $connection->feasibility >= 4 ) {
+ $header .= " ${output_critical}XX${output_reset}";
+ $format = $output_bold_critical;
+ }
+ else {
+ $header .= " ${output_warning}X?${output_reset}";
+ $format = $output_bold_warning;
+ }
+ }
+ if ( $connection->is_cancelled ) {
+ $format = $output_bold_critical;
+ }
+
+ if ( defined $passengers and defined $connection->price ) {
+ $header .= sprintf( ' %.2f %s', $connection->price,
+ $connection->price_unit );
+ }
+
for my $segment ( $connection->segments ) {
if ( $segment->train_short ) {
$header .= sprintf( ' %s', $segment->train_short );
@@ -307,15 +340,19 @@ for my $connection ( $ris->connections ) {
say q{};
printf(
- "%s (%02d:%02d) %s %s%s%s\n\n",
- $connection->dep ? $connection->dep->strftime('%d.%m. %H:%M')
- : q{??.??. ??:??},
+ "%s %s%s%s (%02d:%02d) %s%s%s %s%s\n",
+ $connection->dep ? $connection->dep->strftime('%d.%m.')
+ : q{??.??.},
+ $format,
+ $connection->dep ? $connection->dep->strftime('%H:%M')
+ : q{??:??},
+ $output_reset,
$connection->duration->in_units( 'hours', 'minutes' ),
+ $format,
$connection->arr ? $connection->arr->strftime('%H:%M') : q{??:??},
- format_occupancy($connection),
- ( defined $passengers and defined $connection->price )
- ? sprintf( ' %.2f %s', $connection->price, $connection->price_unit )
- : q{},
+ $output_reset,
+ $connection->is_cancelled ? "${output_critical}XX${output_reset}"
+ : format_occupancy($connection),
$header,
);
@@ -389,8 +426,10 @@ for my $connection ( $ris->connections ) {
}
printf(
- "%s%s an %s%s\n",
+ "%s%s%s%s an %s%s\n",
+ $segment->is_unlikely ? $output_critical : q{},
$segment->arr->strftime('%H:%M'),
+ $segment->is_unlikely ? $output_reset : q{},
$max_delay_digits
? q{ } . format_delay( $segment->arr_delay, $max_delay_digits )
: q{},
diff --git a/lib/Travel/Routing/DE/DBRIS/Connection.pm b/lib/Travel/Routing/DE/DBRIS/Connection.pm
index d7c74f0..6ff4507 100644
--- a/lib/Travel/Routing/DE/DBRIS/Connection.pm
+++ b/lib/Travel/Routing/DE/DBRIS/Connection.pm
@@ -13,7 +13,7 @@ use Travel::Routing::DE::DBRIS::Connection::Segment;
our $VERSION = '0.02';
Travel::Routing::DE::DBRIS::Connection->mk_ro_accessors(
- qw(changes
+ qw(changes feasibility is_cancelled is_unscheduled is_unlikely
duration sched_duration rt_duration
sched_dep rt_dep dep
sched_arr rt_arr arr
@@ -30,11 +30,14 @@ sub new {
my $strptime = $opt{strptime_obj};
my $ref = {
- changes => $json->{umstiegsAnzahl},
- id => $json->{tripId},
- price => $json->{angebotsPreis}{betrag},
- price_unit => $json->{angebotsPreis}{waehrung},
- strptime_obj => $strptime,
+ changes => $json->{umstiegsAnzahl},
+ feasibility => $json->{ereignisZusammenfassung}{anschlussBewertungCode}
+ // -1,
+ is_unscheduled => $json->{isAlternativeVerbindung},
+ id => $json->{tripId},
+ price => $json->{angebotsPreis}{betrag},
+ price_unit => $json->{angebotsPreis}{waehrung},
+ strptime_obj => $strptime,
};
if ( $ref->{price_unit} and $ref->{price_unit} eq 'EUR' ) {
diff --git a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm
index f2278ef..1b01d77 100644
--- a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm
+++ b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm
@@ -18,7 +18,7 @@ Travel::Routing::DE::DBRIS::Connection::Segment->mk_ro_accessors(
sched_dep rt_dep dep dep_platform
sched_arr rt_arr arr arr_platform
sched_duration rt_duration duration duration_percent
- arr_delay dep_delay delay
+ arr_delay dep_delay delay feasibility is_unlikely
journey_id
occupancy occupancy_first occupancy_second
is_transfer is_walk walk_name distance_m
@@ -42,6 +42,7 @@ sub new {
train_long => $json->{verkehrsmittel}{langText},
direction => $json->{verkehrsmittel}{richtung},
distance_m => $json->{distanz},
+ feasibility => $json->{anschlussBewertungCode},
};
if ( my $ts = $json->{abfahrtsZeitpunkt} ) {
@@ -134,6 +135,9 @@ sub new {
for my $message ( @{ $json->{risNotizen} // [] } ) {
push( @{ $ref->{messages_ris} }, $message );
+ if ( $message->{key} eq 'text.realtime.journey.missed.connection' ) {
+ $ref->{is_unlikely} = 1;
+ }
}
for my $message ( @{ $json->{priorisierteMeldungen} // [] } ) {