-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeroroute.py
171 lines (127 loc) · 6.35 KB
/
aeroroute.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
"""
A program I use to get the length of routes typed in human-readable
format. Requires AIRAC files in vasFMC format in a /AIRAC/ folder.
"""
import nav_data_library
import functions
import objects
import logging
def main() -> None:
"""
The main method of the program
:return: nothing
"""
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s (%(levelname)s): %(message)s (Line: %(lineno)d [%(filename)s])",
datefmt='%Y-%m-%d %I:%M:%S %p',
filename='aeroroute.log',
encoding='utf-8',
filemode='w'
)
print('\n***Aeroroute loading***')
logging.info("Program starting")
# create nav_data_library object
nav_data = nav_data_library.NavDataLibrary()
while True:
# allows user to input waypoint(s)/exit instructions to list
print('\nType "quit" to exit program, enter 20.000000/-123.000000 or 5029N/05120W format for manual waypoints')
input_string = input("Enter input string: ")
print("")
input_string = input_string.upper()
logging.info("Input string was: " + input_string) # log inputted string
input_list = input_string.split()
if len(input_list) == 0:
print("No input detected")
continue
if "QUIT" in input_list:
print('***Program exiting***')
break
print(aeroroute_input(input_list, nav_data))
def aeroroute_input(input_list, nav_data=nav_data_library.NavDataLibrary()):
"""
"""
if len(input_list) == 1: # single item, what happens if item doesn't exist?
print('Single item detected, looking up item.')
logging.info("Looking up single item: " + input_list[0])
found_item = nav_data.nav_data_searcher(input_list[0])
if found_item is None:
logging.info("Single item " + input_list[0] + " not found.")
return (input_list[0] + " not found.")
else:
logging.info("Single item " + input_list[0] + " is " + str(found_item))
return(found_item)
if multiple_adjacent_string_detector(input_list): # if true, there were multiple identical adjacent items
return
# no multiple adjacent inputs, pass on to list_parser
input_route_obj = functions.list_parser(input_list, nav_data)
if input_route_obj is None: # something bad came back from string_parser
logging.warning("string_parser returned None, back to beginning of loop")
return
if input_route_obj.contains_airway: # is there an airway in the route?
# is airway at beginning of route? - not OK
if isinstance(input_route_obj.first_element, (objects.Airway, objects.AmbiguousAirway)):
logging.warning("Route started with an airway, back to beginning of loop")
return("Route cannot start with an airway")
# is airway at end of route? - not OK
if isinstance(input_route_obj.last_element, (objects.Airway, objects.AmbiguousAirway)):
logging.warning("Route ended with an airway, back to beginning of loop")
return("Route cannot end with an airway")
# no airways should touch another airway
if adjacent_airway_detector(input_route_obj):
# airways touch other airways - not OK
return
if input_route_obj.contains_ambiguous_point: # try solving with adjacent airways
logging.info("Ambiguous point(s) detected. Trying to solve using adjacent airways.")
input_route_obj = functions.deambiguate_points_using_airways(input_route_obj)
if input_route_obj.contains_ambiguous_airway: # try solving ambiguousairways with adjacent waypoints
logging.info("Ambiguous airway(s) detected. Trying to solve using adjacent waypoints.")
input_route_obj = functions.deambiguate_airways_using_points(input_route_obj)
if input_route_obj.contains_ambiguous_airway: # deambiguating was not sucessful. unable to compute
return("Unable to deambiguate airway(s). Cannot continue.")
if input_route_obj.contains_airway: # we need to unpack the airway into only the waypoints we want
input_route_obj = functions.slice_airways(input_route_obj)
if input_route_obj.contains_ambiguous_point: # adjacent airways didn't find everything, brute is needed
logging.info("Ambiguous point(s) still detected. Using brute deambiguator.")
multiples_map = functions.multiple_point_finder(input_route_obj)
input_route_obj = functions.deambiguator_brute(input_route_obj, multiples_map)
if input_route_obj.contains_ambiguous_point: # brute deambiguator was not successful. unable to compute
return("Unable to deambiguate point(s). Cannot continue.")
for item in input_route_obj.elements:
print(item)
sum_distance = functions.distance_summer(input_route_obj)
return('Distance in nm:', sum_distance)
def multiple_adjacent_string_detector(input_list: list[str]) -> bool:
"""
detects if there are multiple adjacent identical strings
:param input_list: list of strings
:return: True if detected, False if not detected
"""
for i in range(len(input_list) - 1):
if input_list[i] == input_list[i + 1]:
logging.warning("Multiple adjacent input found with name: " + input_list[i])
print('Multiple adjacent input found with name', input_list[i], '- unable to compute.')
return True
return False
def adjacent_airway_detector(input_route_obj) -> bool:
"""
detects if two Airways or AmbiguousAirways are touching
:param input_route_obj: input Route object containing route elements
:return: True if detected, False if not detected
"""
for i in range(input_route_obj.num_elements - 1):
if isinstance(input_route_obj.get_element(i), (objects.Airway, objects.AmbiguousAirway)) and \
isinstance(input_route_obj.get_element(i+1), (objects.Airway, objects.AmbiguousAirway)):
logging.warning("Adjacent airways were found: " + str(input_route_obj.get_element(i)) + " " +
str(input_route_obj.get_element(i+1)))
print(("Adjacent airways found. Unable to compute."))
return True
return False
def flask_test() -> str:
"""
A test function for use with Flask
:return: a string
"""
return "Hello, Flask!"
if __name__ == "__main__":
main()