-
Notifications
You must be signed in to change notification settings - Fork 0
/
nav_data_library.py
138 lines (119 loc) · 7.04 KB
/
nav_data_library.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import airportsreader
import navaidsreader
import waypointsreader
import atsreader
import logging
import objects
class NavDataLibrary(object):
"""
Holds functionality for Nav Data, along with some functionality
"""
def __init__(self):
logging.info("Loading airports into memory")
self.airport_dict = airportsreader.airport_dict_maker()
logging.info("Airports loaded into memory") # loading airports was successful
logging.info("Loading NAVAIDs into memory")
self.navaid_dict = navaidsreader.navaid_dict_maker()
logging.info("NAVAIDs loaded into memory") # loading NAVAIDs was successful
logging.info("Loading waypoints into memory")
self.waypoint_dict = waypointsreader.waypoint_dict_maker()
logging.info("Waypoints loaded into memory") # loading elements was successful
logging.info("Loading airways into memory")
self.airway_dict = atsreader.airway_dict_maker()
logging.info("Airways loaded into memory") # loading airways was successful
logging.info("Combining NAVAID and waypoint dictionaries")
self.points_in_space_dict = self.points_in_space_dict_combiner()
logging.info("NAVAID and waypoint dictionaries combined") # dictionary combination was successful
logging.info("Adding airway references to combined dictionary")
self.airway_matcher()
logging.info("Airway references added to combined dictionary") # reference matching was successful
logging.info("NAV data loading complete")
def points_in_space_dict_combiner(self):
"""
combines waypoint_dict and navaid_dict into one dictionary
:return: points_in_space_dict
"""
points_in_space_dict = self.navaid_dict.copy()
for key, val in self.waypoint_dict.items():
if key in points_in_space_dict:
# the entry is already in points_in_space_dict
if type(points_in_space_dict[key]) is objects.AmbiguousPoint:
# points_in_space_dict already has AmbiguousPoint
if type(val) is objects.AmbiguousPoint:
# must add AmbiguousPoint to AmbiguousPoint
points_in_space_dict[key].add_possibility(self.waypoint_dict[key].possibilities)
else:
# must add PointInSpace to AmbiguousPoint
points_in_space_dict[key].add_possibility(self.waypoint_dict[key])
else:
# points_in_space_dict contains a PointInSpace
if type(val) is objects.AmbiguousPoint:
# Adding AmbiguousPoint to a PointInSpace, make a new AmbiguousPoint
original_point_in_space = points_in_space_dict[key]
points_in_space_dict[key] = val
points_in_space_dict[key].add_possibility(original_point_in_space)
else:
# Adding PointInSpace to a PointInSpace
points_in_space_dict[key] = objects.AmbiguousPoint(key, points_in_space_dict[key])
points_in_space_dict[key].add_possibility(val)
else:
# the entry is not yet in points_in_space_dict, so just add it
points_in_space_dict[key] = val
return points_in_space_dict
def airway_matcher(self) -> None:
"""
adds airway references into the points_in_space_dict
:return: None
"""
for airway_names in self.airway_dict.values():
if isinstance(airway_names, objects.AmbiguousAirway): # we have encountered an AmbiguousAirway
for airway in airway_names.possibilities:
for waypoint in airway.waypoints:
if waypoint.identifier in self.points_in_space_dict:
if isinstance(self.points_in_space_dict[waypoint.identifier], objects.AmbiguousPoint):
# trying to match with an AmbiguousElement in the points_in_space_dict, need a loop
for point in self.points_in_space_dict[waypoint.identifier].possibilities:
if point.coordinates == waypoint.coordinates:
if airway.identifier not in point.available_airways:
point.add_available_airway(airway.identifier)
else:
# trying to match with a single item
if self.points_in_space_dict[waypoint.identifier].coordinates == \
waypoint.coordinates:
# need to check if it's there first!
if airway.identifier not in \
self.points_in_space_dict[waypoint.identifier].available_airways:
self.points_in_space_dict[waypoint.identifier].add_available_airway(
airway.identifier)
else: # we have encountered an Airway by itself
for waypoint in airway_names.waypoints:
if waypoint.identifier in self.points_in_space_dict:
if isinstance(self.points_in_space_dict[waypoint.identifier], objects.AmbiguousPoint):
# trying to match with an AmbiguousElement in the points_in_space_dict, need a loop
for point in self.points_in_space_dict[waypoint.identifier].possibilities:
if point.coordinates == waypoint.coordinates:
if airway_names.identifier not in point.available_airways:
point.add_available_airway(airway_names.identifier)
else:
# trying to match with a single item
if self.points_in_space_dict[waypoint.identifier].coordinates == \
waypoint.coordinates:
# need to check if it's there first!
if airway_names.identifier not in \
self.points_in_space_dict[waypoint.identifier].available_airways:
self.points_in_space_dict[waypoint.identifier].add_available_airway(
airway_names.identifier)
def nav_data_searcher(self, item):
"""
looks for item inside this Nav Data library
:param item: string to search for
:return: found object or none
"""
found_item = None
if item in self.airport_dict:
found_item = self.airport_dict[item]
elif item in self.points_in_space_dict:
found_item = self.points_in_space_dict[item]
elif item in self.airway_dict:
found_item = self.airway_dict[item]
return found_item