Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions PySoar/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
settings = Settings()


def run(url, source, download_progress=None, analysis_progress=None, on_success=None, on_failure=None):
def run(url, source, to_elevation, download_progress=None, analysis_progress=None, on_success=None, on_failure=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it helps to explicitly show the optional behavior of to_elevation:

Suggested change
def run(url, source, to_elevation, download_progress=None, analysis_progress=None, on_success=None, on_failure=None):
def run(url, source, to_elevation=None, download_progress=None, analysis_progress=None, on_success=None, on_failure=None):

target_directory = os.path.join(settings.current_dir, 'bin')
if source == 'cuc':
daily_result_page = SoaringSpotDaily(url)
Expand Down Expand Up @@ -42,8 +42,13 @@ def run(url, source, download_progress=None, analysis_progress=None, on_success=
if fix['pressure_alt'] != 0:
gps_altitude = False

# if field elevation of takeoff is provided then calculate the altitude correction to be used in alitudes
elevation_correction = 0
if to_elevation != None:
elevation_correction = (competitor.trace[0]['gps_alt'] if gps_altitude else competitor.trace[0]['pressure_alt']) - to_elevation

competitor.performance = Performance(competition_day.task, competitor.trip, competitor.phases,
gps_altitude)
gps_altitude, elevation_correction)
except Exception:
failed_comp_ids.append(competitor.competition_id)

Expand Down
33 changes: 26 additions & 7 deletions PySoar/main_pysoar.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,23 @@ def __init__(self, current_version, latest_version):
self.url_input = wx.TextCtrl(panel)
my_sizer.Add(self.url_input, 0, wx.ALL | wx.EXPAND, 5)

to_elevation_sizer = wx.BoxSizer(wx.HORIZONTAL)

text = wx.StaticText(panel, label="Field elevation:")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe nice to add a unit:

is this above MSL?

Suggested change
text = wx.StaticText(panel, label="Field elevation:")
text = wx.StaticText(panel, label="Field elevation [m]:")

to_elevation_sizer.Add(text, 0, wx.ALL, 5)
self.to_elevation_input = wx.TextCtrl(panel)
to_elevation_sizer.Add(self.to_elevation_input, 0, wx.ALL | wx.EXPAND, 5)

status_sizer = wx.BoxSizer(wx.VERTICAL)
self.status = wx.StaticText(panel, label="")
my_sizer.Add(self.status)
status_sizer.Add(self.status)

self.download_status = wx.StaticText(panel, label="")
my_sizer.Add(self.download_status)
status_sizer.Add(self.download_status)

self.analyse_status = wx.StaticText(panel, label="")
my_sizer.Add(self.analyse_status)

status_sizer.Add(self.analyse_status)
buttons_sizer = wx.BoxSizer(wx.HORIZONTAL)

self.start_analysis = wx.Button(panel, label='Start analysis')
Expand All @@ -96,6 +104,8 @@ def __init__(self, current_version, latest_version):
buttons_sizer.Add(bug_report)

complete_sizer.Add(my_sizer, 0, wx.ALL | wx.EXPAND, 5)
complete_sizer.Add(to_elevation_sizer, 0, wx.ALL | wx.LEFT, 5)
complete_sizer.Add(status_sizer, 0, wx.ALL | wx.LEFT, 5)
complete_sizer.Add(buttons_sizer, 0, wx.ALL | wx.CENTER, 5)

panel.SetSizer(complete_sizer)
Expand Down Expand Up @@ -159,7 +169,12 @@ def on_press(self, event):

url = self.url_input.GetValue()
if url_format_correct(url, self.update_status):
args = (url, get_url_source(url), self.set_download_status, self.set_analyse_status,
try:
to_elevation = int(self.to_elevation_input.GetValue())
except:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using a bare except clause, this also catches a KeyboardInterrupt or other signal.
https://docs.python.org/3/library/exceptions.html#exception-hierarchy

i prefer to only catch the instances of Exception

Suggested change
except:
except Exception:

to_elevation = None

args = (url, get_url_source(url), to_elevation, self.set_download_status, self.set_analyse_status,
self.after_successful_run, self.after_unsuccessful_run)
x = Thread(target=run, args=args)
x.start()
Expand Down Expand Up @@ -188,7 +203,9 @@ def run_commandline_program(sys_argv, current_version, latest_version):
def print_help():
print('There are two options for running PySoar from the commandline:\n'
'1. `python main_python` for GUI\n'
'2. `python main_pysoar [url]` - where [url] is the daily competition url')
'2. `python main_pysoar [url] <takeoff elevation>` - where:\n' \
' - [url] is the daily competition url,\n'\
' - <takeoff elevation> (optional) is the elevation of the takeoff field to be used in altitude corrections')

def status_handle(message):
print(message)
Expand Down Expand Up @@ -216,15 +233,17 @@ def analysis_handle(new, total=None):
if latest_version and latest_version.lstrip('v') != current_version:
print('Latest version is %s! Current: %s' % (latest_version, current_version))

if len(sys_argv) == 2:
if len(sys_argv) >= 2:
if sys_argv[1] == '--help':
print_help()
else:
url = sys_argv[1]
to_elevation = None if len(sys_argv) == 2 else int(sys_argv[2])
if url_format_correct(url, status_handle):
source = get_url_source(url)
run(url,
source,
to_elevation,
download_progress=download_handle,
analysis_progress=analysis_handle,
on_success=on_success,
Expand Down
55 changes: 33 additions & 22 deletions PySoar/performanceClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,68 @@ class Performance(object):
'v_turn_avg', 'LD_avg', 'turn_percentage', 'h_loss_turn', 's_glide_avg', 'dh_cruise_avg',
's_extra', 'tsk_v']

def __init__(self, task, trip, phases, gps_altitude):
def __init__(self, task, trip, phases, gps_altitude, elevation_correction):

self.all = None
self.leg = None

self.tsk_distance_all = sum(trip.distances)
self.tsk_distance_leg = trip.distances
self.trip = trip
self.gps_altitude = gps_altitude
self.elevation_correction = elevation_correction

# why not use phases directly? pass in functions as argument?
self.no_cruises_leg = [len(phases.cruises(leg)) for leg in range(trip.started_legs())]
self.no_cruises = len(phases.cruises(leg='all'))
self.no_thermals_leg = [len(phases.thermals(leg)) for leg in range(trip.started_legs())]
self.no_thermals = len(phases.thermals(leg='all'))

self.init_all(trip, gps_altitude)
self.init_leg(trip, gps_altitude)
self.init_all()
self.init_leg()

self.determine_performance(task, trip, phases, gps_altitude)

def init_all(self, trip, gps_altitude):
start_h = trip.fixes[0]['gps_alt'] if gps_altitude else trip.fixes[0]['pressure_alt']
start_t = trip.refined_start_time
def get_height(self, trip_index):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice improvement

if (self.gps_altitude):
# return gps altitude corrected for start elevation
return self.trip.fixes[trip_index]['gps_alt'] - self.elevation_correction
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it is clearer if the elevation correction is simply added here and that the value can be both negative and positive. if this is changed, the calculation should be changed too. also there might be other places where this is used.

else:
# return pressure altitude corrected for start elevation
return self.trip.fixes[trip_index]['pressure_alt'] - self.elevation_correction

def init_all(self):
start_h = self.get_height(0)
start_t = self.trip.refined_start_time

if len(trip.fixes) == 1:
if len(self.trip.fixes) == 1:
finish_h = None
finish_t = None
else:
finish_h = trip.fixes[-1]['gps_alt'] if gps_altitude else trip.fixes[-1]['pressure_alt']
finish_t = trip.fixes[-1]['time']
finish_h = self.get_height(-1)
finish_t = self.trip.fixes[-1]['time']

s_flown_task_all = sum(trip.distances) / 1000
s_flown_task_all = sum(self.trip.distances) / 1000

self.all = {"t_start": start_t,
"t_finish": finish_t,
"h_start": start_h,
"h_finish": finish_h,
"s_flown_task": s_flown_task_all}

def init_leg(self, trip, gps_altitude):
def init_leg(self):
leg_values = []

for leg in range(len(trip.distances)):
if trip.outlanding_fix is not None and leg == trip.outlanding_leg():
start_h = trip.fixes[leg]['gps_alt'] if gps_altitude else trip.fixes[leg]['pressure_alt']
start_t = trip.refined_start_time if leg == 0 else trip.fixes[leg]['time']
for leg in range(len(self.trip.distances)):
if self.trip.outlanding_fix is not None and leg == self.trip.outlanding_leg():
start_h = self.get_height(leg)
start_t = self.trip.refined_start_time if leg == 0 else self.trip.fixes[leg]['time']

finish_t = 0
finish_h = 0

s_flown_task_leg = trip.distances[-1] / 1000
elif trip.outlanding_fix is not None and leg > trip.outlanding_leg():
s_flown_task_leg = self.trip.distances[-1] / 1000
elif self.trip.outlanding_fix is not None and leg > self.trip.outlanding_leg():
start_t = 0
start_h = 0

Expand All @@ -68,13 +79,13 @@ def init_leg(self, trip, gps_altitude):

s_flown_task_leg = 0
else:
start_h = trip.fixes[leg]['gps_alt'] if gps_altitude else trip.fixes[leg]['pressure_alt']
start_t = trip.refined_start_time if leg == 0 else trip.fixes[leg]['time']
start_h = self.get_height(leg)
start_t = self.trip.refined_start_time if leg == 0 else self.trip.fixes[leg]['time']

finish_t = trip.fixes[leg+1]['time']
finish_h = trip.fixes[leg+1]['gps_alt'] if gps_altitude else trip.fixes[leg+1]['pressure_alt']
finish_t = self.trip.fixes[leg+1]['time']
finish_h = self.get_height(leg+1)

s_flown_task_leg = trip.distances[leg] / 1000
s_flown_task_leg = self.trip.distances[leg] / 1000

leg_values.append({"t_start": start_t,
"t_finish": finish_t,
Expand Down
2 changes: 1 addition & 1 deletion PySoar/settingsClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def determine_performance_dictionary(self):
self.set_performance_entry("t_start", "Start time", "text", "neutral", "[local time]", True, True, True, True)
self.set_performance_entry("t_finish", "Finish time", "text", "neutral", "[local time]", True, False, True, True)
self.set_performance_entry("h_start", "Start height", "number", "high", "[m]", True, True, True, True)
self.set_performance_entry("h_finish", "Finish height", "number", "high", "[m]", True, False, True, False)
self.set_performance_entry("h_finish", "Finish height", "number", "low", "[m]", True, False, True, True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it really umambiguous that a lower finish height is always better? i guess it makes sense for the last leg, but for others along the task this really depends? (for instance if you round a turnpoint downwind).
i think the original code was also wrong, so maybe "neutral" would be best here?

now that i think of this, the same goes for the start height...

self.set_performance_entry("vario_gem", "Average rate of climb", "number", "high", "[m/s]", False, False, True, True)
self.set_performance_entry("v_glide_avg", "Average cruise speed (GS)", "number", "high", "[km/h]", True, False, True, True)
self.set_performance_entry("v_turn_avg", "Average thermal speed (GS)", "number", "low", "[km/h]", False, False, True, True)
Expand Down