Loading lib/DBInfoscreen/Controller/Map.pm +50 −26 Original line number Diff line number Diff line Loading @@ -20,12 +20,12 @@ my $strp = DateTime::Format::Strptime->new( ); # Input: # - polyline: Travel::Status::DE::HAFAS::Journey->polyline # - polyline: [{lat, lon, name?}, ...] # - from_name: station name # - to_name: station name # Ouptut: # - from_index: polyline index that corresponds to from_name # - to_index: polyline index that corresponds to to_name # - from_index: polyline index where name eq from_name # - to_index: polyline index where name eq to_name sub get_route_indexes { my ( $polyline, $from_name, $to_name ) = @_; my ( $from_index, $to_index ); Loading @@ -51,9 +51,9 @@ sub get_route_indexes { # Input: # now: DateTime # from: current/previous stop # {dep => DateTime, name => str, lat => float, lon => float} # {arr => DateTime, dep => DateTime, name => str, lat => float, lon => float} # to: next stop # {arr => DateTime, name => str, lat => float, lon => float} # {arr => DateTime, dep => DateTime, name => str, lat => float, lon => float} # route: Travel::Status::DE::HAFAS::Journey->route # polyline: Travel::Status::DE::HAFAS::Journey->polyline (list of lon/lat hashes) # Output: list of estimated train positions in [lat, lon] format. Loading @@ -66,10 +66,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}->loc->name; my $to_name = $opt{to}->loc->name; 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 $route = $opt{route}; my $polyline = $opt{polyline}; Loading Loading @@ -143,16 +143,14 @@ sub estimate_train_positions { ); for my $ratio (@completion_ratios) { my $lat = $opt{from}->loc->lat + ( $opt{to}->loc->lat - $opt{from}->loc->lat ) * $ratio; = $opt{from}{lat} + ( $opt{to}{lat} - $opt{from}{lat} ) * $ratio; my $lon = $opt{from}->loc->lon + ( $opt{to}->loc->lon - $opt{from}->loc->lon ) * $ratio; = $opt{from}{lon} + ( $opt{to}{lon} - $opt{from}{lon} ) * $ratio; push( @train_positions, [ $lat, $lon ] ); } return @train_positions; } return [ $opt{to}->loc->lat, $opt{to}->loc->lon ]; return [ $opt{to}{lat}, $opt{to}{lon} ]; } # Input: Loading @@ -163,6 +161,8 @@ sub estimate_train_positions { # name: str # arr: DateTime # dep: DateTime # arr_delay: int # dep_delay: int # polyline: ref to Travel::Status::DE::HAFAS::Journey polyline list # Output: # next_stop: {type, station} Loading @@ -180,10 +180,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 Loading @@ -208,15 +208,15 @@ sub estimate_train_positions2 { and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) ) { @train_positions = ( [ $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon ] ); = ( [ $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon} ] ); $next_stop = { type => 'present', station => $route[ $i - 1 ], }; } $stop_distance_sum += $distance->distance_metal( $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon, $route[$i]->loc->lat, $route[$i]->loc->lon $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon}, $route[$i]{lat}, $route[$i]{lon} ) / 1000; } Loading @@ -225,7 +225,7 @@ sub estimate_train_positions2 { } if ( @route and not $next_stop ) { @train_positions = ( [ $route[-1]->loc->lat, $route[-1]->loc->lon ] ); @train_positions = ( [ $route[-1]{lat}, $route[-1]{lon} ] ); $next_stop = { type => 'present', station => $route[-1] Loading Loading @@ -467,7 +467,19 @@ sub route { my $train_pos = $self->estimate_train_positions2( now => $now, route => \@route, route => [ map { { name => $_->loc->name, arr => $_->arr, dep => $_->dep, arr_delay => $_->arr_delay, dep_delay => $_->dep_delay, lat => $_->loc->lat, lon => $_->loc->lon } } @route ], polyline => \@polyline, ); Loading Loading @@ -632,7 +644,19 @@ sub ajax_route { my $train_pos = $self->estimate_train_positions2( now => $now, route => \@route, route => [ map { { name => $_->loc->name, arr => $_->arr, dep => $_->dep, arr_delay => $_->arr_delay, dep_delay => $_->dep_delay, lat => $_->loc->lat, lon => $_->loc->lon } } @route ], polyline => \@polyline, ); Loading templates/_map_infobox.html.ep +4 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ data-poly="<%= stash('ajax_polyline') %>" % if (my $next = stash('next_stop')) { <div class="nextstop"> % if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) { Aufenthalt in <strong><%= $next->{station}->loc->name %></strong> Aufenthalt in <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { an Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading @@ -24,7 +24,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % } % elsif ($next->{type} eq 'present' and $next->{station}{dep}) { Abfahrt in <strong><%= $next->{station}->loc->name %></strong> Abfahrt in <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { von Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading Loading @@ -52,7 +52,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % elsif ($next->{type} eq 'next' and $next->{station}{arr}) { Nächster Halt: <strong><%= $next->{station}->loc->name %></strong> <strong><%= $next->{station}{name} %></strong> um <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong> % if ($next->{station}{arr_delay}) { %= sprintf('(%+d)', $next->{station}{arr_delay}) Loading @@ -63,7 +63,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % elsif ($next->{type} eq 'next') { Nächster Halt: <strong><%= $next->{station}->loc->name %></strong> <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { auf Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading Loading
lib/DBInfoscreen/Controller/Map.pm +50 −26 Original line number Diff line number Diff line Loading @@ -20,12 +20,12 @@ my $strp = DateTime::Format::Strptime->new( ); # Input: # - polyline: Travel::Status::DE::HAFAS::Journey->polyline # - polyline: [{lat, lon, name?}, ...] # - from_name: station name # - to_name: station name # Ouptut: # - from_index: polyline index that corresponds to from_name # - to_index: polyline index that corresponds to to_name # - from_index: polyline index where name eq from_name # - to_index: polyline index where name eq to_name sub get_route_indexes { my ( $polyline, $from_name, $to_name ) = @_; my ( $from_index, $to_index ); Loading @@ -51,9 +51,9 @@ sub get_route_indexes { # Input: # now: DateTime # from: current/previous stop # {dep => DateTime, name => str, lat => float, lon => float} # {arr => DateTime, dep => DateTime, name => str, lat => float, lon => float} # to: next stop # {arr => DateTime, name => str, lat => float, lon => float} # {arr => DateTime, dep => DateTime, name => str, lat => float, lon => float} # route: Travel::Status::DE::HAFAS::Journey->route # polyline: Travel::Status::DE::HAFAS::Journey->polyline (list of lon/lat hashes) # Output: list of estimated train positions in [lat, lon] format. Loading @@ -66,10 +66,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}->loc->name; my $to_name = $opt{to}->loc->name; 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 $route = $opt{route}; my $polyline = $opt{polyline}; Loading Loading @@ -143,16 +143,14 @@ sub estimate_train_positions { ); for my $ratio (@completion_ratios) { my $lat = $opt{from}->loc->lat + ( $opt{to}->loc->lat - $opt{from}->loc->lat ) * $ratio; = $opt{from}{lat} + ( $opt{to}{lat} - $opt{from}{lat} ) * $ratio; my $lon = $opt{from}->loc->lon + ( $opt{to}->loc->lon - $opt{from}->loc->lon ) * $ratio; = $opt{from}{lon} + ( $opt{to}{lon} - $opt{from}{lon} ) * $ratio; push( @train_positions, [ $lat, $lon ] ); } return @train_positions; } return [ $opt{to}->loc->lat, $opt{to}->loc->lon ]; return [ $opt{to}{lat}, $opt{to}{lon} ]; } # Input: Loading @@ -163,6 +161,8 @@ sub estimate_train_positions { # name: str # arr: DateTime # dep: DateTime # arr_delay: int # dep_delay: int # polyline: ref to Travel::Status::DE::HAFAS::Journey polyline list # Output: # next_stop: {type, station} Loading @@ -180,10 +180,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 Loading @@ -208,15 +208,15 @@ sub estimate_train_positions2 { and $now <= ( $route[ $i - 1 ]{dep} // $route[ $i - 1 ]{arr} ) ) { @train_positions = ( [ $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon ] ); = ( [ $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon} ] ); $next_stop = { type => 'present', station => $route[ $i - 1 ], }; } $stop_distance_sum += $distance->distance_metal( $route[ $i - 1 ]->loc->lat, $route[ $i - 1 ]->loc->lon, $route[$i]->loc->lat, $route[$i]->loc->lon $route[ $i - 1 ]{lat}, $route[ $i - 1 ]{lon}, $route[$i]{lat}, $route[$i]{lon} ) / 1000; } Loading @@ -225,7 +225,7 @@ sub estimate_train_positions2 { } if ( @route and not $next_stop ) { @train_positions = ( [ $route[-1]->loc->lat, $route[-1]->loc->lon ] ); @train_positions = ( [ $route[-1]{lat}, $route[-1]{lon} ] ); $next_stop = { type => 'present', station => $route[-1] Loading Loading @@ -467,7 +467,19 @@ sub route { my $train_pos = $self->estimate_train_positions2( now => $now, route => \@route, route => [ map { { name => $_->loc->name, arr => $_->arr, dep => $_->dep, arr_delay => $_->arr_delay, dep_delay => $_->dep_delay, lat => $_->loc->lat, lon => $_->loc->lon } } @route ], polyline => \@polyline, ); Loading Loading @@ -632,7 +644,19 @@ sub ajax_route { my $train_pos = $self->estimate_train_positions2( now => $now, route => \@route, route => [ map { { name => $_->loc->name, arr => $_->arr, dep => $_->dep, arr_delay => $_->arr_delay, dep_delay => $_->dep_delay, lat => $_->loc->lat, lon => $_->loc->lon } } @route ], polyline => \@polyline, ); Loading
templates/_map_infobox.html.ep +4 −4 Original line number Diff line number Diff line Loading @@ -14,7 +14,7 @@ data-poly="<%= stash('ajax_polyline') %>" % if (my $next = stash('next_stop')) { <div class="nextstop"> % if ($next->{type} eq 'present' and $next->{station}{dep} and $next->{station}{arr}) { Aufenthalt in <strong><%= $next->{station}->loc->name %></strong> Aufenthalt in <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { an Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading @@ -24,7 +24,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % } % elsif ($next->{type} eq 'present' and $next->{station}{dep}) { Abfahrt in <strong><%= $next->{station}->loc->name %></strong> Abfahrt in <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { von Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading Loading @@ -52,7 +52,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % elsif ($next->{type} eq 'next' and $next->{station}{arr}) { Nächster Halt: <strong><%= $next->{station}->loc->name %></strong> <strong><%= $next->{station}{name} %></strong> um <strong><%= $next->{station}{arr}->strftime('%H:%M') %></strong> % if ($next->{station}{arr_delay}) { %= sprintf('(%+d)', $next->{station}{arr_delay}) Loading @@ -63,7 +63,7 @@ data-poly="<%= stash('ajax_polyline') %>" % } % elsif ($next->{type} eq 'next') { Nächster Halt: <strong><%= $next->{station}->loc->name %></strong> <strong><%= $next->{station}{name} %></strong> % if ($next->{station}{platform}) { auf Gleis <strong><%= $next->{station}{platform} %></strong> % } Loading