From 84b4d0f10b0cf9c3ef1334fabb1dd752b86ae67b Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Wed, 2 Dec 2020 09:55:45 +0100 Subject: [PATCH] responsive frm --- rowers/interactiveplots.py | 34 +++--- rowers/templates/performancemanager.html | 139 +++++++++++++---------- rowers/templates/virtualevents.html | 2 +- rowers/views/analysisviews.py | 13 +++ 4 files changed, 111 insertions(+), 77 deletions(-) diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 376e6c43..ccec5fec 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1680,6 +1680,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, metricchoice='trimp',doform=False,dofatigue=False): TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' + TOOLS2 = 'box_zoom,hover' fatigues = [] @@ -1777,18 +1778,18 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, fitlabel = 'PTE (fitness)' fatiguelabel = 'NTE (fatigue)' formlabel = 'Performance' - rightaxlabel = 'NTE' - if doform: - yaxlabel = 'PTE/Performance' + rightaxlabel = 'Performance' + if dofatigue: + yaxlabel = 'PTE/NTE' else: yaxlabel = 'PTE' else: fitlabel = 'Fitness' fatiguelabel = 'Fatigue' formlabel = 'Freshness' - rightaxlabel = 'Fatigue' - if doform: - yaxlabel = 'Fitness/Freshness' + rightaxlabel = 'Freshness' + if dofatigue: + yaxlabel = 'Fitness/Fatigue' else: yaxlabel = 'Fitness' @@ -1829,13 +1830,6 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, plot.legend.location = "top_left" - #plot.xaxis.formatter = DatetimeTickFormatter( - # days=["%d %B %Y"], - # months=["%d %B %Y"], - # years=["%d %B %Y"], - # ) - - #plot.xaxis.major_label_orientation = pi/4 plot.sizing_mode = 'scale_both' #plot.y_range = Range1d(0,1.5*max(df['testpower'])) @@ -1854,19 +1848,26 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, hover = plot.select(dict(type=HoverTool)) + linked_crosshair = CrosshairTool(dimensions='height') + hover.tooltips = OrderedDict([ #(legend_label,'@testpower'), ('Date','@fdate'), (fitlabel,'@fitness'), (fatiguelabel,'@fatigue'), - (formlabel,'@form') + (formlabel,'@form'), + ('Impulse','@impulse') ]) - plot2 = Figure(tools=TOOLS,x_axis_type='datetime', + + + plot2 = Figure(tools=TOOLS2,x_axis_type='datetime', plot_width=900,plot_height=150, toolbar_location=None, toolbar_sticky=False) + + plot2.x_range = xrange plot2.y_range = Range1d(0,df['impulse'].max()) @@ -1876,6 +1877,9 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, plot2.yaxis.axis_label = 'Impulse' plot2.xaxis.axis_label = 'Date' + plot.add_tools(linked_crosshair) + plot2.add_tools(linked_crosshair) + layout = layoutcolumn([plot,plot2]) layout.sizing_mode = 'stretch_both' diff --git a/rowers/templates/performancemanager.html b/rowers/templates/performancemanager.html index ddafcfa8..726bc460 100644 --- a/rowers/templates/performancemanager.html +++ b/rowers/templates/performancemanager.html @@ -4,72 +4,72 @@ {% block title %}Rowsandall Fitness Progress {% endblock %} -{% block main %} - +{% block scripts %} + + +{% endblock %} + +{% block main %} + -{{ chartscript |safe }} +
+ {{ chartscript |safe }} +
+ - {% if rower.user %}

Fitness Progress for {{ rower.user.first_name }}

@@ -77,31 +77,48 @@

Fitness Progress for {{ user.first_name }}

{% endif %} -

- Text Explaining Performance Manager -

-
    +
  • +
    + {{ the_div|safe }} +
    +
  • -
    + {{ form.as_table }}
    {% csrf_token %} - +
    +
  • +
  • +

    + The Performance Manager on this page is based on scientific literature + on modeling human performance. A good description can be found + here. + Every person is different. This statement has implications for training and modeling of + training impact. Each person differs in their response to training, diet, rest, or + other factors. You are an experiment of one, a unique person and all models are + wrong (but some are useful). Be prepared to learn from this chart, to experiment + and perhaps to go against established advice. +

    +

    + The chart models your performance over a time period that you can set with the form + on the left. The model balances out after a few weeks of regular training, so don't + make this chart shorter than a few months. +

    +
  • - -
  • - {{ the_div|safe }} -
{% endblock %} + + {% block sidebar %} {% include 'menu_analytics.html' %} {% endblock %} diff --git a/rowers/templates/virtualevents.html b/rowers/templates/virtualevents.html index e2b06add..9fb5856f 100644 --- a/rowers/templates/virtualevents.html +++ b/rowers/templates/virtualevents.html @@ -65,7 +65,7 @@ {% csrf_token %}

- +

diff --git a/rowers/views/analysisviews.py b/rowers/views/analysisviews.py index 6f28e61e..64c86fb3 100644 --- a/rowers/views/analysisviews.py +++ b/rowers/views/analysisviews.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals, absolute_import from rowers.views.statements import * import collections +import simplejson from jinja2 import Template,Environment,FileSystemLoader def floatformat(x,prec=2): @@ -1547,6 +1548,10 @@ def performancemanager_view(request,userid=0,mode='rower', startdate=timezone.now()-timezone.timedelta(days=365), enddate=timezone.now()): + is_ajax = False + if request.is_ajax(): + is_ajax = True + therower = getrequestrower(request,userid=userid) theuser = therower.user @@ -1590,6 +1595,14 @@ def performancemanager_view(request,userid=0,mode='rower', } ] + if is_ajax: + response = json.dumps({ + 'script':script, + 'div':thediv, + }) + + return(HttpResponse(response,content_type='application/json')) + return render(request,'performancemanager.html', {