Skip to content

Commit

Permalink
added info to tracks map
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Golfari committed Aug 24, 2023
1 parent 1ea61a9 commit a12730e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
1 change: 1 addition & 0 deletions airscore/core/flightcheck/flightcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def check_fixes(
if fix_dist_flown > result.distance_flown:
'''time of trackpoint with shortest distance to ESS'''
result.best_distance_time = next_fix.rawtime
result.best_distance_fix = next_fix
'''updating best distance flown'''
result.distance_flown = fix_dist_flown

Expand Down
18 changes: 14 additions & 4 deletions airscore/core/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,19 @@ def make_map(
waypoints = layer_geojson['geojson']['waypoint_achieved']
waypoint_group = FeatureGroup(name='Waypoints Taken', show=show_waypoint)
for w in waypoints:
waypoint_group.add_child(Marker([w[1], w[0]], popup=Popup(w[6], max_width=300)))

waypoint_group.add_child(Marker([w[1], w[0]], popup=Popup(w[6], max_width='300')))
if layer_geojson['geojson']['takeoff_landing']:
for w in layer_geojson['geojson']['takeoff_landing']:
# label = w['properties'].get('label')
event = w['properties']['event']
color = "green" if event == "TakeOff" else "darkred" if event == "Landing" else "orange"
icon = folium.Icon(color=color, icon="times", prefix='fa')
coords = w['geometry']['coordinates']
label = f"{event} at {w['properties'].get('time')}"
coords.reverse() # changing to [lat, lon]
waypoint_group.add_child(Marker(coords, icon=icon, popup=Popup(label, max_width='300')))
folium_map.add_child(waypoint_group)

"""Design cylinders"""
if circles:
for c in circles:
Expand All @@ -131,7 +141,7 @@ def make_map(
text = f"<b>{c['name']}</b><br>{str(c['description'])}<br>Altitude: {str(c['altitude'])} m."
else:
text = f"<b>{c['name']}</b>"
popup = folium.Popup(text, max_width=300)
popup = folium.Popup(text, max_width='300')

folium.Circle(
location=(c['latitude'], c['longitude']),
Expand Down Expand Up @@ -242,7 +252,7 @@ def make_map(
if infringements:
for i in infringements:
popup = folium.Popup(
f"<b>{i[3]}</b><br>{i[5]}. separation: {i[4]} m. <br>" f"{i[7]} - alt. {i[2]} m.", max_width=300
f"<b>{i[3]}</b><br>{i[5]}. separation: {i[4]} m. <br>" f"{i[7]} - alt. {i[2]} m.", max_width='300'
)
icon = folium.Icon(color="red", icon="times", prefix='fa')
airspace_group.add_child(Marker([i[1], i[0]], icon=icon, popup=popup))
Expand Down
54 changes: 33 additions & 21 deletions airscore/core/mapUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def result_to_geojson(result, task, flight, second_interval=5):
takeoff_landing = []
thermals = []
infringements = []
fixes_to_keep = []
point = namedtuple('fix', 'lat lon')

min_lat = flight.fixes[0].lat
Expand All @@ -238,9 +239,19 @@ def result_to_geojson(result, task, flight, second_interval=5):
bbox = [[min_lat, min_lon], [max_lat, max_lon]]

takeoff = Point((flight.takeoff_fix.lon, flight.takeoff_fix.lat))
takeoff_landing.append(Feature(geometry=takeoff, properties={"TakeOff": "TakeOff"}))
time = "%02d:%02d:%02d" % rawtime_float_to_hms(flight.takeoff_fix.rawtime + task.time_offset)
takeoff_landing.append(Feature(geometry=takeoff, properties={"event": "TakeOff", "time": time}))
landing = Point((flight.landing_fix.lon, flight.landing_fix.lat))
takeoff_landing.append(Feature(geometry=landing, properties={"Landing": "Landing"}))
time = "%02d:%02d:%02d" % rawtime_float_to_hms(flight.landing_fix.rawtime + task.time_offset)
takeoff_landing.append(Feature(geometry=landing, properties={"event": "Landing", "time": time}))

fixes_to_keep.extend([flight.takeoff_fix.rawtime, flight.landing_fix.rawtime])
# adding best distance fix if not in goal
if not result.goal_time and result.best_distance_fix:
best_distance = Point((result.best_distance_fix.lon, result.best_distance_fix.lat))
time = "%02d:%02d:%02d" % rawtime_float_to_hms(result.best_distance_fix.rawtime + task.time_offset)
takeoff_landing.append(Feature(geometry=best_distance, properties={"event": "BestDistance", "time": time}))
fixes_to_keep.append(result.best_distance_fix.rawtime)

for thermal in flight.thermals:
thermals.append(
Expand Down Expand Up @@ -273,6 +284,7 @@ def result_to_geojson(result, task, flight, second_interval=5):
time,
f'<b>{tp.name}</b> <br>' f'alt: <b>{tp.altitude:.0f} m.</b><br>' f'time: <b>{time}</b>',
]
fixes_to_keep.append(tp.rawtime)
if idx > 0:
current = point(lon=tp.lon, lat=tp.lat)
previous = point(lon=waypoints_achieved[-1][0], lat=waypoints_achieved[-1][1])
Expand All @@ -290,14 +302,31 @@ def result_to_geojson(result, task, flight, second_interval=5):
achieved.extend([0, "0:00:00", '-'])
waypoints_achieved.append(achieved)

'''airspace infringements'''
if result.infringements:
for entry in result.infringements:
time = "%02d:%02d:%02d" % rawtime_float_to_hms(entry['rawtime'] + task.time_offset)
infringements.append(
[
entry['lon'],
entry['lat'],
int(entry['alt']),
entry['space'],
int(entry['distance']),
entry['separation'],
int(entry['rawtime']),
time,
]
)
fixes_to_keep.append(int(entry['rawtime']))

lastfix = flight.fixes[0]
for fix in flight.fixes:
bbox = checkbbox(fix.lat, fix.lon, bbox)
keep = False
if (
fix.rawtime >= lastfix.rawtime + second_interval
or any(tp for tp in result.waypoints_achieved if tp.rawtime == fix.rawtime)
or any(tp for tp in result.infringements if int(tp['rawtime']) == fix.rawtime)
or fix.rawtime in fixes_to_keep
):
'''keep fixes that validate a turnpoint or cause an infringement'''
###
Expand Down Expand Up @@ -328,23 +357,6 @@ def result_to_geojson(result, task, flight, second_interval=5):

tracklog = FeatureCollection(features)

'''airspace infringements'''
if result.infringements:
for entry in result.infringements:
time = "%02d:%02d:%02d" % rawtime_float_to_hms(entry['rawtime'] + task.time_offset)
infringements.append(
[
entry['lon'],
entry['lat'],
int(entry['alt']),
entry['space'],
int(entry['distance']),
entry['separation'],
int(entry['rawtime']),
time,
]
)

return tracklog, thermals, takeoff_landing, bbox, waypoints_achieved, infringements


Expand Down

0 comments on commit a12730e

Please sign in to comment.