diff --git a/rowers/dataprep.py b/rowers/dataprep.py index cd1eaec5..f6eaaba1 100644 --- a/rowers/dataprep.py +++ b/rowers/dataprep.py @@ -263,6 +263,12 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True, pass + # protect 0 spm values from being nulled + try: + datadf['spm'] = datadf['spm'] + 1.0 + except TypeError: + pass + try: datadf = datadf.clip(lower=0) except TypeError: @@ -270,6 +276,11 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True, datadf.replace(to_replace=0, value=np.nan, inplace=True) + # bring spm back to real values + try: + datadf['spm'] = datadf['spm'] - 1 + except TypeError: + pass # return from positive domain to negative try: @@ -295,6 +306,12 @@ def clean_df_stats(datadf, workstrokesonly=True, ignorehr=True, except KeyError: pass + try: + mask = datadf['spm'] < 0 + datadf.loc[mask,'spm'] = np.nan + except KeyError: + pass + try: mask = datadf['efficiency'] > 200. datadf.loc[mask, 'efficiency'] = np.nan @@ -1614,6 +1631,7 @@ def getsmallrowdata_db(columns, ids=[], doclean=True, workstrokesonly=True): if doclean: data = clean_df_stats(data, ignorehr=True, workstrokesonly=workstrokesonly) + data.dropna(inplace=True,axis=0) return data diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 6b3ae2e4..f498fce3 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -2638,18 +2638,18 @@ def interactive_flex_chart2(id=0,promember=0, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, workstrokesonly=False) workstrokesonly=False - try: tests = rowdata[yparam2] except KeyError: yparam2 = 'None' + + try: tests = rowdata[yparam1] except KeyError: yparam1 = 'None' - rowdata.dropna(axis=1,how='all',inplace=True) # test if we have drive energy nowork = 1 @@ -2670,7 +2670,7 @@ def interactive_flex_chart2(id=0,promember=0, row = Workout.objects.get(id=id) if rowdata.empty: - return "","No valid data" + return "","No valid data",'','',workstrokesonly else: try: rowdata.sort_values(by='time',ascending=True,inplace=True) @@ -2690,7 +2690,7 @@ def interactive_flex_chart2(id=0,promember=0, try: tseconds = rowdata.ix[:,'time'] except KeyError: - return '','No time data - cannot make flex plot','','' + return '','No time data - cannot make flex plot','','',workstrokesonly try: @@ -3098,7 +3098,7 @@ def interactive_flex_chart2(id=0,promember=0, try: distmax = 100+100*int(rowdata['distance'].max()/100.) - except KeyError: + except (KeyError,ValueError): distmax = 100 slider_dist_min = Slider(start=0,end=distmax,value=0,step=1, diff --git a/rowers/utils.py b/rowers/utils.py index 08f97d4b..003a41ab 100644 --- a/rowers/utils.py +++ b/rowers/utils.py @@ -326,7 +326,10 @@ def wavg(group, avg_name, weight_name): should return otherwise. """ d = group[avg_name] - w = group[weight_name] + try: + w = group[weight_name] + except KeyError: + return d.mean() try: return (d * w).sum() / w.sum() except ZeroDivisionError: diff --git a/rowers/views.py b/rowers/views.py index 409ac0d5..ca375bb0 100644 --- a/rowers/views.py +++ b/rowers/views.py @@ -7446,7 +7446,6 @@ def workout_stats_view(request,id=0,message="",successmessage=""): return HttpResponseRedirect(url) datadf = dataprep.clean_df_stats(datadf,workstrokesonly=workstrokesonly) - datadf['deltat'] = datadf['time'].diff() if datadf.empty: datadf,row = dataprep.getrowdata_db(id=id) @@ -7455,6 +7454,7 @@ def workout_stats_view(request,id=0,message="",successmessage=""): if datadf.empty: return HttpResponse("CSV data file not found") + datadf['deltat'] = datadf['time'].diff() workoutstateswork = [1,4,5,8,9,6,7] @@ -8069,15 +8069,31 @@ def workout_flexchart3_view(request,*args,**kwargs): # create interactive plot try: - script,div,js_resources,css_resources,workstrokesonly = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1, - yparam2=yparam2, - promember=promember,plottype=plottype, - workstrokesonly=workstrokesonly) + ( + script, + div, + js_resources, + css_resources, + workstrokesonly + ) = interactive_flex_chart2( + id,xparam=xparam,yparam1=yparam1, + yparam2=yparam2, + promember=promember,plottype=plottype, + workstrokesonly=workstrokesonly + ) except ValueError: - script,div = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1, - yparam2=yparam2, - promember=promember,plottype=plottype, - workstrokesonly=workstrokesonly) + ( + script, + div, + js_resources, + css_resources, + workstrokesonly + ) = interactive_flex_chart2( + id,xparam=xparam,yparam1=yparam1, + yparam2=yparam2, + promember=promember,plottype=plottype, + workstrokesonly=workstrokesonly + ) js_resources = "" css_resources = ""