From 02c998af3e54cb7e4618b62749e4abd91f6cd14b Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Mon, 25 Mar 2024 19:57:57 +0100 Subject: [PATCH] removing obsolete code --- rowers/interactiveplots.py | 177 +++-------------------- rowers/templates/performancemanager.html | 34 +++-- 2 files changed, 39 insertions(+), 172 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 8555400e..c83f0f88 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1797,174 +1797,37 @@ def performance_chart(user, startdate=None, enddate=None, kfitness=42, kfatigue= tz=datetime.timezone.utc).replace(tzinfo=None)) df = df.loc[mask] - source = ColumnDataSource( - data=dict( - testpower=df['testpower'], - testduration=df['testduration'].apply( - lambda x: totaltime_sec_to_string(x, shorten=True)), - date=df['date'], - fdate=df['date'].map(lambda x: x.strftime('%d-%m-%Y')), - fitness=df['fitness'], - fatigue=df['fatigue'], - form=df['form'], - impulse=df['impulse'] - ) - ) + df2 = pd.DataFrame({ + "testpower" :df['testpower'], + "testduration":df['testduration'].apply( + lambda x: totaltime_sec_to_string(x, shorten=True)), + "fitness":df['fitness'], + "fatigue":df['fatigue'], + "form":df['form'], + "impulse":df['impulse'], + "date": df['date'].map(lambda x: x.strftime('%Y-%m-%d')), + }) - plot = figure(tools=TOOLS, x_axis_type='datetime', - width=900, height=300, - toolbar_location="above", - toolbar_sticky=False) - # add watermark - watermarkurl = "/static/img/logo7.png" - 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} + df2.fillna(value=0, inplace=True) - plot.image_url([watermarkurl], watermarkx, watermarky, - watermarkw, watermarkh, - global_alpha=watermarkalpha, - w_units='screen', - h_units='screen', - anchor=watermarkanchor, - dilate=True, - x_range_name="watermark", - y_range_name="watermark", - ) + data_dict = df2.to_dict("records") - fitlabel = 'Fitness' - fatiguelabel = 'Fatigue' - formlabel = 'Freshness' - rightaxlabel = 'Freshness' - if dofatigue: # pragma: no cover - yaxlabel = 'Fitness/Fatigue' - else: # pragma: no cover - yaxlabel = 'Fitness' - - if modelchoice == 'banister': # pragma: no cover - fitlabel = 'PTE (fitness)' - fatiguelabel = 'NTE (fatigue)' - formlabel = 'Performance' - rightaxlabel = 'Performance' - if dofatigue: - yaxlabel = 'PTE/NTE' - else: - yaxlabel = 'PTE' + chart_data = { + 'data': data_dict, + 'title': 'Performance Manager '+user.first_name, + 'plotform' : doform, + 'plotfatigue': dofatigue, + } - plot.xaxis.axis_label = None - plot.yaxis.axis_label = yaxlabel - - y2rangemin = df.loc[:, ['form']].min().min() - y2rangemax = df.loc[:, ['form']].max().max() - - if dofatigue: # pragma: no cover - y1rangemax = df.loc[:, ['fitness', 'fatigue']].max().max()*1.02 - else: # pragma: no cover - y1rangemax = df.loc[:, ['fitness']].max().max()*1.02 - - 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") - - plot.line('date', 'fitness', source=source, color='blue', - legend_label=fitlabel) - band = Band(base='date', upper='fitness', lower=0, source=source, level='underlay', - fill_alpha=0.2, fill_color='blue') - plot.add_layout(band) - - if dofatigue: # pragma: no cover - plot.line('date', 'fatigue', source=source, color='red', - legend_label=fatiguelabel) - if doform: # pragma: no cover - plot.line('date', 'form', source=source, color='green', - legend_label=formlabel, y_range_name="yax2") - - plot.legend.location = "top_left" - - #plot.sizing_mode = 'scale_both' - - startdate = datetime.datetime.combine( - startdate, datetime.datetime.min.time()) - enddate = datetime.datetime.combine(enddate, datetime.datetime.min.time()) - - xrange = Range1d( - startdate, enddate, - ) - plot.x_range = xrange - plot.y_range = Range1d( - start=0, end=y1rangemax, - ) - plot.title.text = 'Performance Manager '+user.first_name - - hover = plot.select(dict(type=HoverTool)) - - linked_crosshair = CrosshairTool(dimensions='height') - - hover.tooltips = OrderedDict([ - ('Date', '@fdate'), - (fitlabel, '@fitness{int}'), - (fatiguelabel, '@fatigue{int}'), - (formlabel, '@form{int}'), - ('Impulse', '@impulse{int}') - ]) - - if showtests: - hover.tooltips = OrderedDict([ - ('Date', '@fdate'), - (fitlabel, '@fitness{int}'), - (fatiguelabel, '@fatigue{int}'), - (formlabel, '@form{int}'), - ('Impulse', '@impulse{int}'), - ('Gold Medal Score', '@testpower{int}'), - ('Test', '@testduration'), - ]) - - plot2 = figure(tools=TOOLS2, x_axis_type='datetime', - width=900, height=150, - toolbar_location=None, - toolbar_sticky=False) - - plot2.x_range = xrange - plot2.y_range = Range1d(0, df['impulse'].max()) - - plot2.vbar(x=df['date'], top=df['impulse'], color='gray') - plot2.vbar(x=df['date'], top=0*df['testpower']+df['impulse'], color='red') - - #plot2.sizing_mode = 'scale_both' - plot2.yaxis.axis_label = 'Impulse' - plot2.xaxis.axis_label = 'Date' - - plot.add_tools(linked_crosshair) - plot2.add_tools(linked_crosshair) - - mylayout = layoutcolumn([plot, plot2]) - - try: - script, div = components(mylayout) - except Exception as e: # pragma: no cover - df.dropna(inplace=True, axis=0, how='any') - return ( - '', - 'Something went wrong with the chart ({nrworkouts} workouts, {nrdata} datapoints, error {e})'.format( - nrworkouts=workouts.count(), - nrdata=len(df), - e=e, - ), 0, 0, 0, [] - ) + script, div = get_chart("/performance", chart_data) return [script, div, endfitness, endfatigue, endform, outids] + def interactive_histoall(theworkouts, histoparam, includereststrokes, spmmin=0, spmmax=55, extratitle='', diff --git a/rowers/templates/performancemanager.html b/rowers/templates/performancemanager.html index c0fd3040..11b38315 100644 --- a/rowers/templates/performancemanager.html +++ b/rowers/templates/performancemanager.html @@ -8,6 +8,15 @@ +{% endblock %} + +{% block main %} + + + + + -{% endblock %} - -{% block main %} - - - - - -
- {{ chartscript |safe }} -
@@ -83,10 +82,12 @@
    +
  • {{ the_div|safe }} -
    + +
  • @@ -188,6 +189,9 @@
+
+ {{ chartscript |safe }} +
{% endblock %}