From 9a9f0725ba7b4c491dc123e5fcd5a0b0dcb471f9 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Tue, 9 Jun 2020 22:46:16 +0200 Subject: [PATCH 1/2] better gps comparisons --- rowers/tasks.py | 3 ++- rowers/views/workoutviews.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/rowers/tasks.py b/rowers/tasks.py index d9ca397a..fcd7bc62 100644 --- a/rowers/tasks.py +++ b/rowers/tasks.py @@ -381,8 +381,9 @@ def handle_check_race_course(self, except IOError: return 0 - + row.calc_dist_from_gps() rowdata = row.df + rowdata['cum_dist'] = rowdata['gps_dist_calculated'] try: s = rowdata[' latitude'] diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 955e6abe..a407d0e2 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -5913,13 +5913,34 @@ def workout_summary_edit_view(request,id,message="",successmessage="" # we are saving the results obtained from the split by power/pace interpreter elif request.method == 'POST' and "savepowerpaceform" in request.POST: - powerorpace = request.POST['powerorpace'] - value_pace = request.POST['value_pace'] - value_power = request.POST['value_power'] - value_work = request.POST['value_work'] - value_spm = request.POST['value_spm'] - activeminutesmin = request.POST['activeminutesmin'] - activeminutesmax = request.POST['activeminutesmax'] + try: + powerorpace = request.POST['powerorpace'] + except: + powerorpace = 'pace' + try: + value_pace = request.POST['value_pace'] + except: + value_pace = avpace + try: + value_power = request.POST['value_power'] + except: + value_power = int(normp) + try: + value_work = request.POST['value_work'] + except: + value_work = int(normw) + try: + value_spm = request.POST['value_spm'] + except: + value_spm = int(normspm) + try: + activeminutesmin = request.POST['activeminutesmin'] + except: + activeminutesmin = 0 + try: + activeminutesmax = request.POST['activeminutesmax'] + except: + pass try: activesecondsmin = 60.*float(activeminutesmin) activesecondsmax = 60.*float(activeminutesmax) From 132ffa856c5e2cf6dd616eae39cfdd43d03a0d23 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 10 Jun 2020 08:23:08 +0200 Subject: [PATCH 2/2] bug fix and fairer GPS comparisons --- rowers/interactiveplots.py | 14 ++++++- rowers/mytypes.py | 3 +- rowers/views/racesviews.py | 82 +++++++++++++++++++++----------------- 3 files changed, 61 insertions(+), 38 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index c993dd42..754c651c 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -261,6 +261,18 @@ def pretty_timedelta(secs): return '{}:{:02}:{:02}'.format(int(hours),int(minutes),int(seconds)) +def mapcolors(x): + try: + return mytypes.color_map[x] + except KeyError: + return mytypes.colors[-1] + +def maptypes(x): + try: + return mytypes.workouttypes_ordered[x] + except KeyError: + return 'Other' + def interactive_workouttype_piechart(workouts): if len(workouts) == 0: return "","Not enough workouts to make a chart" @@ -286,7 +298,7 @@ def interactive_workouttype_piechart(workouts): data = pd.DataFrame(data) - data['color'] = data['type'].apply(lambda x:mytypes.color_map[x]) + data['color'] = data['type'].apply(lambda x:mapcolors(x)) data['totaltime'] = data['value'].apply(lambda x:pretty_timedelta(x)) data['type'] = data['type'].apply(lambda x:mytypes.workouttypes_ordered[x]) diff --git a/rowers/mytypes.py b/rowers/mytypes.py index 294cb8bb..42538697 100644 --- a/rowers/mytypes.py +++ b/rowers/mytypes.py @@ -273,7 +273,8 @@ checktypes = [i[0] for i in workouttypes] from bokeh.palettes import Category10,Category20, Category20c -colors = Category10[9]+Category20[19]+Category20c[19] +#colors = Category10[9] +colors = Category10[9]+list(set(Category20[19]+Category20c[19])) color_map = {checktypes[i]:colors[i] for i in range(len(checktypes))} workoutsources = ( diff --git a/rowers/views/racesviews.py b/rowers/views/racesviews.py index 09a3cb0e..1f6f4a33 100644 --- a/rowers/views/racesviews.py +++ b/rowers/views/racesviews.py @@ -1640,18 +1640,22 @@ def virtualevent_addboat_view(request,id=0): race = race).exclude(userid = r.id) for otherrecord in otherrecords: - otheruser = Rower.objects.get(id=otherrecord.userid) - othername = otheruser.user.first_name+' '+otheruser.user.last_name - registeredname = r.user.first_name+' '+r.user.last_name - if otherrecord.emailnotifications: - job = myqueue( - queue, - handle_sendemail_raceregistration, - otheruser.user.email, othername, - registeredname, - race.name, - race.id - ) + try: + otheruser = Rower.objects.get(id=otherrecord.userid) + othername = otheruser.user.first_name+' '+otheruser.user.last_name + registeredname = r.user.first_name+' '+r.user.last_name + if otherrecord.emailnotifications: + job = myqueue( + queue, + handle_sendemail_raceregistration, + otheruser.user.email, othername, + registeredname, + race.name, + race.id + ) + except Rower.DoesNotExist: + pass + followers = VirtualRaceFollower.objects.filter(race = race) @@ -1868,18 +1872,21 @@ def virtualevent_register_view(request,id=0): race = race).exclude(userid = r.id) for otherrecord in otherrecords: - otheruser = Rower.objects.get(id=otherrecord.userid) - othername = otheruser.user.first_name+' '+otheruser.user.last_name - registeredname = r.user.first_name+' '+r.user.last_name - if otherrecord.emailnotifications: - job = myqueue( - queue, - handle_sendemail_raceregistration, - otheruser.user.email, othername, - registeredname, - race.name, - race.id - ) + try: + otheruser = Rower.objects.get(id=otherrecord.userid) + othername = otheruser.user.first_name+' '+otheruser.user.last_name + registeredname = r.user.first_name+' '+r.user.last_name + if otherrecord.emailnotifications: + job = myqueue( + queue, + handle_sendemail_raceregistration, + otheruser.user.email, othername, + registeredname, + race.name, + race.id + ) + except Rower.DoesNotExist: + pass followers = VirtualRaceFollower.objects.filter(race = race) @@ -2136,18 +2143,21 @@ def indoorvirtualevent_register_view(request,id=0): race = race).exclude(userid = r.id) for otherrecord in otherrecords: - otheruser = Rower.objects.get(id=otherrecord.userid) - othername = otheruser.user.first_name+' '+otheruser.user.last_name - registeredname = r.user.first_name+' '+r.user.last_name - if otherrecord.emailnotifications: - job = myqueue( - queue, - handle_sendemail_raceregistration, - otheruser.user.email, othername, - registeredname, - race.name, - race.id - ) + try: + otheruser = Rower.objects.get(id=otherrecord.userid) + othername = otheruser.user.first_name+' '+otheruser.user.last_name + registeredname = r.user.first_name+' '+r.user.last_name + if otherrecord.emailnotifications: + job = myqueue( + queue, + handle_sendemail_raceregistration, + otheruser.user.email, othername, + registeredname, + race.name, + race.id + ) + except Rower.DoesNotExist: + pass followers = VirtualRaceFollower.objects.filter(race = race)