Private
Public Access
1
0

using sessions to keep workout type selected

This commit is contained in:
Sander Roosendaal
2017-02-07 15:54:07 +01:00
parent 2fc2431de9
commit abcf2f1789
3 changed files with 123 additions and 60 deletions

View File

@@ -233,3 +233,15 @@ class IntervalUpdateForm(forms.Form):
self.fields['intervald_%s' % i].widget.attrs['style'] = 'width:76px; height: 16px;'
self.fields['type_%s' % i].widget.attrs['style'] = 'width:156px; height: 22px;'
self.fields['intervald_%s' % i].widget = forms.TimeInput(format='%H:%M:%S.%f')
# This form sets options for the summary stats page
class StatsOptionsForm(forms.Form):
includereststrokes = forms.BooleanField(initial=False,label='Include Rest Strokes',required=False)
water = forms.BooleanField(initial=False,required=False)
rower = forms.BooleanField(initial=True,required=False)
dynamic = forms.BooleanField(initial=True,required=False)
slides = forms.BooleanField(initial=True,required=False)
skierg = forms.BooleanField(initial=False,required=False)
paddle = forms.BooleanField(initial=False,required=False)
snow = forms.BooleanField(initial=False,required=False)
other = forms.BooleanField(initial=False,required=False)

View File

