From 39a196b94974bb5e2df8069f23971a9b478d3ef2 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 14 Apr 2021 17:42:12 +0200 Subject: [PATCH] coverage info --- rowers/interactiveplots.py | 605 +++++++++---------------- rowers/tests/test_emails.py | 5 +- rowers/tests/test_interactivecharts.py | 9 - rowers/tests/test_permissions2.py | 28 -- rowers/tests/test_plans.py | 4 + rowers/views/workoutviews.py | 6 +- 6 files changed, 232 insertions(+), 425 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 7c89a0bf..271fec56 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -145,7 +145,7 @@ def errorbar(fig, x, y, source=ColumnDataSource(), yerrvalues = source.data['yerror'] try: colorvalues = source.data['color'] - except KeyError: + except KeyError: # pragma: no cover colorvalues = ["#%02x%02x%02x" % (255,0,0) for x in xvalues] @@ -168,7 +168,7 @@ def errorbar(fig, x, y, source=ColumnDataSource(), fig.multi_line(x_err_x, x_err_y, color=err_color, name='xerr', **error_kwargs) - except TypeError: + except TypeError: # pragma: no cover pass try: @@ -189,7 +189,7 @@ def errorbar(fig, x, y, source=ColumnDataSource(), fig.multi_line(y_err_x, y_err_y, color=err_color, name='yerr',**error_kwargs) - except TypeError: + except TypeError: # pragma: no cover pass fig.circle(x, y, source=source, name='data',color=color, @@ -317,7 +317,7 @@ def pretty_timedelta(secs): def mapcolors(x): try: return mytypes.color_map[x] - except KeyError: + except KeyError: # pragma: no cover return mytypes.colors[-1] def interactive_workouttype_piechart(workouts): @@ -331,7 +331,7 @@ def interactive_workouttype_piechart(workouts): try: # label = mytypes.workouttypes_ordered[w.workouttype] label = w.workouttype - except KeyError: + except KeyError: # pragma: no cover label = w.workouttype try: datadict[label] += 60*(60*w.duration.hour+w.duration.minute)+w.duration.second @@ -350,7 +350,7 @@ def interactive_workouttype_piechart(workouts): data['totaltime'] = data['value'].apply(lambda x:pretty_timedelta(x)) try: data['type'] = data['type'].apply(lambda x:mytypes.workouttypes_ordered[x]) - except KeyError: + except KeyError: # pragma: no cover pass @@ -376,15 +376,15 @@ def interactive_workouttype_piechart(workouts): def interactive_boxchart(datadf,fieldname,extratitle='', spmmin=0,spmmax=0,workmin=0,workmax=0): - if datadf.empty: + if datadf.empty: # pragma: no cover return '','It looks like there are no data matching your filter' columns = datadf.columns - if not fieldname in columns: + if not fieldname in columns: # pragma: no cover return '','It looks like there are no data matching your filter' - if not 'date' in columns: + if not 'date' in columns: # pragma: no cover return '','Not enough data' @@ -402,7 +402,7 @@ def interactive_boxchart(datadf,fieldname,extratitle='', try: boxwhiskers = hv.BoxWhisker(datadf,'date',fieldname) boxwhiskers.opts(tools=TOOLS,outlier_color='white') - except DataError: + except DataError: # pragma: no cover return "","Invalid Data" @@ -422,7 +422,7 @@ def interactive_boxchart(datadf,fieldname,extratitle='', years=["%d %B %Y"], ) - if fieldname == 'pace': + if fieldname == 'pace': # pragma: no cover plot.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] @@ -458,10 +458,10 @@ def interactive_planchart(data,startdate,enddate): yaxmaximum = data['executed'].max() - if data['planned'].max() > yaxmaximum: + if data['planned'].max() > yaxmaximum: # pragma: no cover yaxmaximum = data['planned'].max() - if yaxmaximum == 0: + if yaxmaximum == 0: # pragma: no cover yaxmaximum = 250 yrange1 = Range1d(start=0,end=1.1*yaxmaximum) @@ -513,7 +513,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type',toolbar_lo aantal=1 initials = w.user.user.first_name[0:aantal]+w.user.user.last_name[0:aantal] if w.user.id not in idseen: - while initials in seen: + while initials in seen: # pragma: no cover aantal += 1 initials = w.user.user.first_name[0:aantal]+w.user.user.last_name[0:aantal] @@ -531,13 +531,13 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type',toolbar_lo rscore = w.rscore trimp = w.trimp - if rscore == 0: + if rscore == 0: # pragma: no cover rscore = w.hrtss if totaldays<30: dates.append(dd) dates_sorting.append(dd2) - else: + else: # pragma: no cover dates.append(dd3) dates_sorting.append(dd3) durations.append(du) @@ -554,17 +554,17 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type',toolbar_lo types.append(w.workouttype) try: rowers.append(rowersinitials[w.user.id]) - except IndexError: + except IndexError: # pragma: no cover rowers.append(str(w.user)) try: d = utc.localize(startdate) - except (ValueError,AttributeError): + except (ValueError,AttributeError): # pragma: no cover d = startdate try: enddate = utc.localize(enddate) - except (ValueError,AttributeError): + except (ValueError,AttributeError): # pragma: no cover pass # add dates with no activity @@ -575,7 +575,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type',toolbar_lo if totaldays<30: dates.append(d.strftime('%m/%d')) dates_sorting.append(d.strftime('%Y/%m/%d')) - else: + else: # pragma: no cover dates.append(d.strftime('%Y/%m')) dates_sorting.append(d.strftime('%Y/%m')) durations.append(0) @@ -699,7 +699,7 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l aantal=1 initials = w.user.user.first_name[0:aantal]+w.user.user.last_name[0:aantal] if w.user.id not in idseen: - while initials in seen: + while initials in seen: # pragma: no cover aantal += 1 initials = w.user.user.first_name[0:aantal]+w.user.user.last_name[0:aantal] @@ -716,10 +716,10 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l du = w.duration.hour*60+w.duration.minute trimp = w.trimp rscore = w.rscore - if rscore == 0: + if rscore == 0: # pragma: no cover rscore = w.hrtss - if totaldays<30: + if totaldays<30: # pragma: no cover dates.append(dd) dates_sorting.append(dd2) else: @@ -739,17 +739,17 @@ def interactive_activitychart2(workouts,startdate,enddate,stack='type',toolbar_l types.append(w.workouttype) try: rowers.append(rowersinitials[w.user.id]) - except IndexError: + except IndexError: # pragma: no cover rowers.append(str(w.user)) try: d = utc.localize(startdate) - except (ValueError,AttributeError): + except (ValueError,AttributeError): # pragma: no cover d = startdate try: enddate = utc.localize(enddate) - except (ValueError,AttributeError): + except (ValueError,AttributeError): # pragma: no cover pass # add dates with no activity @@ -875,7 +875,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): if workstrokesonly: try: rowdata = rowdata[~rowdata['workoutstate'].isin(workoutstatesrest)] - except KeyError: + except KeyError: # pragma: no cover pass if rowdata.empty: @@ -886,7 +886,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): # peakforce = slope*peakforceangle + intercept try: slope, intercept, r,p,stderr = linregress(rowdata['peakforceangle'],rowdata['peakforce']) - except KeyError: + except KeyError: # pragma: no cover slope = 0 intercept = 0 @@ -938,7 +938,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): a95b = Rinv[0,1]*y95 + rowdata['peakforceangle'].median() F95b = Rinv[1,1]*y95 + rowdata['peakforce'].median() - except KeyError: + except KeyError: # pragma: no cover a25 = 0 F25 = 0 @@ -972,7 +972,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): catch75 = rowdata['catch'].quantile(q=0.75) catch05 = rowdata['catch'].quantile(q=0.05) catch95 = rowdata['catch'].quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover catchav = 0 catch25 = 0 catch75 = 0 @@ -985,7 +985,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): finish75 = rowdata['finish'].quantile(q=0.75) finish05 = rowdata['finish'].quantile(q=0.05) finish95 = rowdata['finish'].quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover finishav = 0 finish25 = 0 finish75 = 0 @@ -998,7 +998,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): wash75 = (rowdata['finish']-rowdata['wash']).quantile(q=0.75) wash05 = (rowdata['finish']-rowdata['wash']).quantile(q=0.05) wash95 = (rowdata['finish']-rowdata['wash']).quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover washav = 0 wash25 = 0 wash75 = 0 @@ -1011,7 +1011,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): slip75 = (rowdata['slip']+rowdata['catch']).quantile(q=0.75) slip05 = (rowdata['slip']+rowdata['catch']).quantile(q=0.05) slip95 = (rowdata['slip']+rowdata['catch']).quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover slipav = 0 slip25 = 0 slip75 = 0 @@ -1024,7 +1024,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): peakforce75 = rowdata['peakforce'].quantile(q=0.75) peakforce05 = rowdata['peakforce'].quantile(q=0.05) peakforce95 = rowdata['peakforce'].quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover peakforceav = 0 peakforce25 = 0 peakforce75 = 0 @@ -1034,7 +1034,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): try: averageforceav = rowdata['averageforce'].median() - except KeyError: + except KeyError: # pragma: no cover averageforceav = 0 try: @@ -1043,7 +1043,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): peakforceangle25 = rowdata['peakforceangle'].quantile(q=0.25) peakforceangle75 = rowdata['peakforceangle'].quantile(q=0.75) peakforceangle95 = rowdata['peakforceangle'].quantile(q=0.95) - except KeyError: + except KeyError: # pragma: no cover peakforceangleav = 0 peakforceangle25 = 0 peakforceangle75 = 0 @@ -1147,7 +1147,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): rowdata ) - if plottype == 'scatter': + if plottype == 'scatter': # pragma: no cover try: sourcepoints = ColumnDataSource( data = dict( @@ -1240,7 +1240,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): rowdata['peakforce'].values[i], thresholdforce, 0] - except KeyError: + except KeyError: # pragma: no cover x = [0,0] y = [0,0] @@ -1259,7 +1259,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'): glyph = MultiLine(xs='x',ys='y',line_color='black',line_alpha=0.05) plot.add_glyph(sourcemultiline,glyph) - else: + else: # pragma: no cover sourcemultiline = ColumnDataSource(dict( x=[],y=[])) @@ -1613,12 +1613,12 @@ def getfatigues( if getattr(w,metricchoice) > 0: weight += getattr(w,metricchoice) if getattr(w,metricchoice) <= 0: - if metricchoice == 'rscore' and w.hrtss > 0: + if metricchoice == 'rscore' and w.hrtss > 0: # pragma: no cover weight+= w.hrtss else: trimp,hrtss = dataprep.workout_trimp(w) rscore,normp = dataprep.workout_rscore(w) - if w.rpe and w.rpe > 0: + if w.rpe and w.rpe > 0: # pragma: no cover dd = 3600*w.duration.hour+60*w.duration.minute+w.duration.second dd = dd/3600 weight += rpetotss[w.rpe]*dd @@ -1886,7 +1886,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, endfatigue = fatigues[-2] endform = endfitness-endfatigue - if modelchoice == 'banister': + if modelchoice == 'banister': # pragma: no cover df['fatigue'] = k2*df['fatigue'] df['fitness'] = p0+k1*df['fitness'] @@ -1949,7 +1949,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, y_range_name = "watermark", ) - if modelchoice == 'banister': + if modelchoice == 'banister': # pragma: no cover fitlabel = 'PTE (fitness)' fatiguelabel = 'NTE (fatigue)' formlabel = 'Performance' @@ -1963,7 +1963,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, fatiguelabel = 'Fatigue' formlabel = 'Freshness' rightaxlabel = 'Freshness' - if dofatigue: + if dofatigue: # pragma: no cover yaxlabel = 'Fitness/Fatigue' else: yaxlabel = 'Fitness' @@ -1985,14 +1985,14 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, #elif showtests: # y1rangemin = df.loc[:,['testpower','fitness']].min().min() # y1rangemax = df.loc[:,['testpower','fitness']].max().max()*1.02 - if dofatigue: + if dofatigue: # pragma: no cover y1rangemin = df.loc[:,['fitness','fatigue']].min().min() y1rangemax = df.loc[:,['fitness','fatigue']].max().max()*1.02 else: y1rangemin = df.loc[:,['fitness']].min().min() y1rangemax = df.loc[:,['fitness']].max().max()*1.02 - if doform: + if doform: # pragma: no cover plot.extra_y_ranges["yax2"] = Range1d(start=y2rangemin,end=y2rangemax) plot.add_layout(LinearAxis(y_range_name="yax2",axis_label=rightaxlabel),"right") @@ -2003,10 +2003,10 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, plot.add_layout(band) - if dofatigue: + if dofatigue: # pragma: no cover plot.line('date','fatigue',source=source,color='red', legend_label=fatiguelabel) - if doform: + if doform: # pragma: no cover plot.line('date','form',source=source,color='green', legend_label=formlabel,y_range_name="yax2") @@ -2079,7 +2079,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, try: script,div = components(layout) - except Exception as e: + except Exception as e: # pragma: no cover df.dropna(inplace=True,axis=0,how='any') return ( '', @@ -2120,7 +2120,7 @@ def interactive_histoall(theworkouts,histoparam,includereststrokes, histopwr = rowdata[histoparam].values except KeyError: return "","No data" - if len(histopwr) == 0: + if len(histopwr) == 0: # pragma: no cover return "","No valid data available" # throw out nans @@ -2226,7 +2226,7 @@ def interactive_histoall(theworkouts,histoparam,includereststrokes, try: script, div = components(layout) - except ValueError: + except ValueError: # pragma: no cover script = '' div = '' @@ -2388,7 +2388,7 @@ def course_map(course): return script,div def leaflet_chart(lat,lon,name=""): - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] @@ -2404,7 +2404,7 @@ def leaflet_chart(lat,lon,name=""): df.fillna(method='ffill',axis=0,inplace=True) lat = df['lat'] lon = df['lon'] - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] latmean = lat.mean() @@ -2542,7 +2542,7 @@ def leaflet_chart_compare(course,workoutids,labeldict={},startenddict={}): 'time':time-time[0], }) data.append(df) - except (Workout.DoesNotExist,KeyError): + except (Workout.DoesNotExist,KeyError): # pragma: no cover pass @@ -2607,7 +2607,7 @@ def leaflet_chart_compare(course,workoutids,labeldict={},startenddict={}): lat = df['lat'] lon = df['lon'] - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] latbegin = lat.values[0] @@ -2715,13 +2715,13 @@ var navionics = new JNC.Leaflet.NavionicsOverlay({{ group = df[df['workoutid']==int(id)].copy() try: startsecond,endsecond = startenddict[id] - except KeyError: + except KeyError: # pragma: no cover startsecond = 0 endsecond = 0 try: label = labeldict[id] - except KeyError: + except KeyError: # pragma: no cover label = str(id) group.sort_values(by='time',ascending=True,inplace=True) @@ -2780,7 +2780,7 @@ var navionics = new JNC.Leaflet.NavionicsOverlay({{ return script,div def leaflet_chart2(lat,lon,name=""): - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] @@ -2796,7 +2796,7 @@ def leaflet_chart2(lat,lon,name=""): df.fillna(method='ffill',axis=0,inplace=True) lat = df['lat'] lon = df['lon'] - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] latmean = lat.mean() @@ -2919,7 +2919,7 @@ def leaflet_chart2(lat,lon,name=""): return script,div def leaflet_chart_video(lat,lon,name=""): - if not len(lat) or not len(lon): + if not len(lat) or not len(lon): # pragma: no cover return [0,"invalid coordinate data"] @@ -2935,7 +2935,7 @@ def leaflet_chart_video(lat,lon,name=""): df.fillna(method='ffill',axis=0,inplace=True) lat = df['lat'] lon = df['lon'] - if lat.empty or lon.empty: + if lat.empty or lon.empty: # pragma: no cover return [0,"invalid coordinate data"] latmean = lat.mean() @@ -3072,7 +3072,7 @@ def interactive_agegroupcpchart(age,normalized=False): weightcategory='hwt' ) velo = (worldclasspower/2.8)**(1./3.) - try: + try: # pragma: no cover duration = distance/velo fhduration.append(duration) fhpower.append(worldclasspower) @@ -3090,7 +3090,7 @@ def interactive_agegroupcpchart(age,normalized=False): distance = int(60*duration*velo) fhduration.append(60.*duration) fhpower.append(worldclasspower) - except ValueError: + except ValueError: # pragma: no cover pass flduration = [] @@ -3104,7 +3104,7 @@ def interactive_agegroupcpchart(age,normalized=False): weightcategory='lwt' ) velo = (worldclasspower/2.8)**(1./3.) - try: + try: # pragma: no cover duration = distance/velo flduration.append(duration) flpower.append(worldclasspower) @@ -3122,7 +3122,7 @@ def interactive_agegroupcpchart(age,normalized=False): distance = int(60*duration*velo) flduration.append(60.*duration) flpower.append(worldclasspower) - except ValueError: + except ValueError: # pragma: no cover pass mlduration = [] @@ -3136,7 +3136,7 @@ def interactive_agegroupcpchart(age,normalized=False): weightcategory='lwt' ) velo = (worldclasspower/2.8)**(1./3.) - try: + try: # pragma: no cover duration = distance/velo mlduration.append(duration) mlpower.append(worldclasspower) @@ -3154,7 +3154,7 @@ def interactive_agegroupcpchart(age,normalized=False): distance = int(60*duration*velo) mlduration.append(60.*duration) mlpower.append(worldclasspower) - except ValueError: + except ValueError: # pragma: no cover pass @@ -3169,7 +3169,7 @@ def interactive_agegroupcpchart(age,normalized=False): weightcategory='hwt' ) velo = (worldclasspower/2.8)**(1./3.) - try: + try: # pragma: no cover duration = distance/velo mhduration.append(duration) mhpower.append(worldclasspower) @@ -3187,7 +3187,7 @@ def interactive_agegroupcpchart(age,normalized=False): distance = int(60*duration*velo) mhduration.append(60.*duration) mhpower.append(worldclasspower) - except ValueError: + except ValueError: # pragma: no cover pass @@ -3201,27 +3201,27 @@ def interactive_agegroupcpchart(age,normalized=False): if len(fhduration)>=4: p1fh, success = optimize.leastsq(errfunc, p0[:], args = (fhduration,fhpower)) - else: + else: # pragma: no cover p1fh = None # fitting WC data to three parameter CP model if len(flduration)>=4: p1fl, success = optimize.leastsq(errfunc, p0[:], args = (flduration,flpower)) - else: + else: # pragma: no cover p1fl = None # fitting WC data to three parameter CP model if len(mlduration)>=4: p1ml, success = optimize.leastsq(errfunc, p0[:], args = (mlduration,mlpower)) - else: + else: # pragma: no cover p1ml = None if len(mhduration)>=4: p1mh, success = optimize.leastsq(errfunc, p0[:], args = (mhduration,mhpower)) - else: + else: # pragma: no cover p1mh = None fitt = pd.Series(10**(4*np.arange(100)/100.)) @@ -3317,7 +3317,7 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data', powerdf = powerdf[~(powerdf == 0).any(axis=1)] # plot tools - if (promember==1): + if (promember==1): # pragma: no cover TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' else: TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' @@ -3348,7 +3348,7 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data', if type == 'water': p1 = [r.p0,r.p1,r.p2,r.p3] ratio = r.cpratio - elif type == 'erg' : + elif type == 'erg' : # pragma: no cover p1 = [r.ep0,r.ep1,r.ep2,r.ep3] ratio = r.ecpratio @@ -3371,7 +3371,7 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data', # fitting WC data to three parameter CP model - if len(wcdurations)>=4: + if len(wcdurations)>=4: # pragma: no cover fitfunc = lambda pars,x: pars[0]/(1+(x/pars[2])) + pars[1]/(1+(x/pars[3])) errfunc = lambda pars,x,y: fitfunc(pars,x)-y p1wc, success = optimize.leastsq(errfunc, p0[:], @@ -3379,7 +3379,7 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data', else: p1wc = None - if p1wc is not None and cpoverlay: + if p1wc is not None and cpoverlay: # pragma: no cover fitpowerwc = fitfunc(p1wc,fitt) fitpowerexcellent = 0.7*fitfunc(p1wc,fitt) fitpowergood = 0.6*fitfunc(p1wc,fitt) @@ -3480,7 +3480,7 @@ def interactive_otwcpchart(powerdf,promember=0,rowername="",r=None,cpfit='data', plot.line('duration','CPmax',source=sourcecomplex,legend_label="CP Model", color='red') - if p1wc is not None: + if p1wc is not None: # pragma: no cover plot.line('duration','fitpowerwc',source=sourcecomplex, legend_label="Gold Medal Standard", color='darkgoldenrod',line_dash='dotted') @@ -3516,7 +3516,7 @@ def interactive_agegroup_plot(df,distance=2000,duration=None, name = df['name'] season = df['season'] - if duration: + if duration: # pragma: no cover duration2 = int(duration/60.) plottitle = sex+' '+weightcategory+' %s min' % duration2 else: @@ -3584,7 +3584,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, # plot tools if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' @@ -3615,7 +3615,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, # fitting the data to Paul if len(thedistances)>=2: paulslope, paulintercept,r,p,stderr = linregress(np.log10(thedistances),p) - else: + else: # pragma: no cover paulslope = 5.0/np.log10(2.0) paulintercept = p[0]-paulslope*np.log10(thedistances[0]) @@ -3655,7 +3655,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, if len(wcdurations)>=4: p1wc, success = optimize.leastsq(errfunc, p0[:], args = (wcdurations,wcpower)) - else: + else: # pragma: no cover p1wc = None # fitting the data to three parameter CP model @@ -3665,18 +3665,18 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, if len(thesecs)>=4: try: p1, success = optimize.leastsq(errfunc, p0[:], args = (thesecs,theavpower)) - except (RuntimeError,RuntimeWarning): + except (RuntimeError,RuntimeWarning): # pragma: no cover factor = fitfunc(p0,thesecs.mean())/theavpower.mean() p1 = [p0[0]/factor,p0[1]/factor,p0[2],p0[3]] success = 0 - else: + else: # pragma: no cover factor = fitfunc(p0,thesecs.mean())/theavpower.mean() p1 = [p0[0]/factor,p0[1]/factor,p0[2],p0[3]] success = 0 # Get stayer score - if success == 1: + if success == 1: # pragma: no cover power1min = fitfunc(p1,60.) power4min = fitfunc(p1,240.) power6min = fitfunc(p1,360.) @@ -3711,7 +3711,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, fitpowerfair = 0.5*fitfunc(p1wc,fitt) fitpoweraverage = 0.4*fitfunc(p1wc,fitt) - else: + else: # pragma: no cover fitpowerwc = 0*fitpower fitpowerexcellent = 0*fitpower fitpowergood = 0*fitpower @@ -3721,7 +3721,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, message = "" - if len(fitpower[fitpower<0]) > 0: + if len(fitpower[fitpower<0]) > 0: # pragma: no cover message = "CP model fit didn't give correct results" fitvelo = (fitpower/2.8)**(1./3.) @@ -3786,7 +3786,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, plot.xaxis.axis_label = "Duration (seconds)" plot.yaxis.axis_label = "Power (W)" - if stayerscore is not None: + if stayerscore is not None: # pragma: no cover plot.add_layout( Label(x=100,y=100,x_units='screen',y_units='screen', text='Stayer Score '+str(stayerscore)+'%', @@ -3805,7 +3805,7 @@ def interactive_cpchart(rower,thedistances,thesecs,theavpower, cpdata = dataprep.fetchcperg(rower, theworkouts) - if cpdata.empty: + if cpdata.empty: # pragma: no cover message = 'Calculations are running in the background. Please refresh this page to see updated results' return ['','',paulslope,paulintercept,p1,message,p1wc] @@ -3899,7 +3899,7 @@ def interactive_windchart(id=0,promember=0): hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) - if rowdata == 0: + if rowdata == 0: # pragma: no cover return 0 try: @@ -3907,7 +3907,7 @@ def interactive_windchart(id=0,promember=0): except KeyError: return ['','No Data Found'] - try: + try: # pragma: no cover vwind = rowdata.df.loc[:,'vwind'] winddirection = rowdata.df.loc[:,'winddirection'] bearing = rowdata.df.loc[:,'bearing'] @@ -3938,7 +3938,7 @@ def interactive_windchart(id=0,promember=0): # plot tools if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' @@ -3992,7 +3992,7 @@ def interactive_streamchart(id=0,promember=0): hrtr=r.tr,hran=r.an,ftp=r.ftp) rowdata = rdata(f1,rower=rr) - if rowdata == 0: + if rowdata == 0: # pragma: no cover return "","No Valid Data Available" try: @@ -4011,7 +4011,7 @@ def interactive_streamchart(id=0,promember=0): # plot tools if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' @@ -4059,12 +4059,12 @@ def interactive_chart(id=0,promember=0,intervaldata = {}): try: spm = datadf['spm'] - except KeyError: + except KeyError: # pragma: no cover datadf['spm'] = 0 try: pace = datadf['pace'] - except KeyError: + except KeyError: # pragma: no cover datadf['pace'] = 0 source = ColumnDataSource( @@ -4180,7 +4180,7 @@ def interactive_chart(id=0,promember=0,intervaldata = {}): def interactive_chart_video(videodata): try: spm = videodata['spm'] - except KeyError: + except KeyError: # pragma: no cover return "","No SPM data" time = range(len(spm)) @@ -4293,22 +4293,22 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', title=None,binsize=1,colorlegend=[], spmmin=0,spmmax=0,workmin=0,workmax=0): - if datadf.empty: + if datadf.empty: # pragma: no cover return ['','

No non-zero data in selection

'] - if xparam == 'workoutid': + if xparam == 'workoutid': # pragma: no cover xparamname = 'Workout' else: xparamname = axlabels[xparam] - if yparam == 'workoutid': + if yparam == 'workoutid': # pragma: no cover yparamname = 'Workout' else: yparamname = axlabels[yparam] - if groupby == 'workoutid': + if groupby == 'workoutid': # pragma: no cover groupname = 'Workout' - elif groupby == 'date': + elif groupby == 'date': # pragma: no cover groupname = 'Date' else: groupname = axlabels[groupby] @@ -4321,31 +4321,31 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', gr = groupname, ) - if xparam == 'cumdist': + if xparam == 'cumdist': # pragma: no cover res = make_cumvalues(datadf[xparam]) datadf[xparam] = res[0] - if xparam=='distance': + if xparam=='distance': # pragma: no cover xaxmax = datadf[xparam].max() xaxmin = datadf[xparam].min() - elif xparam=='time': + elif xparam=='time': # pragma: no cover tseconds = datadf.loc[:,'time'] xaxmax = tseconds.max() xaxmin = 0 - elif xparam == 'workoutid': + elif xparam == 'workoutid': # pragma: no cover xaxmax = datadf[xparam].max()-5 xaxmin = datadf[xparam].min()+5 else: xaxmax = yaxmaxima[xparam] xaxmin = yaxminima[xparam] - if yparam=='distance': + if yparam=='distance':# pragma: no cover yaxmax = datadf[yparam].max() yaxmin = datadf[yparam].min() - elif yparam=='time': + elif yparam=='time': # pragma: no cover tseconds = datadf.loc[:,'time'] yaxmax = tseconds.max() yaxmin = 0 - elif yparam == 'workoutid': + elif yparam == 'workoutid': # pragma: no cover yaxmax = datadf[yparam].max()-5 yaxmin = datadf[yparam].min()+5 else: @@ -4354,7 +4354,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', x_axis_type = 'linear' y_axis_type = 'linear' - if xparam == 'time': + if xparam == 'time': # pragma: no cover x_axis_type = 'datetime' if yparam == 'pace': y_axis_type = 'datetime' @@ -4375,7 +4375,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', (xparamname,'@x{1.1}'), (yparamname,'@y') ]) - else: + else: # pragma: no cover hover = HoverTool(names=['data'], tooltips = [ (groupby,'@groupval'), @@ -4465,12 +4465,12 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='', angle=90, angle_units='deg') - if xparam == 'workoutid': + if xparam == 'workoutid': # pragma: no cover plot.xaxis.axis_label = 'Workout' else: plot.xaxis.axis_label = axlabels[xparam] - if yparam == 'workoutid': + if yparam == 'workoutid': # pragma: no cover plot.xaxis.axis_label = 'Workout' else: plot.yaxis.axis_label = axlabels[yparam] @@ -4529,7 +4529,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, try: tests = datadf[yparam2] - except KeyError: + except KeyError: # pragma: no cover yparam2 = 'None' try: @@ -4563,19 +4563,19 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, # check if dataframe not empty - if datadf.empty: + if datadf.empty: # pragma: no cover return ['','

