From 3bf512179c89e1f19d32092093404dde588da1f2 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 19 May 2017 13:27:09 +0200 Subject: [PATCH 1/3] solved losing Empower data --- rowers/dataprep.py | 102 ++++++++++++++++++++++++++++----------------- rowers/forms.py | 7 ++-- rowers/views.py | 4 +- 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/rowers/dataprep.py b/rowers/dataprep.py index e18c8c8b..ec6a050e 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -730,11 +730,11 @@ def new_workout_from_df(r,df, csvfilename ='media/Fusion_'+timestr+'.csv' + df.rename(columns = columndict,inplace=True) starttimeunix = mktime(startdatetime.utctimetuple()) df[' ElapsedTime (sec)'] = df['TimeStamp (sec)'] df['TimeStamp (sec)'] = df['TimeStamp (sec)']+starttimeunix - print df.info() row = rrdata(df=df) row.write_csv(csvfilename,gzip=True) @@ -888,8 +888,9 @@ def getrowdata_db(id=0,doclean=False): if doclean: data = clean_df_stats(data,ignorehr=True) - data['averageforce'] = data['averageforce'] - data['peakforce'] = data['peakforce'] + # these two lines seem redundant ?? + #data['averageforce'] = data['averageforce'] + #data['peakforce'] = data['peakforce'] return data,row @@ -1106,10 +1107,13 @@ def datafusion(id1,id2,columns,offset): offsetmillisecs += offset.days*(3600*24*1000) df2['time'] = df2['time']+offsetmillisecs + keep1 = {c:c for c in set(df1.columns)} + for c in columns: keep1.pop(c) - + + for c in df1.columns: if not c in keep1: df1 = df1.drop(c,1,errors='ignore') @@ -1134,7 +1138,7 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, empower=True,inboard=0.88): if rowdatadf.empty: return 0 - + rowdatadf.set_index([range(len(rowdatadf))],inplace=True) t = rowdatadf.ix[:,'TimeStamp (sec)'] t = pd.Series(t-rowdatadf.ix[0,'TimeStamp (sec)']) @@ -1246,40 +1250,62 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, if empower: try: wash = rowdatadf.ix[:,'wash'] - catch = rowdatadf.ix[:,'catch'] - finish = rowdatadf.ix[:,'finish'] - peakforceangle = rowdatadf.ix[:,'peakforceangle'] - driveenergy = rowdatadf.ix[:,'driveenergy'] - arclength = (inboard-0.05)*(np.radians(finish)-np.radians(catch)) - if arclength.mean()>0: - drivelength = arclength - else: - drivelength = driveenergy/(averageforce*4.44822) - - slip = rowdatadf.ix[:,'slip'] - totalangle = finish-catch - effectiveangle = finish-wash-catch-slip - if windowsize > 3 and windowsize0: + drivelength = arclength + else: + drivelength = driveenergy/(averageforce*4.44822) + + try: + slip = rowdatadf.ix[:,'slip'] + except KeyError: + slip = 0*power + + totalangle = finish-catch + effectiveangle = finish-wash-catch-slip + if windowsize > 3 and windowsize Date: Mon, 22 May 2017 14:19:43 +0200 Subject: [PATCH 2/3] strava upload improvements --- rowers/c2stuff.py | 10 ++++++++-- rowers/stravastuff.py | 13 +++++++------ rowers/views.py | 18 +++++++++++------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/rowers/c2stuff.py b/rowers/c2stuff.py index 91752ca1..88b1fe76 100644 --- a/rowers/c2stuff.py +++ b/rowers/c2stuff.py @@ -104,8 +104,14 @@ 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: + resttime = data['rest_time']/10. + except KeyError: + resttime = 0 + try: + restdistance = data['rest_distance'] + except keyError: + restdistance = 0 try: avghr = data['heart_rate']['average'] except KeyError: diff --git a/rowers/stravastuff.py b/rowers/stravastuff.py index 75fdc740..34297d4b 100644 --- a/rowers/stravastuff.py +++ b/rowers/stravastuff.py @@ -257,11 +257,12 @@ def createstravaworkoutdata(w): with gzip.GzipFile(gzfilename,'wb') as outF: outF.write(s) os.remove(tcxfilename) - return gzfilename + return gzfilename,"" except: + message = str(sys.exc_info()[0]) tcxfilename = 0 - return tcxfilename + return tcxfilename,message # Upload the TCX file to Strava and set the workout activity type # to rowing on Strava @@ -282,8 +283,8 @@ def handle_stravaexport(f2,workoutname,stravatoken,description=''): if res: act = client.update_activity(res.id,activity_type='Rowing',description=description,device_name='Rowsandall.com') else: - message = 'Strava upload timed out.' - return (0,message) + message = 'Strava activity update timed out.' + return (res.id,message) return (res.id,message) @@ -299,7 +300,7 @@ def workout_strava_upload(user,w): else: if (checkworkoutuser(user,w)): try: - tcxfile = createstravaworkoutdata(w) + tcxfile,tcxmesg = createstravaworkoutdata(w) if tcxfile: with open(tcxfile,'rb') as f: res,mes = handle_stravaexport(f,w.name, @@ -326,7 +327,7 @@ def workout_strava_upload(user,w): stravaid = res return message,stravaid else: - message = "Strava Upload error" + message = "Strava TCX data error "+tcxmesg w.uploadedtostrava = -1 stravaid = -1 w.save() diff --git a/rowers/views.py b/rowers/views.py index bf54be17..dbf0ac41 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -1060,9 +1060,9 @@ def workout_tcxemail_view(request,id=0): raise Http404("Workout doesn't exist") if (checkworkoutuser(request.user,w)): try: - tcxfile = stravastuff.createstravaworkoutdata(w) + tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w) if tcxfile == 0: - message = "Something went wrong (TCX export)" + message = "Something went wrong (TCX export) "+tcxmessg messages.error(request,message) url = reverse(workout_export_view, kwargs = { @@ -1179,7 +1179,7 @@ def workout_csvtoadmin_view(request,id=0): successmessage = "The CSV file was sent to the site admin per email" messages.info(request,successmessage) - url = reverse(workout_export_view, + url = reverse(workout_view, kwargs = { 'id':str(w.id), }) @@ -1263,7 +1263,7 @@ def workout_strava_upload_view(request,id=0): raise Http404("Workout doesn't exist") if (checkworkoutuser(request.user,w)): try: - tcxfile = stravastuff.createstravaworkoutdata(w) + tcxfile,tcxmessg = stravastuff.createstravaworkoutdata(w) if tcxfile: with open(tcxfile,'rb') as f: res,mes = stravastuff.handle_stravaexport(f,w.name, @@ -1287,7 +1287,11 @@ def workout_strava_upload_view(request,id=0): try: w.uploadedtostrava = res w.save() - os.remove(tcxfile) + try: + os.remove(tcxfile) + except WindowsError: + print tcxfile + pass url = "/rowers/workout/"+str(w.id)+"/edit" messages.info(request,mes) @@ -1299,8 +1303,8 @@ def workout_strava_upload_view(request,id=0): errorlog.write("views.py line 826\r\n") message = 'Error: '+errorstring messages.error(request,message) - else: - message = "Strava Upload error" + else: # No tcxfile + message = "Strava Data error "+tcxmessg messages.error(request,message) w.uploadedtostrava = -1 w.save() From 753f4a5b9a7339482cfc3e2041d76abc70086d2f Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 22 May 2017 14:22:24 +0200 Subject: [PATCH 3/3] removed print statement --- rowers/runkeeperstuff.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rowers/runkeeperstuff.py b/rowers/runkeeperstuff.py index 2d025ce4..267e421e 100644 --- a/rowers/runkeeperstuff.py +++ b/rowers/runkeeperstuff.py @@ -315,7 +315,6 @@ def get_userid(access_token): except KeyError: res = '' - print res,'userID' return str(res) def workout_runkeeper_upload(user,w):