Unverified Commit 07bcce9b authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Switch to T-S-DE-HAFAS 5.03

parent f357bb52
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -12,6 +12,6 @@ requires 'LWP::Protocol::https';
requires 'Mojolicious';
requires 'Mojolicious';
requires 'Mojolicious::Plugin::I18N';
requires 'Mojolicious::Plugin::I18N';
requires 'Travel::Status::DE::DBWagenreihung', '0.06';
requires 'Travel::Status::DE::DBWagenreihung', '0.06';
requires 'Travel::Status::DE::HAFAS', '== 4.19';
requires 'Travel::Status::DE::HAFAS', '>= 5.03';
requires 'Travel::Status::DE::IRIS';
requires 'Travel::Status::DE::IRIS';
requires 'XML::LibXML';
requires 'XML::LibXML';
+55 −48
Original line number Original line Diff line number Diff line
@@ -65,10 +65,10 @@ sub estimate_train_positions {


	my $now = $opt{now};
	my $now = $opt{now};


	my $from_dt   = $opt{from}{dep} // $opt{from}{arr};
	my $from_dt   = $opt{from}->dep // $opt{from}->arr;
	my $to_dt     = $opt{to}{arr}   // $opt{to}{dep};
	my $to_dt     = $opt{to}->arr   // $opt{to}->dep;
	my $from_name = $opt{from}{name};
	my $from_name = $opt{from}->loc->name;
	my $to_name   = $opt{to}{name};
	my $to_name   = $opt{to}->loc->name;
	my $route     = $opt{route};
	my $route     = $opt{route};
	my $polyline  = $opt{polyline};
	my $polyline  = $opt{polyline};


@@ -135,16 +135,23 @@ sub estimate_train_positions {
		}
		}
	}
	}
	else {
	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) {
		for my $ratio (@completion_ratios) {
			my $lat
			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
			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 ] );
			push( @train_positions, [ $lat, $lon ] );
		}
		}
		return @train_positions;
		return @train_positions;
	}
	}
	return [ $opt{to}{lat}, $opt{to}{lon} ];
	return [ $opt{to}->loc->lat, $opt{to}->loc->lon ];
}
}


