summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2025-07-11 19:06:19 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2025-07-11 19:06:19 +0200
commitd5349ede4fae363cc4fb1e04eca807c38496a93e (patch)
treef96adf002704cd8fb776013d33c90a6593a4eb17
parentd6cca3f837337c12095cb71f694f68fb66cc4ccb (diff)
InTransit: re-add fallback path to location estimation.
It makes sense when annotating the position with the user rather than the vehicle.
-rw-r--r--lib/Travelynx/Model/InTransit.pm31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/Travelynx/Model/InTransit.pm b/lib/Travelynx/Model/InTransit.pm
index 40c96c8..d4f13e2 100644
--- a/lib/Travelynx/Model/InTransit.pm
+++ b/lib/Travelynx/Model/InTransit.pm
@@ -1667,17 +1667,26 @@ sub estimate_trip_position {
$prev_ts = $ts;
}
- # Actually, the vehicle's position isn't well-known in this case.
- #if (not @now_latlon and $in_transit->{sched_dep_ts} and $in_transit->{sched_arr_ts}) {
- # my $time_complete = $now - ($in_transit->{real_dep_ts} // $in_transit->{sched_dep_ts});
- # my $time_total = ($in_transit->{real_arr_ts} // $in_transit->{sched_arr_ts}) - ($in_transit->{real_dep_ts} // $in_transit->{sched_dep_ts});
- # my $completion = $time_complete / $time_total;
- # $completion = $completion < 0 ? 0 : $completion > 1 ? 1 : $completion;
- # @now_latlon = (
- # $in_transit->{dep_lat} + ($in_transit->{arr_lat} - $in_transit->{dep_lat}) * $completion,
- # $in_transit->{dep_lon} + ($in_transit->{arr_lon} - $in_transit->{dep_lon}) * $completion,
- # );
- #}
+ if ( not @now_latlon
+ and $in_transit->{sched_dep_ts}
+ and $in_transit->{sched_arr_ts} )
+ {
+ my $time_complete = $now
+ - ( $in_transit->{real_dep_ts} // $in_transit->{sched_dep_ts} );
+ my $time_total
+ = ( $in_transit->{real_arr_ts} // $in_transit->{sched_arr_ts} )
+ - ( $in_transit->{real_dep_ts} // $in_transit->{sched_dep_ts} );
+ my $completion = $time_complete / $time_total;
+ $completion = $completion < 0 ? 0 : $completion > 1 ? 1 : $completion;
+ @now_latlon = (
+ $in_transit->{dep_lat}
+ + ( $in_transit->{arr_lat} - $in_transit->{dep_lat} )
+ * $completion,
+ $in_transit->{dep_lon}
+ + ( $in_transit->{arr_lon} - $in_transit->{dep_lon} )
+ * $completion,
+ );
+ }
return \@now_latlon;
}