From 2f5b256481c25b266fe6295acd32460ec70b3a2d Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 4 Jan 2017 12:32:19 +0100 Subject: [PATCH 1/5] added test if splitsdata is available --- rowers/views.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/rowers/views.py b/rowers/views.py index f80ff03a..4b3510e8 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -319,7 +319,8 @@ def checkworkoutuser(user,workout): except Rower.DoesNotExist: return(False) -def add_workout_from_strokedata(user,importid,data,strokedata,source='c2'): +def add_workout_from_strokedata(user,importid,data,strokedata, + source='c2',splitdata=None): workouttype = data['type'] if workouttype not in [x[0] for x in Workout.workouttypes]: workouttype = 'water' @@ -3691,14 +3692,21 @@ def workout_getc2workout_view(request,c2id): res = c2stuff.get_c2_workout(request.user,c2id) if (res.status_code == 200): data = res.json()['data'] + splitdata = None + if 'splits' in data: + splitdata = data['splits'] + if 'intervals' in data: + splitdata = data['intervals'] if 'stroke_data' in data: # test = data['stroke_data'] res2 = c2stuff.get_c2_workout_strokes(request.user,c2id) # 2016-07-27 added below if statement (balkanboy error report) if res2.status_code == 200: strokedata = pd.DataFrame.from_dict(res2.json()['data']) - id = add_workout_from_strokedata(request.user,c2id,data,strokedata, - source='c2') + id = add_workout_from_strokedata(request.user,c2id, + data,strokedata, + splitdata=None, + source='c2') w = Workout.objects.get(id=id) w.uploadedtoc2=c2id w.save() From af9662edac83bba1aeaa234e19aae0ab5ad67b24 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 6 Jan 2017 19:43:46 +0100 Subject: [PATCH 2/5] Make email processing more robust --- rowers/management/commands/processemail.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rowers/management/commands/processemail.py b/rowers/management/commands/processemail.py index 4e24d3ef..b92692bb 100644 --- a/rowers/management/commands/processemail.py +++ b/rowers/management/commands/processemail.py @@ -63,12 +63,16 @@ class Command(BaseCommand): wid = [make_new_workout_from_email(rr,a.document,name)] res += wid link = 'http://rowsandall.com/rowers/workout/'+str(wid[0])+'/edit' - dd = send_confirm(u,name,link) except: # replace with code to process error res += ['fail: '+name] donotdelete = 1 + try: + dd = send_confirm(u,name,link) + except: + pass + except Rower.DoesNotExist: pass From aec79544ecf1d2759728e25a1da5e80905d08fb0 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 9 Jan 2017 14:34:04 +0100 Subject: [PATCH 3/5] refined Strava error logging --- rowers/views.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rowers/views.py b/rowers/views.py index 1d1a64c2..0c690489 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -929,6 +929,15 @@ def workout_strava_upload_view(request,id=0): res = stravastuff.handle_stravaexport(f,w.name, r.stravatoken, description=w.notes) + except: + with open("media/stravaerrors.log","a") as errorlog: + errorstring = str(sys.exc_info()[0]) + timestr = strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\r\n") + errorlog.write("views.py line 937\r\n") + message = 'Error: '+errorstring + res = 0 + try: w.uploadedtostrava = res w.save() os.remove(tcxfile) @@ -939,7 +948,7 @@ def workout_strava_upload_view(request,id=0): errorstring = str(sys.exc_info()[0]) timestr = strftime("%Y%m%d-%H%M%S") errorlog.write(timestr+errorstring+"\r\n") - errorlog.write("views.py line 946\r\n") + errorlog.write("views.py line 952\r\n") message = 'Error: '+errorstring From 29180b3f78832304e9f909e3f519b2e914b18289 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 9 Jan 2017 16:08:08 +0100 Subject: [PATCH 4/5] C2 splits on import --- rowers/c2stuff.py | 66 +++++++++++++++++++++++++++++++++++++++++++++++ rowers/views.py | 46 ++++++++++++--------------------- 2 files changed, 82 insertions(+), 30 deletions(-) diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 13f3e0e4..d94b9a9a 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -77,6 +77,72 @@ def c2wc(weightclass): return res + +def summaryfromsplitdata(splitdata,data,filename,sep='|'): + + totaldist = data['distance'] + totaltime = data['time']/10. + spm = data['stroke_rate'] + resttime = data['rest_time']/10. + restdistance = data['rest_distance'] + try: + avghr = data['heart_rate']['average'] + except KeyError: + avghr = 0 + try: + maxhr = data['heart_rate']['max'] + except KeyError: + maxhr = 0 + + avgpace = 500.*totaltime/totaldist + restpace = 500.*resttime/restdistance + + velo = totaldist/totaltime + avgpower = 2.8*velo**(3.0) + + restvelo = restdistance/resttime + restpower = 2.8*restvelo**(3.0) + + avgdps = totaldist/data['stroke_count'] + + from rowingdata import summarystring,workstring,interval_string + + sums = summarystring(totaldist,totaltime,avgpace,spm,avghr,maxhr, + avgdps,avgpower,readFile=filename, + separator=sep) + + sums += workstring(totaldist,totaltime,avgpace,spm,avghr,maxhr, + avgdps,avgpower,separator=sep,symbol='W') + + sums += workstring(restdistance,resttime,restpace,0,0,0,0,restpower, + separator=sep, + symbol='R') + + intervalnr=0 + for interval in splitdata: + idist = interval['distance'] + itime = interval['time']/10. + ipace = 500.*itime/idist + ispm = interval['stroke_rate'] + try: + iavghr = interval['heart_rate']['average'] + except KeyError: + iavghr = 0 + + try: + imaxhr = interval['heart_rate']['average'] + except KeyError: + imaxhr = 0 + + ivelo = idist/itime + ipower = 2.8*ivelo**(3.0) + + sums += interval_string(intervalnr,idist,itime,ipace,ispm, + iavghr,imaxhr,0,ipower,separator=sep) + intervalnr+=1 + + return sums + def createc2workoutdata_as_splits(w): filename = w.csvfilename row = rowingdata(filename) diff --git a/rowers/views.py b/rowers/views.py index 1606770d..1c9afaa5 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -3697,35 +3697,12 @@ def workout_getc2workout_view(request,c2id): res = c2stuff.get_c2_workout(request.user,c2id) if (res.status_code == 200): data = res.json()['data'] -<<<<<<< HEAD splitdata = None - if 'splits' in data: - splitdata = data['splits'] - if 'intervals' in data: - splitdata = data['intervals'] - if 'stroke_data' in data: - # test = data['stroke_data'] - res2 = c2stuff.get_c2_workout_strokes(request.user,c2id) - # 2016-07-27 added below if statement (balkanboy error report) - if res2.status_code == 200: - strokedata = pd.DataFrame.from_dict(res2.json()['data']) - id = add_workout_from_strokedata(request.user,c2id, - data,strokedata, - splitdata=None, - source='c2') - w = Workout.objects.get(id=id) - w.uploadedtoc2=c2id - w.save() - url = "/rowers/workout/"+str(id)+"/edit" - return HttpResponseRedirect(url) - else: - message = json.loads(s.text)['message'] - url = reverse(workout_c2import_view, - kwargs={ - 'message':message, - }) - return HttpResponseRedirect(url) -======= + if 'splits' in data['workout']: + splitdata = data['workout']['splits'] + if 'intervals' in data['workout']: + splitdata = data['workout']['intervals'] + if data['stroke_data']: res2 = c2stuff.get_c2_workout_strokes(request.user,c2id) else: @@ -3742,10 +3719,19 @@ def workout_getc2workout_view(request,c2id): source='c2') w = Workout.objects.get(id=id) w.uploadedtoc2=c2id - w.save() + if splitdata: + try: + w.summary = c2stuff.summaryfromsplitdata(splitdata,data,w.csvfilename) + except: + with open("media/c2splitdata.log","a") as errorlog: + errorstring = str(sys.exc_info()[0]) + timestr = strftime("%Y%m%d-%H%M%S") + errorlog.write(timestr+errorstring+"\r\n") + errorlog.write("views.py line 952\r\n") + + w.save() url = "/rowers/workout/"+str(id)+"/edit" return HttpResponseRedirect(url) ->>>>>>> develop else: # message = json.loads(s.text)['message'] message = json.loads(res2.text)['message'] From 699123eae6ae624c1cfb4f6651d3194a67c80ad3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 9 Jan 2017 21:10:14 +0100 Subject: [PATCH 5/5] inverted pace y axis --- rowers/interactiveplots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index be61191e..0dc9ba73 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1714,7 +1714,7 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm', seconds = ["%S"], minutes = ["%M"] ) - + plot.y_range = Range1d(ymin,ymax) #plot.y_range = Range1d(ymin,ymax) hover = plot.select(dict(type=HoverTool))