# Input:
# Input:
@@ -172,10 +179,10 @@ sub estimate_train_positions2 {


	for my $i ( 1 .. $#route ) {
	for my $i ( 1 .. $#route ) {
		if (    not $next_stop
		if (    not $next_stop
			and ( $route[$i]{arr} // $route[$i]{dep} )
			and ( $route[$i]->arr // $route[$i]->dep )
			and ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} )
			and ( $route[ $i - 1 ]->dep // $route[ $i - 1 ]->arr )
			and $now > ( $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 $now < ( $route[$i]->arr // $route[$i]->dep ) )
		{
		{


			# HAFAS does not provide delays for past stops
			# 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} ) )
			and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) )
		{
		{
			@train_positions
			@train_positions
			  = ( [ $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon} ] );
			  = ( [ $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon ] );
			$next_stop = {
			$next_stop = {
				type    => 'present',
				type    => 'present',
				station => $route[ $i - 1 ],
				station => $route[ $i - 1 ],
			};
			};
		}
		}
		$stop_distance_sum += $distance->distance_metal(
		$stop_distance_sum += $distance->distance_metal(
			$route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon},
			$route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon,
			$route[$i]{lat},       $route[$i]{lon}
			$route[$i]->loc->lat,       $route[$i]->loc->lon
		) / 1000;
		) / 1000;
	}
	}


@@ -217,7 +224,7 @@ sub estimate_train_positions2 {
	}
	}


	if ( @route and not $next_stop ) {
	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       = {
		$next_stop       = {
			type    => 'present',
			type    => 'present',
			station => $route[-1]
			station => $route[-1]
@@ -240,12 +247,12 @@ sub route_to_ajax {
	my @route_entries;
	my @route_entries;


	for my $stop (@stopovers) {
	for my $stop (@stopovers) {
		my @stop_entries = ( $stop->{name} );
		my @stop_entries = ( $stop->loc->name );
		my $platform;
		my $platform;


		if ( my $arr = $stop->{arr} and not $stop->{arr_cancelled} ) {
		if ( my $arr = $stop->arr and not $stop->arr_cancelled ) {
			my $delay = $stop->{arr_delay} // 0;
			my $delay = $stop->arr_delay // 0;
			$platform = $stop->{arr_platform};
			$platform = $stop->platform;


			push( @stop_entries, $arr->epoch, $delay );
			push( @stop_entries, $arr->epoch, $delay );
		}
		}
@@ -253,9 +260,9 @@ sub route_to_ajax {
			push( @stop_entries, q{}, q{} );
			push( @stop_entries, q{}, q{} );
		}
		}


		if ( my $dep = $stop->{dep} and not $stop->{dep_cancelled} ) {
		if ( my $dep = $stop->dep and not $stop->dep_cancelled ) {
			my $delay = $stop->{dep_delay} // 0;
			my $delay = $stop->dep_delay // 0;
			$platform //= $stop->{dep_platform} // q{};
			$platform //= $stop->platform // q{};


			push( @stop_entries, $dep->epoch, $delay, $platform );
			push( @stop_entries, $dep->epoch, $delay, $platform );
		}
		}
@@ -338,51 +345,51 @@ sub route {


			# Prepare from/to markers and name/time/delay overlays for stations
			# Prepare from/to markers and name/time/delay overlays for stations
			for my $stop (@route) {
			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(
					push(
						@markers,
						@markers,
						{
						{
							lon   => $stop->{lon},
							lon   => $stop->loc->lon,
							lat   => $stop->{lat},
							lat   => $stop->loc->lat,
							title => $stop->{name},
							title => $stop->loc->name,
							icon  => 'goldIcon',
							icon  => 'goldIcon',
						}
						}
					);
					);
				}
				}
				if ( $to_name and $stop->{name} eq $to_name ) {
				if ( $to_name and $stop->loc->name eq $to_name ) {
					push(
					push(
						@markers,
						@markers,
						{
						{
							lon   => $stop->{lon},
							lon   => $stop->loc->lon,
							lat   => $stop->{lat},
							lat   => $stop->loc->lat,
							title => $stop->{name},
							title => $stop->loc->name,
							icon  => 'greenIcon',
							icon  => 'greenIcon',
						}
						}
					);
					);
				}
				}


				if ( $stop->{platform} ) {
				if ( $stop->platform ) {
					push( @stop_lines, 'Gleis ' . $stop->{platform} );
					push( @stop_lines, 'Gleis ' . $stop->platform );
				}
				}
				if ( $stop->{arr} ) {
				if ( $stop->arr ) {
					my $arr_line = $stop->{arr}->strftime('Ankunft: %H:%M');
					my $arr_line = $stop->arr->strftime('Ankunft: %H:%M');
					if ( $stop->{arr_delay} ) {
					if ( $stop->arr_delay ) {
						$arr_line .= sprintf( ' (%+d)', $stop->{arr_delay} );
						$arr_line .= sprintf( ' (%+d)', $stop->arr_delay );
					}
					}
					push( @stop_lines, $arr_line );
					push( @stop_lines, $arr_line );
				}
				}
				if ( $stop->{dep} ) {
				if ( $stop->dep ) {
					my $dep_line = $stop->{dep}->strftime('Abfahrt: %H:%M');
					my $dep_line = $stop->dep->strftime('Abfahrt: %H:%M');
					if ( $stop->{dep_delay} ) {
					if ( $stop->dep_delay ) {
						$dep_line .= sprintf( ' (%+d)', $stop->{dep_delay} );
						$dep_line .= sprintf( ' (%+d)', $stop->dep_delay );
					}
					}
					push( @stop_lines, $dep_line );
					push( @stop_lines, $dep_line );
				}
				}


				push( @station_coordinates,
				push( @station_coordinates,
					[ [ $stop->{lat}, $stop->{lon} ], [@stop_lines], ] );
					[ [ $stop->loc->lat, $stop->loc->lon ], [@stop_lines], ] );
			}
			}


			push(
			push(
@@ -406,12 +413,12 @@ sub route {
				ajax_polyline => join( '|',
				ajax_polyline => join( '|',
					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),
					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),
				origin => {
				origin => {
					name => ( $journey->route )[0]->{name},
					name => ( $journey->route )[0]->loc->name,
					ts   => ( $journey->route )[0]->{dep},
					ts   => ( $journey->route )[0]->dep,
				},
				},
				destination => {
				destination => {
					name => $journey->route_end,
					name => $journey->route_end,
					ts   => ( $journey->route )[-1]->{arr},
					ts   => ( $journey->route )[-1]->arr,
				},
				},
				train_no => $journey->number
				train_no => $journey->number
				? ( $journey->type . ' ' . $journey->number )
				? ( $journey->type . ' ' . $journey->number )
@@ -478,12 +485,12 @@ sub ajax_route {
				ajax_polyline => join( '|',
				ajax_polyline => join( '|',
					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),
					map { join( ';', @{$_} ) } @{ $train_pos->{positions} } ),
				origin => {
				origin => {
					name => ( $journey->route )[0]->{name},
					name => ( $journey->route )[0]->loc->name,
					ts   => ( $journey->route )[0]->{dep},
					ts   => ( $journey->route )[0]->dep,
				},
				},
				destination => {
				destination => {
					name => $journey->route_end,
					name => $journey->route_end,
					ts   => ( $journey->route )[-1]->{arr},
					ts   => ( $journey->route )[-1]->arr,
				},
				},
				train_no => $journey->number
				train_no => $journey->number
				? ( $journey->type . ' ' . $journey->number )
				? ( $journey->type . ' ' . $journey->number )
+12 −8
Original line number Original line Diff line number Diff line
@@ -834,7 +834,9 @@ sub render_train {
				my @missing_pre;
				my @missing_pre;
				for my $station (@hafas_stations) {
				for my $station (@hafas_stations) {
					if (
					if (
						List::MoreUtils::any { $_->{name} eq $station->{name} }
						List::MoreUtils::any {
							$_->{name} eq $station->loc->name
						}
						@iris_stations
						@iris_stations
					  )
					  )
					{
					{
@@ -847,7 +849,7 @@ sub render_train {
					push(
					push(
						@missing_pre,
						@missing_pre,
						{
						{
							name  => $station->{name},
							name  => $station->loc->name,
							hafas => 1
							hafas => 1
						}
						}
					);
					);
@@ -857,7 +859,9 @@ sub render_train {
				my @missing_post;
				my @missing_post;
				for my $station ( reverse @hafas_stations ) {
				for my $station ( reverse @hafas_stations ) {
					if (
					if (
						List::MoreUtils::any { $_->{name} eq $station->{name} }
						List::MoreUtils::any {
							$_->{name} eq $station->loc->name
						}
						@iris_stations
						@iris_stations
					  )
					  )
					{
					{
@@ -870,7 +874,7 @@ sub render_train {
					unshift(
					unshift(
						@missing_post,
						@missing_post,
						{
						{
							name  => $station->{name},
							name  => $station->loc->name,
							hafas => 1
							hafas => 1
						}
						}
					);
					);
@@ -1202,7 +1206,7 @@ sub train_details {
			$res->{operator}    = $journey->operator;
			$res->{operator}    = $journey->operator;


			$res->{route_post_diff}
			$res->{route_post_diff}
			  = [ map { { name => $_->{name} } } $journey->route ];
			  = [ map { { name => $_->loc->name } } $journey->route ];
			for my $elem ( @{ $res->{route_post_diff} } ) {
			for my $elem ( @{ $res->{route_post_diff} } ) {
				for my $key ( keys %{ $route_ts->{ $elem->{name} } // {} } ) {
				for my $key ( keys %{ $route_ts->{ $elem->{name} } // {} } ) {
					$elem->{$key} = $route_ts->{ $elem->{name} }{$key};
					$elem->{$key} = $route_ts->{ $elem->{name} }{$key};
@@ -1709,7 +1713,7 @@ sub handle_result {
						train_no   => $result->number,
						train_no   => $result->number,
						journey_id => $result->id,
						journey_id => $result->id,
						via        => [
						via        => [
							map { $_->{name} =~ s{,\Q$city\E}{}r }
							map { $_->loc->name =~ s{,\Q$city\E}{}r }
							  $result->route_interesting(3)
							  $result->route_interesting(3)
						],
						],
						destination => $result->route_end =~ s{,\Q$city\E}{}r,
						destination => $result->route_end =~ s{,\Q$city\E}{}r,
@@ -1725,10 +1729,10 @@ sub handle_result {
						replaced_by        => [],
						replaced_by        => [],
						replacement_for    => [],
						replacement_for    => [],
						route_pre          => $admode eq 'arr'
						route_pre          => $admode eq 'arr'
						? [ map { $_->{name} } $result->route ]
						? [ map { $_->loc->name } $result->route ]
						: [],
						: [],
						route_post => $admode eq 'arr' ? []
						route_post => $admode eq 'arr' ? []
						: [ map { $_->{name} } $result->route ],
						: [ map { $_->loc->name } $result->route ],
						wr_link => $result->sched_datetime
						wr_link => $result->sched_datetime
						? $result->sched_datetime->strftime('%Y%m%d%H%M')
						? $result->sched_datetime->strftime('%Y%m%d%H%M')
						: undef,
						: undef,
+17 −18
Original line number Original line Diff line number Diff line
@@ -232,25 +232,24 @@ sub get_route_timestamps_p {


			my $station_is_past = 1;
			my $station_is_past = 1;
			for my $stop ( $journey->route ) {
			for my $stop ( $journey->route ) {
				my $name = $stop->{name};
				my $name = $stop->loc->name;
				$ret->{$name} = $ret->{ $stop->{eva} } = {
				$ret->{$name} = $ret->{ $stop->loc->eva } = {
					name           => $stop->{name},
					name           => $stop->loc->name,
					eva            => $stop->{eva},
					eva            => $stop->loc->eva,
					sched_arr      => $stop->{sched_arr},
					sched_arr      => $stop->sched_arr,
					sched_dep      => $stop->{sched_dep},
					sched_dep      => $stop->sched_dep,
					rt_arr         => $stop->{rt_arr},
					rt_arr         => $stop->rt_arr,
					rt_dep         => $stop->{rt_dep},
					rt_dep         => $stop->rt_dep,
					arr_delay      => $stop->{arr_delay},
					arr_delay      => $stop->arr_delay,
					dep_delay      => $stop->{dep_delay},
					dep_delay      => $stop->dep_delay,
					arr_cancelled  => $stop->{arr_cancelled},
					arr_cancelled  => $stop->arr_cancelled,
					dep_cancelled  => $stop->{dep_cancelled},
					dep_cancelled  => $stop->dep_cancelled,
					platform       => $stop->{platform},
					platform       => $stop->platform,
					sched_platform => $stop->{sched_platform},
					sched_platform => $stop->sched_platform,
					load           => $stop->{load},
					load           => $stop->load,
					isCancelled    => (
					isCancelled    => (
						( $stop->{arr_cancelled} or not $stop->{sched_arr} )
						      ( $stop->arr_cancelled or not $stop->sched_arr )
						  and
						  and ( $stop->dep_cancelled or not $stop->sched_dep )
						  ( $stop->{dep_cancelled} or not $stop->{sched_dep} )
					),
					),
				};
				};
				if (
				if (
+4 −4
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@ data-poly="<%= stash('ajax_polyline') %>"
% if (my $next = stash('next_stop')) {
% if (my $next = stash('next_stop')) {
	<div class="nextstop">
	<div class="nextstop">
	% if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) {
	% if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) {
		<%= l 'Aufenthalt in' %> <strong><%= $next->{station}{name} %></strong>
		<%= l 'Aufenthalt in' %> <strong><%= $next->{station}->loc->name %></strong>
		% if ($next->{station}{platform}) {
		% if ($next->{station}{platform}) {
			<%= l 'an Gleis' %> <strong><%= $next->{station}{platform} %></strong>
			<%= l 'an Gleis' %> <strong><%= $next->{station}{platform} %></strong>
		% }
		% }
@@ -24,7 +24,7 @@ data-poly="<%= stash('ajax_polyline') %>"
		% }
		% }
	% }
	% }
	% elsif ($next->{type} eq 'present' and $next->{station}{dep}) {
	% elsif ($next->{type} eq 'present' and $next->{station}{dep}) {
		<%= l 'Abfahrt in' %> <strong><%= $next->{station}{name} %></strong>
		<%= l 'Abfahrt in' %> <strong><%= $next->{station}->loc->name %></strong>
		% if ($next->{station}{platform}) {
		% if ($next->{station}{platform}) {
			<%= l 'von Gleis' %> <strong><%= $next->{station}{platform} %></strong>
			<%= l 'von Gleis' %> <strong><%= $next->{station}{platform} %></strong>
		% }
		% }
@@ -52,7 +52,7 @@ data-poly="<%= stash('ajax_polyline') %>"
	% }
	% }
	% elsif ($next->{type} eq 'next' and $next->{station}{arr}) {
	% elsif ($next->{type} eq 'next' and $next->{station}{arr}) {
		%= l 'Nächster Halt:'
		%= l 'Nächster Halt:'
		<strong><%= $next->{station}{name} %></strong>
		<strong><%= $next->{station}->loc->name %></strong>
		<%= l 'um' %> <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
		<%= l 'um' %> <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong>
		% if ($next->{station}{arr_delay}) {
		% if ($next->{station}{arr_delay}) {
			%= sprintf('(%+d)', $next->{station}{arr_delay})
			%= sprintf('(%+d)', $next->{station}{arr_delay})
@@ -63,7 +63,7 @@ data-poly="<%= stash('ajax_polyline') %>"
	% }
	% }
	% elsif ($next->{type} eq 'next') {
	% elsif ($next->{type} eq 'next') {
		%= l 'Nächster Halt:'
		%= l 'Nächster Halt:'
		<strong><%= $next->{station}{name} %></strong>
		<strong><%= $next->{station}->loc->name %></strong>
		% if ($next->{station}{platform}) {
		% if ($next->{station}{platform}) {
			<%= l 'auf Gleis' %> <strong><%= $next->{station}{platform} %></strong>
			<%= l 'auf Gleis' %> <strong><%= $next->{station}{platform} %></strong>
		% }
		% }