Browse Source

fix a potential crash

Sven Czarnian 3 years ago
parent
commit
7636c549db
1 changed files with 10 additions and 6 deletions
  1. 10 6
      aman/sys/aco/Node.py

+ 10 - 6
aman/sys/aco/Node.py

@@ -25,6 +25,14 @@ class Node:
                         return star
         return None
 
+    def updateArrivalWaypoint(self, arrivalRoute, flightTime, altitude, indicatedAirspeed, groundSpeed):
+        arrivalRoute[-1].FlightTime = timedelta(seconds = flightTime)
+        arrivalRoute[-1].ETA = self.PredictionTime + arrivalRoute[-1].FlightTime
+        arrivalRoute[-1].PTA = arrivalRoute[-1].ETA
+        arrivalRoute[-1].Altitude = altitude
+        arrivalRoute[-1].IndicatedAirspeed = indicatedAirspeed
+        arrivalRoute[-1].GroundSpeed = groundSpeed
+
     def arrivalEstimation(self, runway : Runway, star : ArrivalRoute, weather : WeatherModel):
         # calculate remaining trackmiles
         trackmiles = self.PredictedDistanceToIAF
@@ -113,6 +121,7 @@ class Node:
 
             flightTimeSeconds += 10
             if flownDistance >= trackmiles:
+                self.updateArrivalWaypoint(arrivalRoute, flightTimeSeconds, currentPosition[0], currentIAS, currentPosition[1])
                 break
 
             # check if we follow a new waypoint pair
@@ -120,12 +129,7 @@ class Node:
                 lastWaypointIndex = nextWaypointIndex
                 nextWaypointIndex += 1
 
-                arrivalRoute[-1].FlightTime = timedelta(seconds = flightTimeSeconds)
-                arrivalRoute[-1].ETA = self.PredictionTime + arrivalRoute[-1].FlightTime
-                arrivalRoute[-1].PTA = arrivalRoute[-1].ETA
-                arrivalRoute[-1].Altitude = currentPosition[0]
-                arrivalRoute[-1].IndicatedAirspeed = currentIAS
-                arrivalRoute[-1].GroundSpeed = currentPosition[1]
+                self.updateArrivalWaypoint(arrivalRoute, flightTimeSeconds, currentPosition[0], currentIAS, currentPosition[1])
 
                 # check if a skip from base to final turn waypoints is needed
                 if -1 != turnIndices[0] and nextWaypointIndex > turnIndices[0] and nextWaypointIndex < turnIndices[1]: