diff options
| author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-12-22 23:01:46 +0100 | 
|---|---|---|
| committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-12-22 23:01:46 +0100 | 
| commit | 07bcce9b4129552ceaa1e48998b4f7720929fa20 (patch) | |
| tree | 2e2930f374d5d7eace613be59f391b86f0c2fff2 /lib/DBInfoscreen | |
| parent | f357bb52cd0acf6ba7039ef4af0282388b5c8a87 (diff) | |
Switch to T-S-DE-HAFAS 5.034.19.4
Diffstat (limited to 'lib/DBInfoscreen')
| -rw-r--r-- | lib/DBInfoscreen/Controller/Map.pm | 103 | ||||
| -rw-r--r-- | lib/DBInfoscreen/Controller/Stationboard.pm | 20 | ||||
| -rw-r--r-- | lib/DBInfoscreen/Helper/HAFAS.pm | 35 | 
3 files changed, 84 insertions, 74 deletions
| diff --git a/lib/DBInfoscreen/Controller/Map.pm b/lib/DBInfoscreen/Controller/Map.pm index 93f2b49..f3ba92a 100644 --- a/lib/DBInfoscreen/Controller/Map.pm +++ b/lib/DBInfoscreen/Controller/Map.pm @@ -65,10 +65,10 @@ sub estimate_train_positions {  	my $now = $opt{now}; -	my $from_dt   = $opt{from}{dep} // $opt{from}{arr}; -	my $to_dt     = $opt{to}{arr}   // $opt{to}{dep}; -	my $from_name = $opt{from}{name}; -	my $to_name   = $opt{to}{name}; +	my $from_dt   = $opt{from}->dep // $opt{from}->arr; +	my $to_dt     = $opt{to}->arr   // $opt{to}->dep; +	my $from_name = $opt{from}->loc->name; +	my $to_name   = $opt{to}->loc->name;  	my $route     = $opt{route};  	my $polyline  = $opt{polyline}; @@ -135,16 +135,23 @@ sub estimate_train_positions {  		}  	}  	else { +		$self->log->debug( +			"Did not find route indexes for $from_name → $to_name"); +		$self->log->debug( +"Falling back to $opt{from}{lat} $opt{from}{lon}  →   $opt{to}{lat} $opt{to}{lon}" +		);  		for my $ratio (@completion_ratios) {  			my $lat -			  = $opt{from}{lat} + ( $opt{to}{lat} - $opt{from}{lat} ) * $ratio; +			  = $opt{from}->loc->lat +			  + ( $opt{to}->loc->lat - $opt{from}->loc->lat ) * $ratio;  			my $lon -			  = $opt{from}{lon} + ( $opt{to}{lon} - $opt{from}{lon} ) * $ratio; +			  = $opt{from}->loc->lon +			  + ( $opt{to}->loc->lon - $opt{from}->loc->lon ) * $ratio;  			push( @train_positions, [ $lat, $lon ] );  		}  		return @train_positions;  	} -	return [ $opt{to}{lat}, $opt{to}{lon} ]; +	return [ $opt{to}->loc->lat, $opt{to}->loc->lon ];  }  # Input: @@ -172,10 +179,10 @@ sub estimate_train_positions2 {  	for my $i ( 1 .. $#route ) {  		if (    not $next_stop -			and ( $route[$i]{arr} // $route[$i]{dep} ) -			and ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) -			and $now > ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) -			and $now < ( $route[$i]{arr} // $route[$i]{dep} ) ) +			and ( $route[$i]->arr // $route[$i]->dep ) +			and ( $route[ $i - 1 ]->dep // $route[ $i - 1 ]->arr ) +			and $now > ( $route[ $i - 1 ]->dep // $route[ $i - 1 ]->arr ) +			and $now < ( $route[$i]->arr // $route[$i]->dep ) )  		{  			# HAFAS does not provide delays for past stops @@ -200,15 +207,15 @@ sub estimate_train_positions2 {  			and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) )  		{  			@train_positions -			  = ( [ $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon} ] ); +			  = ( [ $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon ] );  			$next_stop = {  				type    => 'present',  				station => $route[ $i - 1 ],  			};  		}  		$stop_distance_sum += $distance->distance_metal( -			$route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon}, -			$route[$i]{lat},       $route[$i]{lon} +			$route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon, +			$route[$i]->loc->lat,       $route[$i]->loc->lon  		) / 1000;  	} @@ -217,7 +224,7 @@ sub estimate_train_positions2 {  	}  	if ( @route and not $next_stop ) { -		@train_positions = ( [ $route[-1]{lat}, $route[-1]{lon} ] ); +		@train_positions = ( [ $route[-1]->loc->lat, $route[-1]->loc->lon ] );  		$next_stop       = {  			type    => 'present',  			station => $route[-1] @@ -240,12 +247,12 @@ sub route_to_ajax {  	my @route_entries;  	for my $stop (@stopovers) { -		my @stop_entries = ( $stop->{name} ); +		my @stop_entries = ( $stop->loc->name );  		my $platform; -		if ( my $arr = $stop->{arr} and not $stop->{arr_cancelled} ) { -			my $delay = $stop->{arr_delay} // 0; -			$platform = $stop->{arr_platform}; +		if ( my $arr = $stop->arr and not $stop->arr_cancelled ) { +			my $delay = $stop->arr_delay // 0; +			$platform = $stop->platform;  			push( @stop_entries, $arr->epoch, $delay );  		} @@ -253,9 +260,9 @@ sub route_to_ajax {  			push( @stop_entries, q{}, q{} );  		} -		if ( my $dep = $stop->{dep} and not $stop->{dep_cancelled} ) { -			my $delay = $stop->{dep_delay} // 0; -			$platform //= $stop->{dep_platform} // q{}; +		if ( my $dep = $stop->dep and not $stop->dep_cancelled ) { +			my $delay = $stop->dep_delay // 0; +			$platform //= $stop->platform // q{};  			push( @stop_entries, $dep->epoch, $delay, $platform );  		} @@ -338,51 +345,51 @@ sub route {  			# Prepare from/to markers and name/time/delay overlays for stations  			for my $stop (@route) { -				my @stop_lines = ( $stop->{name} ); +				my @stop_lines = ( $stop->loc->name ); -				if ( $from_name and $stop->{name} eq $from_name ) { +				if ( $from_name and $stop->loc->name eq $from_name ) {  					push(  						@markers,  						{ -							lon   => $stop->{lon}, -							lat   => $stop->{lat}, -							title => $stop->{name}, +							lon   => $stop->loc->lon, +							lat   => $stop->loc->lat, +							title => $stop->loc->name,  							icon  => 'goldIcon',  						}  					);  				} -				if ( $to_name and $stop->{name} eq $to_name ) { +				if ( $to_name and $stop->loc->name eq $to_name ) {  					push(  						@markers,  						{ -							lon   => $stop->{lon}, -							lat   => $stop->{lat}, -							title => $stop->{name}, +							lon   => $stop->loc->lon, +							lat   => $stop->loc->lat, +							title => $stop->loc->name,  							icon  => 'greenIcon',  						}  					);  				} -				if ( $stop->{platform} ) { -					push( @stop_lines, 'Gleis ' . $stop->{platform} ); +				if ( $stop->platform ) { +					push( @stop_lines, 'Gleis ' . $stop->platform );  				} -				if ( $stop->{arr} ) { -					my $arr_line = $stop->{arr}->strftime('Ankunft: %H:%M'); -					if ( $stop->{arr_delay} ) { -						$arr_line .= sprintf( ' (%+d)', $stop->{arr_delay} ); +				if ( $stop->arr ) { +					my $arr_line = $stop->arr->strftime('Ankunft: %H:%M'); +					if ( $stop->arr_delay ) { +						$arr_line .= sprintf( ' (%+d)', $stop->arr_delay );  					}  					push( @stop_lines, $arr_line );  				} -				if ( $stop->{dep} ) { -					my $dep_line = $stop->{dep}->strftime('Abfahrt: %H:%M'); -					if ( $stop->{dep_delay} ) { -						$dep_line .= sprintf( ' (%+d)', $stop->{dep_delay} ); +				if ( $stop->dep ) { +					my $dep_line = $stop->dep->strftime('Abfahrt: %H:%M'); +					if ( $stop->dep_delay ) { +						$dep_line .= sprintf( ' (%+d)', $stop->dep_delay );  					}  					push( @stop_lines, $dep_line );  				}  				push( @station_coordinates, -					[ [ $stop->{lat}, $stop->{lon} ], [@stop_lines], ] ); +					[ [ $stop->loc->lat, $stop->loc->lon ], [@stop_lines], ] );  			}  			push( @@ -406,12 +413,12 @@ sub route {  				ajax_polyline => join( '|',  					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),  				origin => { -					name => ( $journey->route )[0]->{name}, -					ts   => ( $journey->route )[0]->{dep}, +					name => ( $journey->route )[0]->loc->name, +					ts   => ( $journey->route )[0]->dep,  				},  				destination => {  					name => $journey->route_end, -					ts   => ( $journey->route )[-1]->{arr}, +					ts   => ( $journey->route )[-1]->arr,  				},  				train_no => $journey->number  				? ( $journey->type . ' ' . $journey->number ) @@ -478,12 +485,12 @@ sub ajax_route {  				ajax_polyline => join( '|',  					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),  				origin => { -					name => ( $journey->route )[0]->{name}, -					ts   => ( $journey->route )[0]->{dep}, +					name => ( $journey->route )[0]->loc->name, +					ts   => ( $journey->route )[0]->dep,  				},  				destination => {  					name => $journey->route_end, -					ts   => ( $journey->route )[-1]->{arr}, +					ts   => ( $journey->route )[-1]->arr,  				},  				train_no => $journey->number  				? ( $journey->type . ' ' . $journey->number ) diff --git a/lib/DBInfoscreen/Controller/Stationboard.pm b/lib/DBInfoscreen/Controller/Stationboard.pm index 66c938c..23a6ee2 100644 --- a/lib/DBInfoscreen/Controller/Stationboard.pm +++ b/lib/DBInfoscreen/Controller/Stationboard.pm @@ -834,7 +834,9 @@ sub render_train {  				my @missing_pre;  				for my $station (@hafas_stations) {  					if ( -						List::MoreUtils::any { $_->{name} eq $station->{name} } +						List::MoreUtils::any { +							$_->{name} eq $station->loc->name +						}  						@iris_stations  					  )  					{ @@ -847,7 +849,7 @@ sub render_train {  					push(  						@missing_pre,  						{ -							name  => $station->{name}, +							name  => $station->loc->name,  							hafas => 1  						}  					); @@ -857,7 +859,9 @@ sub render_train {  				my @missing_post;  				for my $station ( reverse @hafas_stations ) {  					if ( -						List::MoreUtils::any { $_->{name} eq $station->{name} } +						List::MoreUtils::any { +							$_->{name} eq $station->loc->name +						}  						@iris_stations  					  )  					{ @@ -870,7 +874,7 @@ sub render_train {  					unshift(  						@missing_post,  						{ -							name  => $station->{name}, +							name  => $station->loc->name,  							hafas => 1  						}  					); @@ -1202,7 +1206,7 @@ sub train_details {  			$res->{operator}    = $journey->operator;  			$res->{route_post_diff} -			  = [ map { { name => $_->{name} } } $journey->route ]; +			  = [ map { { name => $_->loc->name } } $journey->route ];  			for my $elem ( @{ $res->{route_post_diff} } ) {  				for my $key ( keys %{ $route_ts->{ $elem->{name} } // {} } ) {  					$elem->{$key} = $route_ts->{ $elem->{name} }{$key}; @@ -1709,7 +1713,7 @@ sub handle_result {  						train_no   => $result->number,  						journey_id => $result->id,  						via        => [ -							map { $_->{name} =~ s{,\Q$city\E}{}r } +							map { $_->loc->name =~ s{,\Q$city\E}{}r }  							  $result->route_interesting(3)  						],  						destination => $result->route_end =~ s{,\Q$city\E}{}r, @@ -1725,10 +1729,10 @@ sub handle_result {  						replaced_by        => [],  						replacement_for    => [],  						route_pre          => $admode eq 'arr' -						? [ map { $_->{name} } $result->route ] +						? [ map { $_->loc->name } $result->route ]  						: [],  						route_post => $admode eq 'arr' ? [] -						: [ map { $_->{name} } $result->route ], +						: [ map { $_->loc->name } $result->route ],  						wr_link => $result->sched_datetime  						? $result->sched_datetime->strftime('%Y%m%d%H%M')  						: undef, diff --git a/lib/DBInfoscreen/Helper/HAFAS.pm b/lib/DBInfoscreen/Helper/HAFAS.pm index e5c82e7..65cddeb 100644 --- a/lib/DBInfoscreen/Helper/HAFAS.pm +++ b/lib/DBInfoscreen/Helper/HAFAS.pm @@ -232,25 +232,24 @@ sub get_route_timestamps_p {  			my $station_is_past = 1;  			for my $stop ( $journey->route ) { -				my $name = $stop->{name}; -				$ret->{$name} = $ret->{ $stop->{eva} } = { -					name           => $stop->{name}, -					eva            => $stop->{eva}, -					sched_arr      => $stop->{sched_arr}, -					sched_dep      => $stop->{sched_dep}, -					rt_arr         => $stop->{rt_arr}, -					rt_dep         => $stop->{rt_dep}, -					arr_delay      => $stop->{arr_delay}, -					dep_delay      => $stop->{dep_delay}, -					arr_cancelled  => $stop->{arr_cancelled}, -					dep_cancelled  => $stop->{dep_cancelled}, -					platform       => $stop->{platform}, -					sched_platform => $stop->{sched_platform}, -					load           => $stop->{load}, +				my $name = $stop->loc->name; +				$ret->{$name} = $ret->{ $stop->loc->eva } = { +					name           => $stop->loc->name, +					eva            => $stop->loc->eva, +					sched_arr      => $stop->sched_arr, +					sched_dep      => $stop->sched_dep, +					rt_arr         => $stop->rt_arr, +					rt_dep         => $stop->rt_dep, +					arr_delay      => $stop->arr_delay, +					dep_delay      => $stop->dep_delay, +					arr_cancelled  => $stop->arr_cancelled, +					dep_cancelled  => $stop->dep_cancelled, +					platform       => $stop->platform, +					sched_platform => $stop->sched_platform, +					load           => $stop->load,  					isCancelled    => ( -						( $stop->{arr_cancelled} or not $stop->{sched_arr} ) -						  and -						  ( $stop->{dep_cancelled} or not $stop->{sched_dep} ) +						      ( $stop->arr_cancelled or not $stop->sched_arr ) +						  and ( $stop->dep_cancelled or not $stop->sched_dep )  					),  				};  				if ( | 
