diff --git a/rowers/dataprep.py b/rowers/dataprep.py index 411449cf..e67aa895 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -111,6 +111,7 @@ def filter_df(datadf,fieldname,value,largerthan=True): except KeyError: return datadf + if largerthan: mask = datadf[fieldname] < value else: @@ -144,6 +145,7 @@ def clean_df_stats(datadf,workstrokesonly=True,ignorehr=True, datadf=datadf.clip(lower=0) datadf.replace(to_replace=0,value=np.nan,inplace=True) + # return from positive domain to negative try: datadf['catch'] = -datadf['catch'] @@ -900,7 +902,7 @@ def getsmallrowdata_db(columns,ids=[],doclean=True,workstrokesonly=True, convertnewtons=False): prepmultipledata(ids) data = read_cols_df_sql(ids,columns) - + if convertnewtons: if 'peakforce' in columns: data['peakforce'] = data['peakforce']*lbstoN @@ -1206,9 +1208,7 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, driveenergy = drivelength*averageforce*lbstoN distance = rowdatadf.ix[:,'cum_dist'] - - - + data = DataFrame( dict( time = t*1e3, @@ -1231,7 +1231,6 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, ) ) - if bands: # HR bands data['hr_ut2'] = rowdatadf.ix[:,'hr_ut2'] @@ -1272,11 +1271,16 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, except KeyError: peakforceangle = 0*power - try: - driveenergy = rowdatadf.ix[:,'driveenergy'] - except KeyError: - driveenergy = 0*power + if data['driveenergy'].mean() == 0: + try: + driveenergy = rowdatadf.ix[:,'driveenergy'] + except KeyError: + driveenergy = 0*power + else: + driveenergy = data['driveenergy'] + + arclength = (inboard-0.05)*(np.radians(finish)-np.radians(catch)) if arclength.mean()>0: drivelength = arclength @@ -1336,7 +1340,7 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True, data = data.replace([-np.inf,np.inf],np.nan) data = data.fillna(method='ffill') - + # write data if id given if id != 0: data['workoutid'] = id diff --git a/rowers/views.py b/rowers/views.py index 3e86de9c..f534f623 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -387,7 +387,11 @@ def sendmail(request): def add_workout_from_strokedata(user,importid,data,strokedata, source='c2',splitdata=None, workoutsource='concept2'): - workouttype = data['type'] + try: + workouttype = data['type'] + except KeyError: + workouttype = 'rower' + if workouttype not in [x[0] for x in Workout.workouttypes]: workouttype = 'water' try: @@ -6177,18 +6181,24 @@ def workout_getstravaworkout_all(request): res = stravastuff.get_strava_workout(request.user,stravaid) strokedata = res[1] data = res[0] - - id,message = add_workout_from_strokedata(request.user,stravaid,data,strokedata, - source='strava', - workoutsource='strava') - if id==0: - messages.error(request,message) + if data: + id,message = add_workout_from_strokedata( + request.user,stravaid,data,strokedata, + source='strava', + workoutsource='strava') + + if id==0: + messages.error(request,message) + + else: + messages.info(request,"imported Strava workout "+str(stravaid)) + w = Workout.objects.get(id=id) + w.uploadedtostrava=stravaid + w.save() else: - w = Workout.objects.get(id=id) - w.uploadedtostrava=stravaid - w.save() + messages.error(request,"Couldn't import Strava workout "+str(stravaid)) url = reverse(workouts_view) return HttpResponseRedirect(url)