Skip to content

Commit

Permalink
CIVL and PWCA speed section distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Golfari committed Jun 23, 2023
1 parent 7502db4 commit 1a8fe02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
25 changes: 20 additions & 5 deletions airscore/core/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,12 +821,27 @@ def get_shortest_path(task, ss_distance=False) -> list:
points = task.projected_turnpoints
line = task.projected_line

SSS_index = None
ESS_index = None
before_SSS = None

# Optimised Speed Section Distance Calculation:
# (2023)
# CIVL: on shorter route between launch and ESS
# PWCA: on shorter route between SSS and ESS
if ss_distance and any(p for p in points if p.type == 'endspeed'):

if task.formula.type.lower() == 'pwc':
SSS_index = points.index(next(p for p in points if p.type == 'speed'))
fake_launch = cPoint(points[SSS_index].x, points[SSS_index].y, 0, 'launch')
before_SSS, points = points[:SSS_index], [fake_launch] + points[SSS_index:]

ESS_index = points.index(next(p for p in points if p.type == 'endspeed'))
else:
ESS_index = None

planar_dist, points = calculate_optimised_path(points, ESS_index, line)
_, points = calculate_optimised_path(points, ESS_index, line)

if before_SSS:
points = before_SSS + points[1:]

'''create optimised points positions on earth model (lat, lon)'''
optimised = revert_opt_points(points, task.geo)
Expand Down Expand Up @@ -922,7 +937,7 @@ def calculate_optimised_path(points: list, ESS_index: int or None, line: list) -
return last_dist, points


def optimize_path(points, count, ESS_index, line):
def optimize_path(points: list, count: int, ESS_index: int or None, line: list) -> float:
"""Inputs:
points - array of point objects
count - number of points (not needed)
Expand All @@ -946,7 +961,7 @@ def optimize_path(points, count, ESS_index, line):
return dist


def get_target_points(points, count, index, ESS_index):
def get_target_points(points: list, count: int, index: int, ESS_index: int or None) -> tuple:
"""Inputs:
points - array of point objects
count - number of points
Expand Down
10 changes: 6 additions & 4 deletions airscore/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -1461,17 +1461,19 @@ def calculate_optimised_task_length(self, method="fast_andoyer"):

self.optimised_turnpoints = optimised

self.opt_dist_to_SS = sum(self.optimised_legs[0:sss_wpt])
self.opt_dist_to_ESS = sum(self.optimised_legs[0:ess_wpt])
# work out self.opt_dist_to_SS, self.opt_dist_to_ESS, self.SS_distance
# 2022: SS_distance has to be calculated as min(launch to ESS)
if any(tp.type == 'endspeed' for tp in self.turnpoints):
optimised = get_shortest_path(self, ss_distance=True)
optimised_legs = [0] + [distance(e, optimised[i+1], method) for i, e in enumerate(optimised[:-1])]
self.opt_dist_to_SS = sum(optimised_legs[0:sss_wpt])
self.opt_dist_to_ESS = sum(optimised_legs[0:ess_wpt])
# self.opt_dist_to_SS = sum(optimised_legs[0:sss_wpt])
# self.opt_dist_to_ESS = sum(optimised_legs[0:ess_wpt]) # this is used for Stopped Task Validity
self.SS_distance = sum(optimised_legs[sss_wpt:ess_wpt])
else:
self.opt_dist_to_SS = sum(self.optimised_legs[0:sss_wpt])
self.opt_dist_to_ESS = sum(self.optimised_legs[0:ess_wpt])
# self.opt_dist_to_SS = sum(self.optimised_legs[0:sss_wpt])
# self.opt_dist_to_ESS = sum(self.optimised_legs[0:ess_wpt])
self.SS_distance = sum(self.optimised_legs[sss_wpt:ess_wpt])

def clear_waypoints(self):
Expand Down

0 comments on commit 1a8fe02

Please sign in to comment.