diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-19 00:01:19 +0100 |
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2025-01-19 00:01:19 +0100 |
| commit | bfdedd4d6a737a5aaa59aada43fdb24576745f5c (patch) | |
| tree | 4d108405e47b4f5870f7437f79708be80ad920ff | |
| parent | 9bac2c56e91db08d9081727549a8bbf84f3a7ee9 (diff) | |
add mot filter ,transfers, and routes
| -rwxr-xr-x | bin/dbris | 52 | ||||
| -rw-r--r-- | lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm | 52 |
2 files changed, 94 insertions, 10 deletions
@@ -32,14 +32,15 @@ my $output_bold = -t STDOUT ? "\033[1m" : q{}; my $output_reset = -t STDOUT ? "\033[0m" : q{}; GetOptions( - 'd|date=s' => \$date, - 'h|help' => sub { show_help(0) }, - 't|time=s' => \$time, - 'V|version' => \&show_version, - 'cache!' => \$use_cache, - 'devmode' => \$developer_mode, - 'json' => \$json_output, - 'raw-json' => \$raw_json_output, + 'd|date=s' => \$date, + 'h|help' => sub { show_help(0) }, + 'm|modes-of-transit=s' => \$mots, + 't|time=s' => \$time, + 'V|version' => \&show_version, + 'cache!' => \$use_cache, + 'devmode' => \$developer_mode, + 'json' => \$json_output, + 'raw-json' => \$raw_json_output, ) or show_help(1); @@ -129,6 +130,10 @@ if ( $date or $time ) { $opt{datetime} = $dt; } +if ($mots) { + $opt{modes_of_transit} = [ split( qr{, *}, $mots ) ]; +} + sub show_help { my ($code) = @_; @@ -201,9 +206,18 @@ for my $connection ( $ris->connections ) { my $header = q{}; for my $segment ( $connection->segments ) { - $header .= sprintf( ' %s', $segment->train_short, ); + if ( $segment->train_short ) { + $header .= sprintf( ' %s', $segment->train_short ); + } + elsif ( $segment->is_transfer ) { + $header .= sprintf( ' %.1fkm', $segment->distance_m / 1e3 ); + } + else { + $header .= q{ ??}; + } } + say q{}; printf( "%s (%02d:%02d) %s %s%s\n\n", $connection->dep @@ -215,10 +229,28 @@ for my $connection ( $ris->connections ) { $header, ); for my $segment ( $connection->segments ) { - printf( "%s → %s\n", $segment->train_mid, $segment->direction ); + if ( $segment->is_transfer ) { + for my $note ( $segment->transfer_notes ) { + say $note; + } + } + elsif ( $segment->direction ) { + printf( "${output_bold}%s${output_reset} → %s %s\n", + $segment->train_mid, $segment->direction, + format_occupancy($segment) ); + } + else { + printf( "${output_bold}%s${output_reset}\n", $segment->train_long ); + } printf( "%s ab %s\n", $segment->dep->strftime('%H:%M'), $segment->dep_name ); + + for my $stop ( $segment->route ) { + printf( "%s %s %s\n", + $stop->arr ? $stop->arr->strftime('%H:%M') : q{ }, + format_occupancy($stop), $stop->name, ); + } printf( "%s an %s\n", $segment->arr->strftime('%H:%M'), $segment->arr_name ); diff --git a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm index b8134bb..f4d82c3 100644 --- a/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm +++ b/lib/Travel/Routing/DE/DBRIS/Connection/Segment.pm @@ -7,6 +7,7 @@ use 5.020; use parent 'Class::Accessor'; use DateTime::Duration; +use Travel::Status::DE::DBRIS::Location; our $VERSION = '0.01'; @@ -18,6 +19,8 @@ Travel::Routing::DE::DBRIS::Connection::Segment->mk_ro_accessors( sched_arr rt_arr arr sched_duration rt_duration duration duration_percent journey_id + occupancy occupancy_first occupancy_second + is_transfer distance_m ) ); @@ -71,9 +74,58 @@ sub new { } $ref->{duration} = $ref->{rt_duration} // $ref->{sched_duration}; + for my $occupancy ( @{ $json->{auslastungsmeldungen} // [] } ) { + if ( $occupancy->{klasse} eq 'KLASSE_1' ) { + $ref->{occupancy_first} = $occupancy->{stufe}; + } + if ( $occupancy->{klasse} eq 'KLASSE_2' ) { + $ref->{occupancy_second} = $occupancy->{stufe}; + } + } + + if ( $ref->{occupancy_first} and $ref->{occupancy_second} ) { + $ref->{occupancy} + = ( $ref->{occupancy_first} + $ref->{occupancy_second} ) / 2; + } + elsif ( $ref->{occupancy_first} ) { + $ref->{occupancy} = $ref->{occupancy_first}; + } + elsif ( $ref->{occupancy_second} ) { + $ref->{occupancy} = $ref->{occupancy_second}; + } + + for my $stop ( @{ $json->{halte} // [] } ) { + push( + @{ $ref->{route} }, + Travel::Status::DE::DBRIS::Location->new( + json => $stop, + strptime_obj => $strptime + ) + ); + } + + if ( $json->{verkehrsmittel}{typ} eq 'TRANSFER' ) { + $ref->{is_transfer} = 1; + $ref->{transfer_notes} + = [ map { $_->{value} } @{ $json->{transferNotes} // [] } ]; + $ref->{distance_m} = $json->{distanz}; + } + bless( $ref, $obj ); return $ref; } +sub route { + my ($self) = @_; + + return @{ $self->{route} // [] }[ 1 .. $#{ $self->{route} } - 1 ]; +} + +sub transfer_notes { + my ($self) = @_; + + return @{ $self->{transfer_notes} // [] }; +} + 1; |