No non-zero data in selection

','',''] try: datadf['x1'] = datadf.loc[:,xparam] - except KeyError: + except KeyError: # pragma: no cover try: datadf['x1'] = datadf['distance'] except KeyError: try: datadf['x1'] = datadf['time'] - except KeyError: + except KeyError: # pragma: no cover return ['','

No non-zero data in selection

','',''] try: @@ -4583,18 +4583,18 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, except KeyError: try: datadf['y1'] = datadf['pace'] - except KeyError: + except KeyError: # pragma: no cover return ['','

No non-zero data in selection

','',''] if yparam2 != 'None': try: datadf['y2'] = datadf.loc[:,yparam2] - except KeyError: + except KeyError: # pragma: no cover datadf['y2'] = datadf['y1'] - else: + else: # pragma: no cover datadf['y2'] = datadf['y1'] - if xparam=='distance': + if xparam=='distance': # pragma: no cover xaxmax = datadf['x1'].max() xaxmin = datadf['x1'].min() else: @@ -4615,7 +4615,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, if xparam == 'time': x_axis_type = 'datetime' - if yparam1 == 'pace': + if yparam1 == 'pace': # pragma: no cover y_axis_type = 'datetime' y1mean = datadf.loc[:,'pace'].mean() @@ -4623,7 +4623,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, datadf['yname1'] = axlabels[yparam1] if yparam2 != 'None': datadf['yname2'] = axlabels[yparam2] - else: + else: # pragma: no cover datadf['yname2'] = axlabels[yparam1] @@ -4638,7 +4638,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, # Add hover to this comma-separated string and see what changes if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type, @@ -4725,7 +4725,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam]) plot.x_range = xrange1 - if yparam1 == 'pace': + if yparam1 == 'pace': # pragma: no cover plot.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] @@ -4880,7 +4880,7 @@ def interactive_cum_flex_chart2(theworkouts,promember=0, try: distmax = 100+100*int(datadf['distance'].max()/100.) - except KeyError: + except KeyError: # pragma: no cover distmax = 1000. slider_dist_min = Slider(width=140, start=0,end=distmax,value=0,step=50, @@ -4944,7 +4944,7 @@ def interactive_flexchart_stacked(id,r,xparam='time', workstrokesonly=False) - if r.usersmooth > 1: + if r.usersmooth > 1: # pragma: no cover for column in columns: try: if metricsdicts[column]['maysmooth']: @@ -4965,23 +4965,23 @@ def interactive_flexchart_stacked(id,r,xparam='time', try: tseconds = rowdata.loc[:,'time'] - except KeyError: + except KeyError: # pragma: no cover return '','No time data - cannot make flex plot','','',comment try: rowdata['x1'] = rowdata.loc[:,xparam] rowmin = rowdata[xparam].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['x1'] = 0*rowdata.loc[:,'time'] try: rowdata['y1'] = rowdata.loc[:,yparam1] rowmin = rowdata[yparam1].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['y1'] = 0*rowdata.loc[:,'time'] rowdata[yparam1] = rowdata['y1'] - try: + try: # pragma: no cover rowdata['y2'] = rowdata.loc[:,yparam2] rowmin = rowdata[yparam2].min() except KeyError: @@ -4991,24 +4991,24 @@ def interactive_flexchart_stacked(id,r,xparam='time', try: rowdata['y3'] = rowdata.loc[:,yparam3] rowmin = rowdata[yparam3].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['y3'] = 0*rowdata.loc[:,'time'] rowdata[yparam3] = rowdata['y3'] try: rowdata['y4'] = rowdata.loc[:,yparam4] rowmin = rowdata[yparam4].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['y4'] = 0*rowdata.loc[:,'time'] rowdata[yparam4] = rowdata['y4'] if xparam=='time': xaxmax = tseconds.max() xaxmin = tseconds.min() - elif xparam=='distance' or xparam=='cumdist': + elif xparam=='distance' or xparam=='cumdist': # pragma: no cover xaxmax = rowdata['x1'].max() xaxmin = rowdata['x1'].min() - else: + else: # pragma: no cover try: xaxmax = get_yaxmaxima(r,xparam,mode) xaxmin = get_yaxminima(r,xparam,mode) @@ -5025,41 +5025,41 @@ def interactive_flexchart_stacked(id,r,xparam='time', if xparam == 'time': x_axis_type = 'datetime' - if yparam1 == 'pace': + if yparam1 == 'pace': # pragma: no cover y1_axis_type = 'datetime' - if yparam2 == 'pace': + if yparam2 == 'pace': # pragma: no cover y2_axis_type = 'datetime' - if yparam3 == 'pace': + if yparam3 == 'pace': # pragma: no cover y3_axis_type = 'datetime' - if yparam4 == 'pace': + if yparam4 == 'pace': # pragma: no cover y4_axis_type = 'datetime' try: rowdata['xname'] = axlabels[xparam] - except KeyError: + except KeyError: # pragma: no cover rowdata['xname'] = xparam try: rowdata['yname1'] = axlabels[yparam1] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname1'] = yparam1 try: rowdata['yname2'] = axlabels[yparam2] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname2'] = yparam2 try: rowdata['yname3'] = axlabels[yparam3] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname3'] = yparam3 try: rowdata['yname4'] = axlabels[yparam4] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname4'] = yparam4 # prepare data @@ -5094,56 +5094,21 @@ def interactive_flexchart_stacked(id,r,xparam='time', plot3.add_tools(linked_crosshair) plot4.add_tools(linked_crosshair) - try: - xaxlabel = axlabels[xparam] - except KeyError: - xaxlabel = xparam - - try: - yax1label = axlabels[yparam1] - except KeyError: - yax1label = yparam1 + xaxlabel = axlabels.get(xparam,xparam) + yax1label = axlabels.get(yparam1,yparam1) plot1.yaxis.axis_label = yax1label - try: - xaxlabel = axlabels[xparam] - except KeyError: - xaxlabel = xparam - - try: - yax2label = axlabels[yparam2] - except KeyError: - yax2label = yparam2 + yax2label = axlabels.get(yparam2,yparam2) plot2.yaxis.axis_label = yax2label - try: - xaxlabel = axlabels[xparam] - except KeyError: - xaxlabel = xparam + yax3label = axlabels.get(yparam3,yparam3) - try: - yax3label = axlabels[yparam3] - except KeyError: - yax3label = yparam3 plot3.yaxis.axis_label = yax3label - try: - xaxlabel = axlabels[xparam] - except KeyError: - xaxlabel = xparam - - try: - yax4label = axlabels[yparam4] - except KeyError: - yax4label = yparam4 - - try: - xaxlabel = axlabels[xparam] - except KeyError: - xaxlabel = xparam + yax4label = axlabels.get(yparam4,yparam4) plot4.yaxis.axis_label = yax4label @@ -5173,49 +5138,49 @@ def interactive_flexchart_stacked(id,r,xparam='time', if yparam1 == 'pace': y1tooltip = '@fpace' - elif yparam1 != 'None': + elif yparam1 != 'None': # pragma: no cover y1tooltip = '@{yparam1}'.format(yparam1=yparam1) if metricsdicts[yparam1]['numtype'] == 'integer' or yparam1 == 'power': y1tooltip+='{int}' - else: + else: # pragma: no cover y1tooltip+='{0.00}' - else: + else: # pragma: no cover y1tooltip = '' comment = 'The metric in the first chart is only accessible with a Pro plan or higher' - if yparam2 == 'pace': + if yparam2 == 'pace': # pragma: no cover y2tooltip = '@fpace' elif yparam2 != 'None': y2tooltip = '@{yparam2}'.format(yparam2=yparam2) if metricsdicts[yparam2]['numtype'] == 'integer' or yparam2 == 'power': y2tooltip+='{int}' - else: + else: # pragma: no cover y2tooltip+='{0.00}' - else: + else: # pragma: no cover y2tooltip = '' comment = 'The metric in the second chart is only accessible with a Pro plan or higher' - if yparam3 == 'pace': + if yparam3 == 'pace': # pragma: no cover y3tooltip = '@fpace' elif yparam3 != 'None': y3tooltip = '@{yparam3}'.format(yparam3=yparam3) if metricsdicts[yparam3]['numtype'] == 'integer' or yparam3 == 'power': y3tooltip+='{int}' - else: + else: # pragma: no cover y3tooltip+='{0.00}' - else: + else: # pragma: no cover y3tooltip = '' comment = 'The metric in the third chart is only accessible with a Pro plan or higher' - if yparam4 == 'pace': + if yparam4 == 'pace': # pragma: no cover y4tooltip = '@fpace' elif yparam4 != 'None': y4tooltip = '@{yparam4}'.format(yparam4=yparam4) - if metricsdicts[yparam4]['numtype'] == 'integer' or yparam4 == 'power': + if metricsdicts[yparam4]['numtype'] == 'integer' or yparam4 == 'power': # pragma: no cover y4tooltip+='{int}' - else: + else: # pragma: no cover y4tooltip+='{0.00}' - else: + else: # pragma: no cover y4tooltip = '' comment = 'The metric in the fourth chart is only accessible with a Pro plan or higher' @@ -5285,7 +5250,7 @@ def interactive_flexchart_stacked(id,r,xparam='time', ) plot1.y_range = Range1d(y1min,y1max) - if yparam2 == 'pace': + if yparam2 == 'pace': # pragma: no cover plot2.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] @@ -5293,14 +5258,14 @@ def interactive_flexchart_stacked(id,r,xparam='time', plot2.y_range = Range1d(y2min,y2max) - if yparam3 == 'pace': + if yparam3 == 'pace': # pragma: no cover plot3.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] ) plot3.y_range = Range1d(y3min,y3max) - if yparam4 == 'pace': + if yparam4 == 'pace': # pragma: no cover plot4.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] @@ -5359,7 +5324,7 @@ def interactive_flex_chart2(id,r,promember=0, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, workstrokesonly=workstrokesonly) - if r.usersmooth > 1: + if r.usersmooth > 1: # pragma: no cover for column in columns: try: if metricsdicts[column]['maysmooth']: @@ -5382,14 +5347,14 @@ def interactive_flex_chart2(id,r,promember=0, workstrokesonly=False try: tests = rowdata[yparam2] - except KeyError: + except KeyError: # pragma: no cover yparam2 = 'None' try: tests = rowdata[yparam1] - except KeyError: + except KeyError: # pragma: no cover yparam1 = 'None' @@ -5421,7 +5386,7 @@ def interactive_flex_chart2(id,r,promember=0, workoutstatesrest = [3] workoutstatetransition = [0,2,10,11,12,13] - if workstrokesonly: + if workstrokesonly: # pragma: no cover try: rowdata = rowdata[~rowdata['workoutstate'].isin(workoutstatesrest)] except KeyError: @@ -5429,20 +5394,20 @@ def interactive_flex_chart2(id,r,promember=0, try: tseconds = rowdata.loc[:,'time'] - except KeyError: + except KeyError: # pragma: no cover return '','No time data - cannot make flex plot','','',workstrokesonly try: rowdata['x1'] = rowdata.loc[:,xparam] rowmin = rowdata[xparam].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['x1'] = 0*rowdata.loc[:,'time'] try: rowdata['y1'] = rowdata.loc[:,yparam1] rowmin = rowdata[yparam1].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['y1'] = 0*rowdata.loc[:,'time'] rowdata[yparam1] = rowdata['y1'] @@ -5450,10 +5415,10 @@ def interactive_flex_chart2(id,r,promember=0, try: rowdata['y2'] = rowdata.loc[:,yparam2] rowmin = rowdata[yparam2].min() - except KeyError: + except KeyError: # pragma: no cover rowdata['y2'] = 0*rowdata.loc[:,'time'] rowdata[yparam2] = rowdata['y2'] - else: + else: # pragma: no cover rowdata['y2'] = rowdata['y1'] if xparam=='time': @@ -5462,7 +5427,7 @@ def interactive_flex_chart2(id,r,promember=0, elif xparam=='distance' or xparam=='cumdist': xaxmax = rowdata['x1'].max() xaxmin = rowdata['x1'].min() - else: + else: # pragma: no cover try: xaxmax = get_yaxmaxima(r,xparam,mode) xaxmin = get_yaxminima(r,xparam,mode) @@ -5474,9 +5439,9 @@ def interactive_flex_chart2(id,r,promember=0, if xparam != 'time': try: x1mean = rowdata['x1'].mean() - except TypeError: + except TypeError: # pragma: no cover x1mean = 0 - else: + else: # pragma: no cover x1mean = 0 y1mean = rowdata['y1'].mean() @@ -5489,7 +5454,7 @@ def interactive_flex_chart2(id,r,promember=0, # constant power plot if yparam1 == 'driveenergy': - if xparam == 'spm': + if xparam == 'spm': # pragma: no cover yconstantpower = rowdata['y1'].mean()*rowdata['x1'].mean()/xvals x_axis_type = 'linear' @@ -5501,23 +5466,23 @@ def interactive_flex_chart2(id,r,promember=0, y_axis_type = 'datetime' try: y1mean = rowdata.loc[:,'pace'].mean() - except KeyError: + except KeyError: # pragma: no cover y1mean = 0 try: rowdata['xname'] = axlabels[xparam] - except KeyError: + except KeyError: # pragma: no cover rowdata['xname'] = xparam try: rowdata['yname1'] = axlabels[yparam1] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname1'] = yparam1 if yparam2 != 'None': try: rowdata['yname2'] = axlabels[yparam2] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname2'] = yparam2 - else: + else: # pragma: no cover rowdata['yname2'] = rowdata['yname1'] @@ -5587,7 +5552,7 @@ def interactive_flex_chart2(id,r,promember=0, xlabeltext = axlabels[xparam]+": {x1mean:6.2f}".format( x1mean=x1mean ) - except KeyError: + except KeyError: # pragma: no cover xlabeltext = xparam+": {x1mean:6.2f}".format(x1mean=x1mean) xlabel = Label(x=50,y=80,x_units='screen',y_units='screen', @@ -5612,7 +5577,7 @@ def interactive_flex_chart2(id,r,promember=0, ) - if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): + if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): # pragma: no cover plot.add_layout(x1means) plot.add_layout(xlabel) @@ -5623,12 +5588,12 @@ def interactive_flex_chart2(id,r,promember=0, try: yaxlabel = axlabels[yparam1] - except KeyError: + except KeyError: # pragma: no cover yaxlabel = str(yparam1)+' ' try: xaxlabel = axlabels[xparam] - except KeyError: + except KeyError: # pragma: no cover xaxlabel = xparam y1label = Label(x=50,y=50,x_units='screen',y_units='screen', @@ -5637,18 +5602,18 @@ def interactive_flex_chart2(id,r,promember=0, background_fill_color='white', text_color='blue', ) - if yparam1 != 'time' and yparam1 != 'pace': + if yparam1 != 'time' and yparam1 != 'pace': # pragma: no cover plot.add_layout(y1label) y2label = y1label # average values - if yparam1 == 'driveenergy': + if yparam1 == 'driveenergy': # pragma: no cover if xparam == 'spm': plot.line(xvals,yconstantpower,color="green",legend_label="Constant Power") if plottype=='line': plot.line('x1','y1',source=source2,legend_label=yaxlabel) - elif plottype=='scatter': + elif plottype=='scatter': # pragma: no cover plot.scatter('x1','y1',source=source2,legend_label=yaxlabel,fill_alpha=0.4, line_color=None) @@ -5665,13 +5630,13 @@ def interactive_flex_chart2(id,r,promember=0, try: yrange1 = Range1d(start=get_yaxminima(r,yparam1,mode), end=get_yaxmaxima(r,yparam1,mode)) - except KeyError: + except KeyError: # pragma: no cover yrange1 = Range1d(start=rowdata[yparam1].min(), end=rowdata[yparam1].max()) plot.y_range = yrange1 - if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): + if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): # pragma: no cover try: xrange1 = Range1d(start=get_yaxminima(r,xparam,mode), end=get_yaxmaxima(r,xparam,mode)) @@ -5705,7 +5670,7 @@ def interactive_flex_chart2(id,r,promember=0, try: yrange2 = Range1d(start=get_yaxminima(r,yparam2,mode), end=get_yaxmaxima(r,yparam2,mode)) - except KeyError: + except KeyError: # pragma: no cover yrange2 = Range1d(start=rowdata[yparam2].min(), end=rowdata[yparam2].max()) @@ -5713,7 +5678,7 @@ def interactive_flex_chart2(id,r,promember=0, #= {"yax2": yrange2} try: axlegend = axlabels[yparam2] - except KeyError: + except KeyError: # pragma: no cover axlegend = str(yparam2)+' ' if plottype=='line': @@ -5721,7 +5686,7 @@ def interactive_flex_chart2(id,r,promember=0, legend_label=axlegend, source=source2) - elif plottype=='scatter': + elif plottype=='scatter': # pragma: no cover plot.scatter('x1','y2',source=source2,legend_label=axlegend, fill_alpha=0.4, line_color=None,color="red",y_range_name="yax2") @@ -5908,7 +5873,7 @@ def interactive_flex_chart2(id,r,promember=0, try: distmax = 100+100*int(rowdata['distance'].max()/100.) - except (KeyError,ValueError): + except (KeyError,ValueError): # pragma: no cover distmax = 100 slider_dist_min = Slider(width=140, start=0,end=distmax,value=0,step=50, @@ -5970,7 +5935,7 @@ def thumbnails_set(r,id,favorites): try: rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=False, workstrokesonly=False) - except: + except: # pragma: no cover return [ {'script':"", 'div':"", @@ -5997,7 +5962,7 @@ def thumbnails_set(r,id,favorites): bins = np.linspace(rowdata['time'].min(),rowdata['time'].max(),maxlength) groups = rowdata.groupby(np.digitize(rowdata['time'],bins)) rowdata = groups.mean() - except KeyError: + except KeyError: # pragma: no cover pass for f in favorites: @@ -6042,24 +6007,24 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, try: tseconds = rowdata.loc[:,'time'] - except KeyError: + except KeyError: # pragma: no cover return '','No time data - cannot make flex plot' try: rowdata['x1'] = rowdata.loc[:,xparam] - except KeyError: + except KeyError: # pragma: no cover rowdata['x1'] = 0*rowdata.loc[:,'time'] try: rowdata['y1'] = rowdata.loc[:,yparam1] - except KeyError: + except KeyError: # pragma: no cover rowdata['y1'] = 0*rowdata.loc[:,'time'] if yparam2 != 'None': try: rowdata['y2'] = rowdata.loc[:,yparam2] - except KeyError: + except KeyError: # pragma: no cover rowdata['y2'] = 0*rowdata.loc[:,'time'] else: rowdata['y2'] = rowdata['y1'] @@ -6067,7 +6032,7 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, if xparam=='time': xaxmax = tseconds.max() xaxmin = tseconds.min() - elif xparam=='distance' or xparam=='cumdist': + elif xparam=='distance' or xparam=='cumdist': # pragma: no cover xaxmax = rowdata['x1'].max() xaxmin = rowdata['x1'].min() else: @@ -6079,7 +6044,7 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, if xparam == 'time': x_axis_type = 'datetime' - if yparam1 == 'pace': + if yparam1 == 'pace': # pragma: no cover y_axis_type = 'datetime' y1mean = rowdata.loc[:,'pace'].mean() @@ -6087,7 +6052,7 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, rowdata['xname'] = axlabels[xparam] try: rowdata['yname1'] = axlabels[yparam1] - except KeyError: + except KeyError: # pragma: no cover rowdata['yname1'] = axlabels[xparam] if yparam2 != 'None': rowdata['yname2'] = axlabels[yparam2] @@ -6126,17 +6091,17 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, try: plot.xaxis.axis_label = axlabels[xparam] - except KeyError: + except KeyError: # pragma: no cover plot.xaxis.axis_label = 'X' try: plot.yaxis.axis_label = axlabels[yparam1] - except KeyError: + except KeyError: # pragma: no cover plot.yaxis.axis_label = 'Y' try: yrange1 = Range1d(start=yaxminima[yparam1],end=yaxmaxima[yparam1]) - except KeyError: + except KeyError: # pragma: no cover yrange1 = Range1d(start=yparam1.min(), end=yparam1.max()) plot.y_range = yrange1 @@ -6158,7 +6123,7 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, ) - if yparam1 == 'pace': + if yparam1 == 'pace': # pragma: no cover plot.yaxis[0].formatter = DatetimeTickFormatter( seconds = ["%S"], minutes = ["%M"] @@ -6174,7 +6139,7 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, plot.line('x1','y2',color="red",y_range_name="yax2", source=source) - elif plottype=='scatter': + elif plottype=='scatter': # pragma: no cover plot.scatter('x1','y2',source=source, fill_alpha=0.4, line_color=None,color="red",y_range_name="yax2") @@ -6191,128 +6156,6 @@ def thumbnail_flex_chart(rowdata,id=0,promember=0, return [script,div] - -def interactive_bar_chart(id=0,promember=0): - # check if valid ID exists (workout exists) - rowdata,row = dataprep.getrowdata_db(id=id) - rowdata.dropna(axis=1,how='all',inplace=True) - rowdata.dropna(axis=0,how='any',inplace=True) - - if rowdata.empty: - return "","No Valid Data Available" - - # Add hover to this comma-separated string and see what changes - if (promember==1): - TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' - else: - TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' - - source = ColumnDataSource( - rowdata - ) - - plot = Figure(x_axis_type="datetime",y_axis_type="datetime", - toolbar_sticky=False, - plot_width=920, - tools=TOOLS) - - # add watermark - watermarkurl = "/static/img/logo7.png" - watermarksource = ColumnDataSource(dict( - url = [watermarkurl],)) - - watermarkrange = Range1d(start=0,end=1) - watermarkalpha = 0.6 - watermarkx = 0.99 - watermarky = 0.01 - watermarkw = 184 - watermarkh = 35 - watermarkanchor = 'bottom_right' - plot.extra_y_ranges = {"watermark": watermarkrange} - plot.extra_x_ranges = {"watermark": watermarkrange} - plot.sizing_mode = 'stretch_both' - - plot.image_url([watermarkurl],0.01,0.99, - watermarkw,watermarkh, - global_alpha=watermarkalpha, - w_units='screen', - h_units='screen', - anchor='top_left', - dilate=True, - x_range_name = "watermark", - y_range_name = "watermark", - ) - - plot.title.text = row.name - plot.title.text_font_size=value("1.0em") - plot.xaxis.axis_label = "Time" - plot.yaxis.axis_label = "Pace (/500m)" - plot.xaxis[0].formatter = DatetimeTickFormatter( - hours ="", - minutes = ["%M"], - seconds = ["%S"], - days = ["0"], - months = [""], - years = [""] - ) - - plot.yaxis[0].formatter = DatetimeTickFormatter( - hours = "", - seconds = ["%S"], - minutes = ["%M"], - ) - ymax = 1.0e3*90 - ymin = 1.0e3*180 - - if row.workouttype == 'water': - ymax = 1.0e3*90 - ymin = 1.0e3*210 - - plot.y_range = Range1d(ymin,ymax) - - - hover = plot.select(dict(type=HoverTool)) - - - hover.tooltips = OrderedDict([ - ('Time','@ftime'), - ('Pace','@fpace'), - ('HR','@hr{int}'), - ('SPM','@spm{1.1}'), - ]) - - hover.mode = 'mouse' - - plot.extra_y_ranges["hr"] = Range1d(start=100,end=200) - plot.quad(left='time',top='hr_ut2',bottom='hr_bottom', - right='x_right',source=source,color="gray", - y_range_name="hr", legend_label=" 0] # check if dataframe not empty - if datadf.empty: + if datadf.empty: # pragma: no cover return ['','

