Skip to content

Commit

Permalink
Merge pull request #1 from derekm1986/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
derekm1986 authored Mar 21, 2024
2 parents 792ae46 + 69e69c6 commit 7b41687
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ AIRAC/
*.pyc
.idea/
__pycache__/
routes/
aeroroute.log
136 changes: 76 additions & 60 deletions aeroroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,78 +49,80 @@ def main() -> None:
if "QUIT" in input_list:
print('***Program exiting***')
break

print(aeroroute_input(input_list, nav_data))

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.")
print(input_list[0] + " not found.")
else:
logging.info("Single item " + input_list[0] + " is " + str(found_item))
print(found_item)
continue

if multiple_adjacent_string_detector(input_list): # if true, there were multiple identical adjacent items
continue
def aeroroute_input(input_list, nav_data=nav_data_library.NavDataLibrary()):
"""
# no multiple adjacent inputs, pass on to list_parser
input_route_obj = functions.list_parser(input_list, nav_data)
"""
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 input_route_obj is None: # something bad came back from string_parser
logging.warning("string_parser returned None, back to beginning of loop")
continue
if multiple_adjacent_string_detector(input_list): # if true, there were multiple identical adjacent items
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")
print("Route cannot start with an airway")
continue

# 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")
print("Route cannot end with an airway")
continue

# no airways should touch another airway
if adjacent_airway_detector(input_route_obj):
# airways touch other airways - not OK
continue

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
print("Unable to deambiguate airway(s). Cannot continue.")
continue
# no multiple adjacent inputs, pass on to list_parser
input_route_obj = functions.list_parser(input_list, nav_data)

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 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_ambiguous_point: # adjacent airways didn't find everything, brute is needed
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")

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)
# 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")

if input_route_obj.contains_ambiguous_point: # brute deambiguator was not successful. unable to compute
print("Unable to deambiguate point(s). Cannot continue.")
continue
# 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

for item in input_route_obj.elements:
print(item)
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)

sum_distance = functions.distance_summer(input_route_obj)
if input_route_obj.contains_ambiguous_point: # brute deambiguator was not successful. unable to compute
return("Unable to deambiguate point(s). Cannot continue.")

print('Distance in nm:', sum_distance)
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:
Expand Down Expand Up @@ -151,5 +153,19 @@ def adjacent_airway_detector(input_route_obj) -> bool:
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()
50 changes: 50 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from flask import Flask, render_template, request
from aeroroute import aeroroute_input

app = Flask(__name__)

# @app.route('/')
# def index():
# # Call the main function from aeroroute.py

# query = ("KJFK", "EGLL")

# result = aeroroute_input((query))

# # Return the result as a response
# #return str(result)

# # Render the index.html template and pass the result to it
# return render_template('index.html', query=query, result=result)


# #return f"Result from aeroroute.py: {result}"

# @app.route('/', methods=['GET', 'POST'])
# def index():
# if request.method == 'POST':
# route = request.form.get('route').upper()
# query = (route.split())
# result = aeroroute_input(query)
# return render_template('result.html', route=route, result=result)
# return render_template('form.html')

# if __name__ == '__main__':
# app.run(debug=True)

from flask import Flask, render_template, request
from aeroroute import aeroroute_input

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def index():
route = result = None
if request.method == 'POST':
route = request.form.get('route').upper()
query = route.split()
result = aeroroute_input(query)
return render_template('form.html', route=route, result=result)

if __name__ == '__main__':
app.run(debug=True)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==1.1.2
33 changes: 33 additions & 0 deletions templates/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
flex-direction: column;
}
</style>
</head>

<body>

<h2>Aeroroute Distance Tool</h2>

<form action="/" method="post" style="display: flex; flex-direction: column; align-items: center;">
Route:<br><br>
<textarea name="route" style="width: 400px; height: 50px;">{{ route }}</textarea>
<br><br>
<input type="submit" value="Submit">
</form>

{% if result %}
<h2>Result</h2>
<p>{{ result }}</p>
{% endif %}

</body>
</html>
13 changes: 13 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>Aeroroute</title>
</head>
<body>
<h1>Welcome to Aeroroute!</h1>
<p>Query was</p>
<p>{{ query }}</p>
<p>Result was</p>
<p>{{ result }}</p>
</body>
</html>
11 changes: 11 additions & 0 deletions templates/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<body>

<h2>Result</h2>

<p>Route: {{ route }}</p>
<p>Result: {{ result }}</p>

</body>
</html>

0 comments on commit 7b41687

Please sign in to comment.