@@ -6,63 +6,63 @@
{% block content %}
<div class="grid_12 alpha">
<h1>Workout Statistics for</h1>
<h1>Workout Statistics</h1>
<p>
This is an experimental page which just lists a bunch of statistics for
your workouts. This page is under rapid development.
</p>
</div>
<div id="summary" class="grid_6 alpha">
<div class="grid_12 alpha">
<div id="summary" class="grid_6 alpha">
<p>Summary for {{ theuser.first_name }} {{ theuser.last_name }}
between {{ startdate|date }} and {{ enddate|date }}</p>
<p>Direct link for other Pro users:
<a href="/rowers/{{ id }}/cumstats/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">https://rowsandall.com/rowers/{{ id }}/cumstats/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
</p>
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% csrf_token %}
<div class="grid_2 alpha">
<table>
{{ optionsform.as_table }}
</table>
</div>
<div class="grid_2 suffix_2 omega">
<input type="hidden" name="options" value="options">
<input class="grid_1 alpha button green small" value="Submit" type="Submit">
</div>
</form>
<p>Summary for {{ theuser.first_name }} {{ theuser.last_name }}
between {{ startdate|date }} and {{ enddate|date }}</p>
<p>Direct link for other Pro users:
<a href="/rowers/{{ id }}/cumstats/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">https://rowsandall.com/rowers/{{ id }}/cumstats/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
</p>
<div class="grid_2 omega suffix_4 tooltip">
<form enctype="multipart/form-data" action="{{ formloc }}" method="post">
{% csrf_token %}
{% if workstrokesonly == True %}
<input class="grid_2 alpha button blue small" type="hidden" name="workstrokesonly" value="False">
<input class="grid_2 alpha button blue small" value="Include Rest Strokes" type="Submit">
{% else %}
<input class="grid_2 alpha button blue small" type="hidden" name="workstrokesonly" value="True">
<input class="grid_2 alpha button blue small" value="Remove Rest Strokes" type="Submit">
{% endif %}
</form>
<span class="tooltiptext">If your data source allows, this will show or hide strokes taken during rest intervals.</span>
</div>
</div>
<div id="form" class="grid_6 omega">
<p>Use this form to select a different date range:</p>
<p>
Select start and end date for a date range:
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="" method="post">
<table>
{{ form.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
</div>
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="" method="post">
<p>Use this form to select a different date range:</p>
<p>
Select start and end date for a date range:
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="" method="post">
<table>
{{ form.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
</div>
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="" method="post">
Or use the last {{ deltaform }} days.
</div>
<div class="grid_2 omega">
{% csrf_token %}
<input name='datedelta' class="button green" type="submit" value="Submit">
</form>
</div>
</div>
<div class="grid_2 omega">
{% csrf_token %}
<input name='datedelta' class="button green" type="submit" value="Submit">
</form>
</div>
</div>
</div>
<div class="grid_12 alpha">
<div class="grid_4 alpha">
{% if stats %}
{% for key, value in stats.items %}
@@ -97,7 +97,7 @@
</div>
<div class="grid_8 omega">
{% if cordict %}
<h2> Correlation table</h2>
<h2> Correlation Matrix</h2>
<p>This table indicates a positive (+) or negative (-) correlation between two parameters. The strong correlations are indicated with ++ and --.
</p>
<table width="90%" class="cortable">
@@ -135,5 +135,5 @@
{% endif %}
</div>
</div>
{% endblock %}

View File

@@ -20,9 +20,13 @@ from django.conf import settings
from django.utils.datastructures import MultiValueDictKeyError
from django.utils import timezone,translation
from django.core.mail import send_mail, BadHeaderError
from rowers.forms import EmailForm, RegistrationForm, RegistrationFormTermsOfService,RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,UpdateStreamForm
from rowers.forms import PredictedPieceForm,DateRangeForm,DeltaDaysForm
from rowers.forms import SummaryStringForm,IntervalUpdateForm,StrokeDataForm
from rowers.forms import (
SummaryStringForm,IntervalUpdateForm,StrokeDataForm,
StatsOptionsForm,PredictedPieceForm,DateRangeForm,DeltaDaysForm,
EmailForm, RegistrationForm, RegistrationFormTermsOfService,
RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,
UpdateStreamForm
)
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
from rowers.models import (
RowerPowerForm,RowerForm,GraphImage,AdvancedWorkoutForm,
@@ -55,7 +59,7 @@ from rowers.tasks import handle_makeplot,handle_otwsetpower,handle_sendemailtcx,
from rowers.tasks import handle_sendemail_unrecognized
from scipy.signal import savgol_filter
from django.shortcuts import render_to_response
from Cookie import SimpleCookie
from shutil import copyfile
from rowingdata import rower as rrower
@@ -2616,12 +2620,20 @@ def cumstats(request,theuser=0,
enddate=timezone.now(),
deltadays=-1,
startdatestring="",
enddatestring="",
workstrokesonly=True):
workstrokesonly = True
if request.method == 'POST' and 'workstrokesonly' in request.POST:
enddatestring="",
options={
'includereststrokes':False,
'workouttypes':['rower','dynamic','slides']
}):
if 'options' in request.session:
options = request.session['options']
workouttypes = options['workouttypes']
includereststrokes = options['includereststrokes']
workstrokesonly = not includereststrokes
checktypes = ['water','rower','dynamic','slides','skierg',
'paddle','snow','other']
if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -2654,6 +2666,7 @@ def cumstats(request,theuser=0,
# process form
if request.method == 'POST' and "daterange" in request.POST:
form = DateRangeForm(request.POST)
deltaform = DeltaDaysForm(request.POST)
optionsform = StatsOptionsForm()
if form.is_valid():
startdate = form.cleaned_data['startdate']
@@ -2676,20 +2689,41 @@ def cumstats(request,theuser=0,
form = DateRangeForm(initial={
'startdate': startdate,
'enddate': enddate,
})
optionsform = StatsOptionsForm()
else:
form = DateRangeForm()
optionsform = StatsOptionsForm()
elif request.method == 'POST' and 'options' in request.POST:
optionsform = StatsOptionsForm(request.POST)
if optionsform.is_valid():
includereststrokes = optionsform.cleaned_data['includereststrokes']
workstrokesonly = not includereststrokes
workouttypes = []
for type in checktypes:
if optionsform.cleaned_data[type]:
workouttypes.append(type)
options = {
'includereststrokes':includereststrokes,
'workouttypes':workouttypes,
}
form = DateRangeForm()
deltaform = DeltaDaysForm()
else:
form = DateRangeForm()
deltaform = DeltaDaysForm()
else:
form = DateRangeForm(initial={
'startdate': startdate,
'enddate': enddate,
})
deltaform = DeltaDaysForm()
optionsform = StatsOptionsForm()
try:
r2 = Rower.objects.get(user=theuser)
allergworkouts = Workout.objects.filter(user=r2,
allergworkouts = Workout.objects.filter(user=r2,
workouttype__in=workouttypes,
startdatetime__gte=startdate,
startdatetime__lte=enddate)
@@ -2795,7 +2829,6 @@ def cumstats(request,theuser=0,
try:
datadf = datadf[~datadf['workoutstate'].isin(workoutstatesrest)]
except:
pass
pass
# Create stats
@@ -2828,20 +2861,38 @@ def cumstats(request,theuser=0,
thedict[field2] = 0
cordict[field1] = thedict
# set options form correctly
initial = {}
initial['includereststrokes'] = includereststrokes
for wtype in checktypes:
if wtype in workouttypes:
initial[wtype] = True
else:
initial[wtype] = False
optionsform = StatsOptionsForm(initial=initial)
response = render(request,
'cumstats.html',
{
'stats':stats,
'stats':stats,
'options':options,
'id':theuser,
'theuser':u,
'startdate':startdate,
'enddate':enddate,
'form':form,
'deltaform':deltaform,
'optionsform':optionsform,
'cordict':cordict,
})
request.session['options'] = options
return response
# Stats page
@login_required()