From f984d25f6a1edfca40e68247c8a4734414b1dcb3 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 18 Feb 2022 18:49:33 +0100 Subject: [PATCH] more pep --- rowers/interactiveplots.py | 112 ++--------------------------------- rowers/views/workoutviews.py | 3 +- 2 files changed, 5 insertions(+), 110 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 6f6ee740..69ed2ff7 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -9,7 +9,6 @@ from rowers.models import course_spline, VirtualRaceResult from bokeh.palettes import Category20c, Category10 from bokeh.layouts import layout, widgetbox from bokeh.resources import CDN, INLINE -from math import pi from rowers.dataprep import timedeltaconv from pandas.core.groupby.groupby import DataError import rowers.datautils as datautils @@ -41,8 +40,7 @@ from bokeh.core.properties import value from rowers.opaque import encoder from bokeh.models import ( OpenURL, TapTool, CrosshairTool, Span, Label, SaveTool, - PanTool, BoxZoomTool, WheelZoomTool, ResetTool, - ) + PanTool, BoxZoomTool, WheelZoomTool, ResetTool,) from bokeh.models.glyphs import ImageURL from bokeh.transform import cumsum from bokeh.models import ( @@ -82,9 +80,6 @@ queue = django_rq.get_queue('default') queuelow = django_rq.get_queue('low') queuehigh = django_rq.get_queue('low') -#from bokeh.io import output_file, show, vplot -#from bokeh.models.widgets import Slider, Select, TextInput - activate(settings.TIME_ZONE) thetimezone = get_current_timezone() @@ -132,7 +127,6 @@ def errorbar(fig, x, y, source=ColumnDataSource(), colorvalues = ["#%02x%02x%02x" % (255, 0, 0) for x in xvalues] try: - a = xvalues[0]+1 if xerr: x_err_x = [] x_err_y = [] @@ -155,7 +149,6 @@ def errorbar(fig, x, y, source=ColumnDataSource(), pass try: - a = yvalues[0]+1 if yerr: y_err_x = [] y_err_y = [] @@ -254,7 +247,6 @@ def interactive_hr_piechart(df, rower, title, totalseconds=0): data['totaltime'] = pd.Series([pretty_timedelta(v) for v in data['value']]) - size = 350 TOOLS = 'save,hover' z = figure(title="HR "+title, x_range=(-0.5, 1), plot_height=375, @@ -345,10 +337,10 @@ def interactive_boxchart(datadf, fieldname, extratitle='', columns = datadf.columns - if not fieldname in columns: # pragma: no cover + if fieldname not in columns: # pragma: no cover return '', 'It looks like there are no data matching your filter' - if not 'date' in columns: # pragma: no cover + if 'date' not in columns: # pragma: no cover return '', 'Not enough data' tooltips = [ @@ -411,8 +403,6 @@ def interactive_boxchart(datadf, fieldname, extratitle='', def interactive_planchart(data, startdate, enddate): - source = ColumnDataSource(data) - hv.extension('bokeh') yaxmaximum = data['executed'].max() @@ -565,14 +555,9 @@ def interactive_activitychart(workouts, startdate, enddate, stack='type', toolba 'link': links, } - dim_expr = hv.dim('type').categorize(mytypes.color_map) - df = pd.DataFrame(thedict) - source = ColumnDataSource(df) - df.sort_values('date_sorting', inplace=True) - #clrs = hv.Cycle(df['colors'].values) hv.extension('bokeh') @@ -608,7 +593,6 @@ def interactive_activitychart(workouts, startdate, enddate, stack='type', toolba p.toolbar_location = toolbar_location p.y_range.start = 0 p.sizing_mode = 'stretch_both' - url = "http://rowsandall.com/rowers/workout/@duration/" taptool = p.select(type=TapTool) callback = CustomJS(args={'links': df.link}, code=""" @@ -749,8 +733,6 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb 'link': links, } - dim_expr = hv.dim('type').categorize(mytypes.color_map) - df = pd.DataFrame(thedict) if totaldays > 30 and yaxis == 'duration': # pragma: no cover @@ -772,9 +754,6 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb df.sort_values('date_sorting', inplace=True) - #clrs = hv.Cycle(df['colors'].values) - source = ColumnDataSource(df) - hv.extension('bokeh') # table = hv.Table(df,[('date','Date'),('type','Workout Type')], @@ -815,7 +794,6 @@ def interactive_activitychart2(workouts, startdate, enddate, stack='type', toolb p.toolbar_location = toolbar_location p.sizing_mode = 'stretch_both' p.y_range.start = 0 - url = "http://rowsandall.com/rowers/workout/@duration/" taptool = p.select(type=TapTool) callback = CustomJS(args={'links': df['link']}, code=""" @@ -849,9 +827,7 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' rowdata.dropna(axis=1, how='all', inplace=True) rowdata.dropna(axis=0, how='any', inplace=True) - workoutstateswork = [1, 4, 5, 8, 9, 6, 7] workoutstatesrest = [3] - workoutstatetransition = [0, 2, 10, 11, 12, 13] if workstrokesonly: try: @@ -862,15 +838,6 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' if rowdata.empty: return "", "No Valid Data Available", "", "" - # quick linear regression - # peakforce = slope*peakforceangle + intercept - try: - slope, intercept, r, p, stderr = linregress( - rowdata['peakforceangle'], rowdata['peakforce']) - except KeyError: # pragma: no cover - slope = 0 - intercept = 0 - try: covariancematrix = np.cov( rowdata['peakforceangle'], y=rowdata['peakforce']) @@ -997,16 +964,8 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' try: peakforceav = rowdata['peakforce'].median() - peakforce25 = rowdata['peakforce'].quantile(q=0.25) - peakforce75 = rowdata['peakforce'].quantile(q=0.75) - peakforce05 = rowdata['peakforce'].quantile(q=0.05) - peakforce95 = rowdata['peakforce'].quantile(q=0.95) except KeyError: # pragma: no cover peakforceav = 0 - peakforce25 = 0 - peakforce75 = 0 - peakforce05 = 0 - peakforce95 = 0 try: averageforceav = rowdata['averageforce'].median() @@ -1015,16 +974,8 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' try: peakforceangleav = rowdata['peakforceangle'].median() - peakforceangle05 = rowdata['peakforceangle'].quantile(q=0.05) - peakforceangle25 = rowdata['peakforceangle'].quantile(q=0.25) - peakforceangle75 = rowdata['peakforceangle'].quantile(q=0.75) - peakforceangle95 = rowdata['peakforceangle'].quantile(q=0.95) except KeyError: # pragma: no cover peakforceangleav = 0 - peakforceangle25 = 0 - peakforceangle75 = 0 - peakforceangle05 = 0 - peakforceangle95 = 0 # thresholdforce /= 4.45 # N to lbs thresholdforce = 100 if 'x' in boattype else 200 @@ -1095,20 +1046,6 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' ) ) - sourcetrend = ColumnDataSource( - data=dict( - x=[peakforceangle25, peakforceangle75], - y=[peakforce25, peakforce75] - ) - ) - - sourcefit = ColumnDataSource( - data=dict( - x=np.array([peakforceangle25, peakforceangle75]), - y=slope*np.array([peakforceangle25, peakforceangle75])+intercept - ) - ) - source2 = ColumnDataSource( rowdata ) @@ -1150,8 +1087,6 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' # add watermark watermarkurl = "/static/img/logo7.png" - watermarksource = ColumnDataSource(dict( - url=[watermarkurl],)) watermarkrange = Range1d(start=0, end=1) watermarkalpha = 0.6 @@ -1524,14 +1459,6 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' slider_dist_max.js_on_change('value', callback) callback.args["maxdist"] = slider_dist_max - #annotation.sizing_mode = 'fixed' - #slider_spm_min.sizing_mode = 'fixed' - #slider_spm_max.sizing_mode = 'fixed' - #slider_work_min.sizing_mode = 'fixed' - #slider_work_max.sizing_mode = 'fixed' - #slider_dist_min.sizing_mode = 'fixed' - #slider_dist_max.sizing_mode = 'fixed' - thesliders = layoutcolumn([annotation, slider_spm_min, slider_spm_max, @@ -1541,10 +1468,8 @@ def interactive_forcecurve(theworkouts, workstrokesonly=True, plottype='scatter' slider_work_max, ] ) - #thesliders.sizing_mode = 'fixed' - mylayout = layoutrow([thesliders, - plot]) + mylayout = layoutrow([thesliders, plot]) mylayout.sizing_mode = 'stretch_both' @@ -1658,12 +1583,9 @@ def goldmedalscorechart(user, startdate=None, enddate=None): duration = [] workoutid = [] - previous = 0 - for i in range(len(dates)): id = ids[i] w = Workout.objects.get(id=id) - dd = str(dates[i]) # td.append(arrow.get(dd).datetime) td.append(arrow.get(w.date).datetime) markerscore.append(testpower[i]) @@ -1729,9 +1651,6 @@ def goldmedalscorechart(user, startdate=None, enddate=None): # add watermark watermarkurl = "/static/img/logo7.png" - watermarksource = ColumnDataSource(dict( - url=[watermarkurl],)) - watermarkrange = Range1d(start=0, end=1) watermarkalpha = 0.6 watermarkx = 0.99 @@ -1892,9 +1811,6 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue= # add watermark watermarkurl = "/static/img/logo7.png" - watermarksource = ColumnDataSource(dict( - url=[watermarkurl],)) - watermarkrange = Range1d(start=0, end=1) watermarkalpha = 0.6 watermarkx = 0.99 @@ -1951,10 +1867,8 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue= # y1rangemin = df.loc[:,['testpower','fitness']].min().min() # y1rangemax = df.loc[:,['testpower','fitness']].max().max()*1.02 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: # pragma: no cover @@ -1979,7 +1893,6 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue= plot.sizing_mode = 'scale_both' - #plot.y_range = Range1d(0,1.5*max(df['testpower'])) startdate = datetime.datetime.combine( startdate, datetime.datetime.min.time()) enddate = datetime.datetime.combine(enddate, datetime.datetime.min.time()) @@ -2102,9 +2015,6 @@ def interactive_histoall(theworkouts, histoparam, includereststrokes, # add watermark watermarkurl = "/static/img/logo7.png" - watermarksource = ColumnDataSource(dict( - url=[watermarkurl],)) - watermarkrange = Range1d(start=0, end=1) watermarkalpha = 0.6 watermarkx = 0.99 @@ -2514,10 +2424,6 @@ def get_map_script_course( """.format( latmean=latmean, lonmean=lonmean, - latbegin=latbegin, - latend=latend, - longbegin=longbegin, - longend=longend, scoordinates=scoordinates, pcoordinates=pcoordinates, plabels=plabels @@ -2778,11 +2684,6 @@ def leaflet_chart_compare(course, workoutids, labeldict={}, startenddict={}): if lat.empty or lon.empty: # pragma: no cover return [0, "invalid coordinate data"] - latbegin = lat.values[0] - longbegin = lon.values[0] - latend = lat.values[-1] - longend = lon.values[-1] - colors = itertools.cycle(palette) try: items = itertools.izip(workoutids, colors) @@ -2869,10 +2770,6 @@ var navionics = new JNC.Leaflet.NavionicsOverlay({{ """.format( latmean=latmean, lonmean=lonmean, - latbegin=latbegin, - latend=latend, - longbegin=longbegin, - longend=longend, pcoordinates=pcoordinates, plabels=plabels, ) @@ -2926,7 +2823,6 @@ var navionics = new JNC.Leaflet.NavionicsOverlay({{ scoordinates=scoordinates, color=color, label=label, - id=id, ) script += """ diff --git a/rowers/views/workoutviews.py b/rowers/views/workoutviews.py index 3922a2fe..2cc2cb83 100644 --- a/rowers/views/workoutviews.py +++ b/rowers/views/workoutviews.py @@ -3736,8 +3736,7 @@ def workout_flexchart3_view(request, *args, **kwargs): 'yaxis1': yparam1, 'yaxis2': yparam2, } - flexaxesform = FlexAxesForm(request, initial=initial, - extrametrics=extrametrics) + flexaxesform = FlexAxesForm(request, initial=initial) initial = { 'includereststrokes': not workstrokesonly,