From 909cfc9e27c0d30c16dad8c6c3b4175f1c4812e2 Mon Sep 17 00:00:00 2001 From: Sven Czarnian Date: Wed, 13 Oct 2021 16:16:03 +0200 Subject: [PATCH] redefine the constructor to be more flexible with constraints, etc. --- aman/formats/SctEseFormat.py | 6 +++--- aman/types/Inbound.py | 4 ++-- aman/types/Waypoint.py | 42 +++++++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/aman/formats/SctEseFormat.py b/aman/formats/SctEseFormat.py index 4f97425..5df3074 100644 --- a/aman/formats/SctEseFormat.py +++ b/aman/formats/SctEseFormat.py @@ -31,15 +31,15 @@ class SctEseFormat: if len(split) <= longitudeIdx: sys.stderr.write('Invalid waypoint format: ' + waypoint) sys.exit(-1) - return Waypoint(split[nameIdx], Waypoint.dms2dd(split[latitudeIdx]), Waypoint.dms2dd(split[longitudeIdx])) + return Waypoint(name = split[nameIdx], latitude = split[latitudeIdx], longitude = split[longitudeIdx]) def parseRunway(runway : str): split = list(filter(None, runway.split(' '))) if 9 != len(split) or '' == split[8]: return None, None, None - waypoint0 = Waypoint(split[0], Waypoint.dms2dd(split[4]), Waypoint.dms2dd(split[5])) - waypoint1 = Waypoint(split[1], Waypoint.dms2dd(split[6]), Waypoint.dms2dd(split[7])) + waypoint0 = Waypoint(name = split[0], latitude = split[4], longitude = split[5]) + waypoint1 = Waypoint(name = split[1], latitude = split[6], longitude = split[7]) return split[8], Runway(waypoint0, waypoint1), Runway(waypoint1, waypoint0) diff --git a/aman/types/Inbound.py b/aman/types/Inbound.py index e697cf7..ae692e5 100644 --- a/aman/types/Inbound.py +++ b/aman/types/Inbound.py @@ -37,7 +37,7 @@ class Inbound: # find the nearest runway for an initial guess distance = 100000.0 - currentPosition = Waypoint('', self.Report.position.latitude, self.Report.position.longitude) + currentPosition = Waypoint(latitude = self.Report.position.latitude, longitude = self.Report.position.longitude) for runway in sequencingConfig.ActiveArrivalRunways: candidateDistance = runway.Runway.Start.haversine(currentPosition) if distance > candidateDistance: @@ -70,7 +70,7 @@ class Inbound: # calculate descend profile flightTimeSeconds = 0 - currentHeading = Waypoint('', self.Report.position.latitude, self.Report.position.longitude).bearing(self.PlannedStar.Route[0]) + currentHeading = Waypoint(latitude = self.Report.position.latitude, longitude = self.Report.position.longitude).bearing(self.PlannedStar.Route[0]) distanceToWaypoint = self.Report.distanceToIAF nextWaypointIndex = 0 currentPosition = [ self.Report.dynamics.altitude, self.Report.dynamics.groundSpeed ] diff --git a/aman/types/Waypoint.py b/aman/types/Waypoint.py index 9f5d09d..5ec36a9 100644 --- a/aman/types/Waypoint.py +++ b/aman/types/Waypoint.py @@ -2,6 +2,7 @@ import numpy as np import pyproj +import sys class Waypoint: def dms2dd(coordinate : str): @@ -20,9 +21,44 @@ class Waypoint: return dd - def __init__(self, name : str, latitude : float, longitude : float): - self.Name = name - self.Coordinate = np.array([ latitude, longitude ]) + def coordinateArgument(value): + if True == isinstance(value, str): + return Waypoint.dms2dd(value) + elif True == isinstance(value, (float, int)): + return float(value) + else: + raise Exception('Invalid constructor argument') + + def __init__(self, **kwargs): + self.Name = None + self.Coordinate = None + self.Altitude = None + self.Speed = None + self.BaseTurn = False + self.FinalTurn = False + + latitude = None + longitude = None + for key, value in kwargs.items(): + if 'name' == key.lower(): + self.Name = str(value) + elif 'latitude' == key.lower(): + latitude = Waypoint.coordinateArgument(value) + elif 'longitude' == key.lower(): + longitude = Waypoint.coordinateArgument(value) + elif 'altitude' == key.lower(): + self.Altitude = int(value) + elif 'speed' == key.lower(): + self.Speed = int(value) + elif 'base' == key: + self.BaseTurn = bool(value) + elif 'final' == key: + self.FinalTurn = bool(value) + else: + raise Exception('Invalid constructor argument: ' + key) + + if None != latitude and None != longitude: + self.Coordinate = np.array([ latitude, longitude ]) def __str__(self): return 'Name: ' + self.Name + ', Lat: ' + str(self.Coordinate[0]) + ', Lon: ' + str(self.Coordinate[1])