diff --git a/aman/config/Airport.py b/aman/config/Airport.py index 8b96cee..2e9483c 100644 --- a/aman/config/Airport.py +++ b/aman/config/Airport.py @@ -1,13 +1,14 @@ #!/usr/bin/env python import configparser +from datetime import timedelta import glob import os import sys from aman.config.RHC import RHC from aman.config.AirportSequencing import AirportSequencing -from aman.config.RunwaySequencing import RunwaySequencing +from aman.config.RunwaySequencing import RunwaySequencing, RunwayAssignmentType from aman.formats.SctEseFormat import SctEseFormat from aman.types.Waypoint import Waypoint @@ -173,6 +174,91 @@ class Airport: # register the arrival route self.ArrivalRouteConstraints[star] = waypoints + def parseAssignment(assignment : str): + elements = list(filter(None, assignment.split(':'))) + retval = {} + type = None + + index = 0 + while index < len(elements): + if 0 == index % 2: + if 'A' == elements[index]: + type = RunwayAssignmentType.AircraftType + elif 'G' == elements[index]: + type = RunwayAssignmentType.GateAssignment + else: + sys.stderr.write('Invalid assignment type: ' + elements[index]) + sys.exit(-1) + else: + if None == type: + sys.stderr.write('No assignment type defined') + sys.exit(-1) + + if type not in retval: + retval.setdefault(type, []) + + retval[type].append(elements[index]) + type = None + index += 1 + + return retval + + def findRunway(self, icao : str, name : str): + for runway in self.GngData.Runways[icao]: + if name == runway.Name: + return runway + + sys.stderr.write('Unable to find runway ' + name + ' in the sequencing data for ' + icao) + raise Exception() + #sys.exit(-1) + + def updateRunwayAssignment(dictionary, runway, assignments): + if runway not in dictionary: + dictionary.setdefault(runway, {}) + + for key in assignments: + if key not in dictionary[runway]: + dictionary[runway].setdefault(key, assignments[key]) + else: + dictionary[runway][key].extend(assignments[key]) + + def parseRunwayAssignment(self, icao : str, planning): + self.RunwayAssignmentsShall = {} + self.RunwayAssignmentsShould = {} + self.RunwayAssignmentsMay = {} + self.MaxDelayShould = 10 + self.MaxDelayMay = 5 + shouldFound = False + mayFound = False + + for key in planning: + if True == key.startswith('shallassign'): + runway = self.findRunway(icao, key.replace('shallassign', '').upper()) + assignments = Airport.parseAssignment(planning[key]) + Airport.updateRunwayAssignment(self.RunwayAssignmentsShall, runway, assignments) + elif True == key.startswith('shouldassign'): + runway = self.findRunway(icao, key.replace('shouldassign', '').upper()) + assignments = Airport.parseAssignment(planning[key]) + Airport.updateRunwayAssignment(self.RunwayAssignmentsShould, runway, assignments) + shouldFound = True + elif True == key.startswith('mayassign'): + runway = self.findRunway(icao, key.replace('mayassign', '').upper()) + assignments = Airport.parseAssignment(planning[key]) + Airport.updateRunwayAssignment(self.RunwayAssignmentsMay, runway, assignments) + mayFound = True + + # find the max delays + if True == shouldFound: + if 'maxdelayshould' not in planning: + sys.stderr.write('maxDelayShould needs to be defined') + sys.exit(-1) + self.MaxDelayShould = timedelta(minutes=int(planning['maxdelayshould'])) + if True == mayFound: + if 'maxdelaymay' not in planning: + sys.stderr.write('maxDelaymay needs to be defined') + sys.exit(-1) + self.MaxDelayMay = timedelta(minutes=int(planning['maxdelaymay'])) + def __init__(self, filepath : str, icao : str): config = configparser.ConfigParser() config.read(filepath) @@ -224,3 +310,15 @@ class Airport: # get the default sequencing data self.parseDefaultSequencingConfiguration(icao, planningConfig) self.parseConstraints(planningConfig) + self.parseRunwayAssignment(icao, planningConfig) + self.assignmentUpdate(self.DefaultSequencing) + + def assignmentUpdate(self, sequenceConfig : AirportSequencing): + # initializes the default sequence data + for active in sequenceConfig.ActiveArrivalRunways: + if active.Runway in self.RunwayAssignmentsShall: + active.ShallAssignments = self.RunwayAssignmentsShall[active.Runway] + if active.Runway in self.RunwayAssignmentsShould: + active.ShouldAssignments = self.RunwayAssignmentsShould[active.Runway] + if active.Runway in self.RunwayAssignmentsMay: + active.MayAssignments = self.RunwayAssignmentsMay[active.Runway]