From 2b2fcbdee810b59ecfec85929f134c07f5aa40c8 Mon Sep 17 00:00:00 2001 From: Birte Kristina Friesel Date: Sun, 19 Nov 2023 12:59:18 +0100 Subject: Use Travel::Status::DE::HAFAS::Journey for journey data --- Build.PL | 1 + bin/hafas | 15 ++-- cpanfile | 1 + lib/Travel/Routing/DE/HAFAS.pm | 3 +- lib/Travel/Routing/DE/HAFAS/Connection.pm | 1 + lib/Travel/Routing/DE/HAFAS/Connection/Section.pm | 88 ++++++----------------- 6 files changed, 35 insertions(+), 74 deletions(-) diff --git a/Build.PL b/Build.PL index f80720a..d3dc192 100644 --- a/Build.PL +++ b/Build.PL @@ -31,6 +31,7 @@ Module::Build->new( 'LWP::UserAgent' => 0, 'LWP::Protocol::https' => 0, 'Travel::Status::DE::HAFAS' => 0, + 'Travel::Status::DE::HAFAS::Journey' => '5.00', 'Travel::Status::DE::HAFAS::Location' => '5.00', 'Travel::Status::DE::HAFAS::Message' => '4.19', }, diff --git a/bin/hafas b/bin/hafas index deccb63..5bb3634 100755 --- a/bin/hafas +++ b/bin/hafas @@ -295,16 +295,16 @@ for my $res ( $hafas->connections ) { $glance .= sprintf( ' (%01d:%02d) %s', $sec->transfer_duration->in_units( 'hours', 'minutes' ), - $sec->name + $sec->journey->name ); } else { $negative_transfer = 1; - $glance .= sprintf( ' (--:--) %s', $sec->name ); + $glance .= sprintf( ' (--:--) %s', $sec->journey->name ); } } else { - $glance .= $sec->name; + $glance .= $sec->journey->name; } } @@ -348,9 +348,12 @@ for my $res ( $hafas->connections ) { for my $sec ( $res->sections ) { if ( $sec->type eq 'JNY' ) { - printf( "${output_bold}%s${output_reset} → %s %s\n", - $sec->name, $sec->direction, - display_occupancies( $sec->load ) ); + printf( + "${output_bold}%s${output_reset} → %s %s\n", + $sec->journey->name, + $sec->journey->direction, + display_occupancies( $sec->load ) + ); printf( "%-5s %-${delay_fmt}s ab %s%s%s\n", $sec->dep_cancelled diff --git a/cpanfile b/cpanfile index 42c9567..510e4ef 100644 --- a/cpanfile +++ b/cpanfile @@ -10,6 +10,7 @@ requires 'List::Util'; requires 'LWP::UserAgent'; requires 'LWP::Protocol::https'; requires 'Travel::Status::DE::HAFAS'; +requires 'Travel::Status::DE::HAFAS::Journey', '5.00'; requires 'Travel::Status::DE::HAFAS::Location', '5.00'; requires 'Travel::Status::DE::HAFAS::Message', '4.19'; diff --git a/lib/Travel/Routing/DE/HAFAS.pm b/lib/Travel/Routing/DE/HAFAS.pm index 4890c3c..ec5689b 100644 --- a/lib/Travel/Routing/DE/HAFAS.pm +++ b/lib/Travel/Routing/DE/HAFAS.pm @@ -647,7 +647,8 @@ Travel::Routing::DE::HAFAS - Interface to HAFAS itinerary services for my $sec ($con->sections) { if ( $sec->type eq 'JNY' ) { printf("%s -> %s\n%s ab %s\n%s an %s\n\n", - $sec->name, $sec->direction, + $sec->journey->name, + $sec->journey->direction, $sec->dep->strftime('%H:%M'), $sec->dep_loc->name, $sec->arr->strftime('%H:%M'), diff --git a/lib/Travel/Routing/DE/HAFAS/Connection.pm b/lib/Travel/Routing/DE/HAFAS/Connection.pm index 64583e9..1600ddf 100644 --- a/lib/Travel/Routing/DE/HAFAS/Connection.pm +++ b/lib/Travel/Routing/DE/HAFAS/Connection.pm @@ -60,6 +60,7 @@ sub new { time_zone => 'Europe/Berlin' ); + # dProgType/aProgType: CORRECTED oder PROGNOSED my $sched_dep = $connection->{dep}{dTimeS}; my $rt_dep = $connection->{dep}{dTimeR}; my $sched_arr = $connection->{arr}{aTimeS}; diff --git a/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm b/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm index b298419..ba1347a 100644 --- a/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm +++ b/lib/Travel/Routing/DE/HAFAS/Connection/Section.pm @@ -9,13 +9,14 @@ use 5.014; use parent 'Class::Accessor'; use DateTime::Duration; use Travel::Routing::DE::HAFAS::Utils; +use Travel::Status::DE::HAFAS::Journey; our $VERSION = '0.01'; Travel::Routing::DE::HAFAS::Connection::Section->mk_ro_accessors( qw(type schep_dep rt_dep sched_arr rt_arr dep arr arr_delay dep_delay journey distance duration transfer_duration dep_loc arr_loc dep_platform arr_platform dep_cancelled arr_cancelled - operator id name category category_long class number line line_no load delay direction) + load) ); # {{{ Constructor @@ -27,7 +28,6 @@ sub new { my $sec = $opt{sec}; my $date = $opt{date}; my $locs = $opt{locL}; - my @prodL = @{ $opt{common}{prodL} // [] }; # himL may only be present in departure monitor mode my @remL = @{ $opt{common}{remL} // [] }; @@ -78,8 +78,6 @@ sub new { $tco->{ $tco_kv->{c} } = $tco_kv->{r}; } - # TODO operator - my $ref = { type => $sec->{type}, sched_dep => $sched_dep, @@ -108,30 +106,12 @@ sub new { if ( $sec->{type} eq 'JNY' ) { - my $journey = $sec->{jny}; - my $product = $prodL[ $journey->{prodX} ]; - $ref->{id} = $journey->{jid}; - $ref->{direction} = $journey->{dirTxt}; - $ref->{name} = $product->{addName} // $product->{name}; - $ref->{category} = $product->{prodCtx}{catOut}; - $ref->{category_long} = $product->{prodCtx}{catOutL}; - $ref->{class} = $product->{cls}; - $ref->{number} = $product->{prodCtx}{num}; - $ref->{line} = $ref->{name}; - $ref->{line_no} = $product->{prodCtx}{line}; - - if ( $ref->{name} - and $ref->{category} - and $ref->{name} eq $ref->{category} - and $product->{nameS} ) - { - $ref->{name} .= ' ' . $product->{nameS}; - } - - my @stops; - for my $stop ( @{ $journey->{stopL} // [] } ) { - my $loc = $locs->[ $stop->{locX} ]; - } + $ref->{journey} = Travel::Status::DE::HAFAS::Journey->new( + common => $opt{common}, + locL => $locs, + journey => $sec->{jny}, + hafas => $hafas, + ); } elsif ( $sec->{type} eq 'WALK' ) { $ref->{distance} = $sec->{gis}{dist}; @@ -186,13 +166,16 @@ Travel::Routing::DE::HAFAS::Connection::Section - A single trip between two stop # $connection is a Travel::Routing::DE::HAFAS::Connection object for my $sec ( $connection->sections ) { - printf("%s -> %s\n%s ab %s\n%s an %s\n\n", - $sec->name, $sec->direction, - $sec->dep->strftime('%H:%M'), - $sec->dep_loc->name, - $sec->arr->strftime('%H:%M'), - $sec->arr_loc->name, - ); + if ($sec->type eq 'JNY') { + printf("%s -> %s\n%s ab %s\n%s an %s\n\n", + $sec->journey->name, + $sec->journey->direction, + $sec->dep->strftime('%H:%M'), + $sec->dep_loc->name, + $sec->arr->strftime('%H:%M'), + $sec->arr_loc->name, + ); + } } =head1 VERSION @@ -257,13 +240,6 @@ Travel::Status::DE::HAFAS::Location(3pm) object describing the departure stop. =item $section->dep_platform -Deprarture platform as string, not necessarily numeric. Undef if unknown. - -=item $section->direction (JNY) - -Travel direction of this trip; this is typically the text printed on the -transport vehicle itself. May differ from its terminus. - =item $section->distance (WALK) Walking distance in meters. Does not take vertical elevation changes into @@ -274,23 +250,10 @@ account. DateTime::Duration(3pm) oobject holding the walking duration. Typically assumes a slow pace. -=item $section->id (JNY) - -HAFAS-internal journey ID. - -=item $section->line (JNY) - -Trip or line name in a format like "Bus SB16" (Bus line SB16), "RE 42" -(RegionalExpress train 42) or "IC 2901" (InterCity train 2901, no line -information). Note that this accessor does not return line information for -IC/ICE/EC services, even if it is available. Use B for those. - -=item $section->line_no (JNY) +=item $section->journey (JNY) -Line identifier; undef if unknown. -The line identifier may be a single number such as "11" (underground train line -U 11), a single word such as "AIR" or a combination (e.g. "SB16"). May also -provide line numbers of IC/ICE services. +Travel::Status::DE::HAFAS::Journey(3pm) instance describing the journey +(mode of transport, intermediate stops, etc.). =item $sec->load @@ -305,15 +268,6 @@ List of Travel::Status::DE::HAFAS::Message(3pm) objects associated with this connection section. Typically contains messages related to the mode of transport, such as construction sites, Wi-Fi availability, and the like. -=item $section->name (JNY) - -Trip or line name in a format like "Bus SB16" (Bus line SB16) or "RE 10111" -(RegionalExpress train 10111, no line information). - -=item $section->number (JNY) - -Trip number (e.g. train number); undef if unknown. - =item $section->rt_arr DateTime(3pm) object holding real-time arrival if available. -- cgit v1.2.3