No non-zero data in selection

','','No non-zero data in selection'] - if xparam != 'distance' and xparam != 'time' and xparam != 'cumdist': + if xparam != 'distance' and xparam != 'time' and xparam != 'cumdist': # pragma: no cover xaxmax = yaxmaxima[xparam] xaxmin = yaxminima[xparam] elif xparam == 'time' and not startenddict: xaxmax = tseconds.max() xaxmin = tseconds.min() - elif xparam == 'time' and startenddict: + elif xparam == 'time' and startenddict: # pragma: no cover deltas = [pair[1]-pair[0] for key,pair in startenddict.items()] xaxmin = 0 xaxmax = pd.Series(deltas).max()*1000. @@ -6373,10 +6216,10 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', xaxmax = datadf['distance'].max() xaxmin = datadf['distance'].min() - if yparam == 'distance': + if yparam == 'distance': # pragma: no cover yaxmin = datadf['distance'].min() yaxmax = datadf['distance'].max() - elif yparam == 'cumdist': + elif yparam == 'cumdist': # pragma: no cover yaxmin = datadf['cumdist'].min() yaxmax = datadf['cumdist'].max() else: @@ -6389,7 +6232,7 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', # Add hover to this comma-separated string and see what changes if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,crosshair' if yparam == 'pace': @@ -6476,7 +6319,7 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', try: group['x'] = group[xparam] - except KeyError: + except KeyError: # pragma: no cover group['x'] = group['time'] errormessage = xparam+' has no values. Plot invalid' try: @@ -6495,7 +6338,7 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', if windowsize > 3 and windowsize < len(group['y']): try: group['y'] = savgol_filter(group['y'],windowsize,3) - except ValueError: + except ValueError: # pragma: no cover pass ylabel = Label(x=100,y=60+nrworkouts*20-20*cntr, @@ -6526,9 +6369,9 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', if labeldict: try: legend_label=labeldict[id] - except KeyError: + except KeyError: # pragma: no cover legend = str(id) - else: + else: # pragma: no cover legend_label=str(id) if plottype=='line': @@ -6544,7 +6387,7 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line', plot.xaxis.axis_label = axlabels[xparam] plot.yaxis.axis_label = axlabels[yparam] - if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): + if (xparam != 'time') and (xparam != 'distance') and (xparam != 'cumdist'): # pragma: no cover xrange1 = Range1d(start=yaxminima[xparam],end=yaxmaxima[xparam]) plot.x_range = xrange1 @@ -6589,7 +6432,7 @@ def interactive_otw_advanced_pace_chart(id=0,promember=0): # Add hover to this comma-separated string and see what changes if (promember==1): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' - else: + else: # pragma: no cover TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' source = ColumnDataSource( @@ -6673,7 +6516,7 @@ def interactive_otw_advanced_pace_chart(id=0,promember=0): try: script, div = components(plot) - except: + except: # pragma: no cover script = '' div = '' diff --git a/rowers/tests/test_emails.py b/rowers/tests/test_emails.py index 916fb50e..8b8bf8ca 100644 --- a/rowers/tests/test_emails.py +++ b/rowers/tests/test_emails.py @@ -575,10 +575,7 @@ race 1 self.assertIn('Successfully processed email attachments',out.getvalue()) ws = Workout.objects.filter(name="johnsworkout") - if not len(ws): - for w in Workout.objects.all(): - print(w) - + self.assertEqual(len(ws),1) w = ws[0] diff --git a/rowers/tests/test_interactivecharts.py b/rowers/tests/test_interactivecharts.py index 522b716d..319f901d 100644 --- a/rowers/tests/test_interactivecharts.py +++ b/rowers/tests/test_interactivecharts.py @@ -63,15 +63,6 @@ class InteractiveChartTest(TestCase): mocked_getsmallrowdata_db): res = iplots.interactive_chart(self.wote.id,promember=1) - @patch('rowers.dataprep.create_engine') - @patch('rowers.dataprep.read_df_sql') - def test_interactive_chart3(self, mocked_sqlalchemy,mocked_read_df_sql): - res = iplots.interactive_bar_chart(self.wote.id) - - @patch('rowers.dataprep.create_engine') - @patch('rowers.dataprep.read_df_sql') - def test_interactive_chart4(self, mocked_sqlalchemy,mocked_read_df_sql): - res = iplots.interactive_bar_chart(self.wote.id,promember=1) @patch('rowers.dataprep.create_engine') @patch('rowers.dataprep.read_df_sql') diff --git a/rowers/tests/test_permissions2.py b/rowers/tests/test_permissions2.py index 8d193337..fee5d5e7 100644 --- a/rowers/tests/test_permissions2.py +++ b/rowers/tests/test_permissions2.py @@ -234,10 +234,6 @@ class PermissionsViewTests(TestCase): mocked_get_video_data, ): - print() - print(view,'anonymous',permissions['anonymous'],permissions['is_staff'],permissions['dotest']) - print() - if permissions['anonymous'] and not permissions['is_staff'] and permissions['dotest']: urlstotest = [] if permissions['workoutid']: @@ -247,8 +243,6 @@ class PermissionsViewTests(TestCase): url = reverse(view) urlstotest.append(url) - print(view,'anonymous',urlstotest) - for url in urlstotest: result = self.c.get(url) self.assertEqual(result.status_code,permissions['anonymous_response']) @@ -275,10 +269,6 @@ class PermissionsViewTests(TestCase): mocked_get_video_data, ): - print() - print(view,'own') - print() - if permissions['own'] in plans and not permissions['is_staff'] and permissions['dotest']: urlstotest = [] falseurlstotest = [] @@ -288,8 +278,6 @@ class PermissionsViewTests(TestCase): memberuser = self.uplan notuser = None - print(view,'own') - if permissions['own'] == 'basic': thisuser = self.ubasic memberuser = self.uplan @@ -323,8 +311,6 @@ class PermissionsViewTests(TestCase): url = reverse(view) urlstotest.append(url) - print(view,'own',urlstotest,falseurlstotest,otheruserurls) - # test logged in as user who has permissions for url in urlstotest: login = self.c.login(username = thisuser['username'],password = thisuser['password']) @@ -365,10 +351,6 @@ class PermissionsViewTests(TestCase): mocked_get_video_data, ): - print() - print(view,'member') - print() - if permissions['member'] in plans and permissions['is_staff'] is False and permissions['dotest']: urlstotest = [] falseurlstotest = [] @@ -378,8 +360,6 @@ class PermissionsViewTests(TestCase): memberuser = self.uplan notuser = None - print(view,'member') - if permissions['member'] == 'basic': thisuser = self.ubasic memberuser = self.uplan @@ -414,8 +394,6 @@ class PermissionsViewTests(TestCase): url = reverse(view) urlstotest.append(url) - print('member',urlstotest,falseurlstotest,otheruserurls) - # test logged in as user who has permissions for url in urlstotest: login = self.c.login(username = thisuser['username'],password = thisuser['password']) @@ -456,10 +434,6 @@ class PermissionsViewTests(TestCase): mocked_get_video_data, ): - print() - print(view,'coachee') - print() - if permissions['coachee'] in plans and not permissions['is_staff'] and permissions['dotest']: urlstotest = [] falseurlstotest = [] @@ -486,8 +460,6 @@ class PermissionsViewTests(TestCase): url = reverse(view) urlstotest.append(url) - print('coachee',urlstotest,falseurlstotest,otheruserurls) - # test logged in as user who has permissions for url in urlstotest: login = self.c.login(username = thisuser['username'],password = thisuser['password']) diff --git a/rowers/tests/test_plans.py b/rowers/tests/test_plans.py index 270b50a3..a961e0bb 100644 --- a/rowers/tests/test_plans.py +++ b/rowers/tests/test_plans.py @@ -83,6 +83,10 @@ class TrainingPlanTest(TestCase): response = self.c.get(urlplan) self.assertEqual(response.status_code,200) + url = reverse('rower_trainingplan_execution_view',kwargs={'id':1}) + response = self.c.get(url) + self.assertEqual(response.status_code,200) + html = BeautifulSoup(response.content,'html.parser') urls = [a['href'] for a in html.find_all('a')] diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 683ebb1a..a5ad0253 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -1951,7 +1951,7 @@ def workouts_view(request,message='',successmessage='', if request.method == 'POST': dateform = DateRangeForm(request.POST) searchform = SearchForm(request.POST) - if dateform.is_valid(): + if dateform.is_valid(): # pragma: no cover startdate = dateform.cleaned_data['startdate'] enddate = dateform.cleaned_data['enddate'] if searchform.is_valid(): @@ -1986,7 +1986,7 @@ def workouts_view(request,message='',successmessage='', activity_enddate = activity_enddate.replace(hour=23,minute=59,second=59).astimezone(usertimezone) activity_startdate = activity_enddate-datetime.timedelta(days=15) activity_startdate = activity_startdate.replace(hour=0,minute=0,second=0) - else: + else: # pragma: no cover activity_enddate = enddate except (ValueError, AttributeError): # pragma: no cover activity_enddate = enddate @@ -2064,7 +2064,7 @@ def workouts_view(request,message='',successmessage='', workouts = workouts.exclude(rankingpiece=False) workoutsnohr = workouts.exclude(averagehr__isnull=False) - for w in workoutsnohr: + for w in workoutsnohr: # pragma: no cover res = dataprep.workout_trimp(w) # ids = [w.id for w in workouts]