prototype history page
This commit is contained in:
@@ -143,6 +143,30 @@ class DisqualificationForm(forms.Form):
|
||||
|
||||
message = forms.CharField(required=True,widget=forms.Textarea)
|
||||
|
||||
class HistorySelectForm(forms.Form):
|
||||
typeselectchoices = [("All","All")]
|
||||
for wtype,verbose in mytypes.workouttypes_ordered.items():
|
||||
typeselectchoices.append((wtype,verbose))
|
||||
startdate = forms.DateField(
|
||||
initial=timezone.now()-datetime.timedelta(days=15),
|
||||
# widget=SelectDateWidget(years=range(1990,2050)),
|
||||
widget=AdminDateWidget(), #format='%Y-%m-%d'),
|
||||
label='Start Date')
|
||||
enddate = forms.DateField(
|
||||
initial=timezone.now(),
|
||||
widget=AdminDateWidget(), #format='%Y-%m-%d'),
|
||||
label='End Date')
|
||||
|
||||
workouttype = forms.ChoiceField(initial='All',choices=typeselectchoices)
|
||||
|
||||
class Meta:
|
||||
fields = ['startdate','enddate']
|
||||
input_formats=("%Y-%m-%d")
|
||||
dateTimeOptions = {
|
||||
'format': '%Y-%m-%d',
|
||||
'autoclose': True,
|
||||
}
|
||||
|
||||
class MetricsForm(forms.Form):
|
||||
avghr = forms.IntegerField(required=False,label='Average Heart Rate')
|
||||
avgpwr = forms.IntegerField(required=False,label='Average Power')
|
||||
|
||||
@@ -172,6 +172,8 @@ from rowers.dataprep import timedeltaconv
|
||||
from math import pi
|
||||
|
||||
def interactive_hr_piechart(df,rower,title):
|
||||
if df.empty:
|
||||
return "","Not enough data to make a chart"
|
||||
|
||||
df.sort_values(by='hr',inplace=True)
|
||||
qry = 'hr < {ut2}'.format(ut2=rower.ut2)
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
<h1>History</h1>
|
||||
<ul class="main-content">
|
||||
<script async="true" src="https://cdn.pydata.org/bokeh/release/bokeh-1.0.4.min.js"></script>
|
||||
<li class="grid_1">
|
||||
<li class="grid_4">
|
||||
<form enctype="multipart/form-data" method="post">
|
||||
{% csrf_token %}
|
||||
<table>
|
||||
{{ form.as_table }}
|
||||
</table>
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</li>
|
||||
<li class="grid_2">
|
||||
<h2>All workouts</h2>
|
||||
|
||||
<p>
|
||||
@@ -39,7 +48,7 @@
|
||||
</table>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<li class="grid_2">
|
||||
<div>{{ totalscript|safe }}{{ totaldiv|safe }}</div>
|
||||
</li>
|
||||
{% for ddict in typedicts %}
|
||||
@@ -74,12 +83,14 @@
|
||||
</table>
|
||||
</p>
|
||||
</li>
|
||||
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
||||
{% block sidebar %}
|
||||
{% include 'menu_analytics.html' %}
|
||||
{% endblock %}
|
||||
|
||||
@@ -4654,12 +4654,33 @@ class AlertDelete(DeleteView):
|
||||
@login_required()
|
||||
def history_view(request,userid=0):
|
||||
r = getrequestrower(request,userid=userid)
|
||||
|
||||
form = HistorySelectForm()
|
||||
|
||||
usertimezone = pytz.timezone(r.defaulttimezone)
|
||||
|
||||
activity_enddate = timezone.now()
|
||||
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)
|
||||
typeselect = 'All'
|
||||
|
||||
if request.method=='POST':
|
||||
form = HistorySelectForm(request.POST)
|
||||
if form.is_valid():
|
||||
startdate = form.cleaned_data['startdate']
|
||||
enddate = form.cleaned_data['enddate']
|
||||
typeselect = form.cleaned_data['workouttype']
|
||||
activity_startdate = datetime.datetime(
|
||||
startdate.year,startdate.month,startdate.day
|
||||
).replace(hour=0,minute=0,second=0).astimezone(usertimezone)
|
||||
activity_enddate = datetime.datetime(
|
||||
enddate.year,enddate.month,enddate.day
|
||||
).replace(hour=23,minute=59,second=59).astimezone(usertimezone)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
g_workouts = Workout.objects.filter(
|
||||
user=r,
|
||||
@@ -4679,6 +4700,13 @@ def history_view(request,userid=0):
|
||||
|
||||
# meters, duration per workout type
|
||||
wtypes = list(set([w.workouttype for w in g_workouts]))
|
||||
|
||||
typechoices = [("All","All")]
|
||||
for wtype in wtypes:
|
||||
typechoices.append((wtype,mytypes.workouttypes_ordered[wtype]))
|
||||
|
||||
form.fields['workouttype'].choices = typechoices
|
||||
|
||||
listofdicts = []
|
||||
|
||||
for wtype in wtypes:
|
||||
@@ -4699,8 +4727,14 @@ def history_view(request,userid=0):
|
||||
ddict['nrworkouts'] = a_workouts.count()
|
||||
listofdicts.append(ddict)
|
||||
|
||||
|
||||
# interactive hr pie chart
|
||||
totalscript,totaldiv = interactive_hr_piechart(df,r,'All Workouts')
|
||||
if typeselect == 'All':
|
||||
totalscript,totaldiv = interactive_hr_piechart(df,r,'All Workouts')
|
||||
else:
|
||||
a_workouts = g_workouts.filter(workouttype=typeselect)
|
||||
ddf = getsmallrowdata_db(columns,ids=[w.id for w in a_workouts])
|
||||
totalscript, totaldiv = interactive_hr_piechart(ddf,r,mytypes.workouttypes_ordered[typeselect])
|
||||
|
||||
# interactive power pie chart
|
||||
|
||||
@@ -4737,4 +4771,5 @@ def history_view(request,userid=0):
|
||||
'typedicts':listofdicts,
|
||||
'totalscript':totalscript,
|
||||
'totaldiv':totaldiv,
|
||||
'form':form,
|
||||
})
|
||||
|
||||
@@ -74,7 +74,7 @@ from rowers.forms import (
|
||||
MetricsForm,DisqualificationForm,disqualificationreasons,
|
||||
disqualifiers,SearchForm,BillingForm,PlanSelectForm,
|
||||
VideoAnalysisCreateForm,WorkoutSingleSelectForm,
|
||||
VideoAnalysisMetricsForm,SurveyForm,
|
||||
VideoAnalysisMetricsForm,SurveyForm,HistorySelectForm,
|
||||
)
|
||||
|
||||
from django.urls import reverse, reverse_lazy
|
||||
|
||||
Reference in New Issue
Block a user