AirportSequencing.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/usr/bin/env python
  2. from datetime import datetime as dt
  3. import pytz
  4. import time
  5. from aman.config.RunwaySequencing import RunwaySequencing
  6. class AirportSequencing:
  7. def __init__(self, icao : str):
  8. self.Airport = icao
  9. self.ActiveArrivalRunways = []
  10. self.RunwayDependencies = []
  11. self.LastUpdateTimestamp = dt.utcfromtimestamp(int(time.time())).replace(tzinfo = pytz.UTC)
  12. self.UseShallShouldMay = True
  13. def clearData(self):
  14. self.ActiveArrivalRunways.clear()
  15. self.RunwayDependencies.clear()
  16. def activateRunway(self, runway : RunwaySequencing):
  17. for active in self.ActiveArrivalRunways:
  18. if active.Runway.Name == runway.Runway.Name:
  19. self.ActiveArrivalRunways[runway.Runway.Name] = runway
  20. return
  21. self.ActiveArrivalRunways.append(runway)
  22. def runway(self, index : int):
  23. if index >= len(self.ActiveArrivalRunways):
  24. return None
  25. return self.ActiveArrivalRunways[index].Runway
  26. def runwayIndex(self, identifier : str):
  27. for i in range(0, len(self.ActiveArrivalRunways)):
  28. if self.ActiveArrivalRunways[i].Runway.Name == identifier:
  29. return i
  30. return -1
  31. def deactivateRunway(self, identifier : str):
  32. index = self.runwayIndex(identifier)
  33. if 0 <= index:
  34. self.ActiveArrivalRunways.pop(index)
  35. # remove the dependencies
  36. for i in range(self.RunwayDependencies - 1, -1, -1):
  37. if index == self.RunwayDependencies[i][0] or index == self.RunwayDependencies[i][1]:
  38. self.RunwayDependencies.pop(i)
  39. def addDependency(self, first : str, second : str):
  40. idxFirst = self.runwayIndex(first)
  41. idxSecond = self.runwayIndex(second)
  42. if 0 > idxFirst or 0 > idxSecond:
  43. return False
  44. foundFirst = False
  45. foundSecond = False
  46. for dependency in self.RunwayDependencies:
  47. if idxFirst == dependency[0] and idxSecond == dependency[1]:
  48. foundFirst = True
  49. elif idxFirst == dependency[1] and idxSecond == dependency[0]:
  50. foundSecond = True
  51. if False == foundFirst:
  52. self.RunwayDependencies.append([ idxFirst, idxSecond ])
  53. if False == foundSecond:
  54. self.RunwayDependencies.append([ idxSecond, idxFirst ])
  55. return True
  56. def removeDependency(self, first : str, second : str):
  57. idxFirst = self.runwayIndex(first)
  58. idxSecond = self.runwayIndex(second)
  59. if 0 > idxFirst or 0 > idxSecond:
  60. return
  61. for i in range(self.RunwayDependencies - 1, -1, -1):
  62. dependency = self.RunwayDependencies[i]
  63. # check for all the pairs
  64. if idxFirst == dependency[0] and idxSecond == dependency[1]:
  65. self.RunwayDependencies.pop(i)
  66. elif idxSecond == dependency[0] and idxSecond == dependency[0]:
  67. self.RunwayDependencies.pop(i)
  68. def findRunway(self, identifier : str):
  69. for runway in self.ActiveArrivalRunways:
  70. if runway.Runway.Name == identifier:
  71. return runway
  72. return None
  73. def findDependentRunways(self, identifier : str):
  74. # runway is unknown
  75. index = self.runwayIndex(identifier)
  76. if 0 > index:
  77. return []
  78. # search the dependency pair
  79. dependencies = [self.ActiveArrivalRunways[self.RunwayDependencies[i][1]] for i in range(0, len(self.RunwayDependencies)) if index == self.RunwayDependencies[i][0]]
  80. return dependencies