Private
Public Access
1
0

Merge branch 'release/histo'

This commit is contained in:
Sander Roosendaal
2016-11-22 16:40:20 +01:00
17 changed files with 492 additions and 126 deletions

View File

@@ -5,6 +5,8 @@ from rowingdata import cumcpdata,histodata
from rowingdata import rowingdata as rrdata
from django.utils import timezone
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
from bokeh.models import CustomJS,Slider
from bokeh.charts import Histogram,HeatMap
@@ -570,7 +572,6 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
datadf = dataprep.smalldataprep(theworkouts,xparam,yparam1,yparam2)
axlabels = {
'time': 'Time',
'distance': 'Distance (m)',
@@ -631,11 +632,16 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
return ['','<p>No non-zero data in selection</p>','','']
datadf['x1'] = datadf.ix[:,xparam]
datadf['y1'] = datadf.ix[:,yparam1]
# datadf['x1'] = datadf.ix[:,xparam]
datadf = datadf.rename(columns={
xparam:'x1',
yparam1:'y1',
})
# datadf['y1'] = datadf.ix[:,yparam1]
if yparam2 != 'None':
datadf['y2'] = datadf.ix[:,yparam2]
# datadf['y2'] = datadf.ix[:,yparam2]
datadf = datadf.rename(columns={yparam2:'y2'})
else:
datadf['y2'] = datadf['y1']
@@ -674,6 +680,8 @@ def interactive_cum_flex_chart2(theworkouts,promember=0,
datadf.copy()
)
print "jet",timezone.now()
# Add hover to this comma-separated string and see what changes
if (promember==1):
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize,crosshair'

View File

@@ -7,115 +7,132 @@
{% block content %}
<div id="workouts" class="grid_6 alpha">
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
{% if form.errors %}
<p style="color: red;">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<h1>Advanced Workout Editor</h1>
{% if user.rower.rowerplan == 'basic' %}
<p>This is a preview of the page with advanced functionality for Pro users. See <a href="/rowers/promembership">the page about Pro membership</a> for more information and to sign up for Pro Membership</a>
{% endif %}
<div class="grid_2 alpha">
<p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
</p>
</div>
<div class="grid_2 suffix_2 omega">
<p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/export">Export</a>
</p>
<h1>Advanced Workout Editor</h1>
{% if user.rower.rowerplan == 'basic' %}
<p>This is a preview of the page with advanced functionality for Pro users.
See
<a href="/rowers/promembership">the page about Pro membership</a> for more information and to sign up for Pro Membership</a>
{% endif %}
<div class="grid_2 alpha">
<p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/edit">Edit Workout</a>
</p>
</div>
<div class="grid_2 suffix_2 omega">
<p>
<a class="button gray small" href="/rowers/workout/{{ workout.id }}/export">Export</a>
</p>
</div>
<div class="grid_6 alpha">
</div>
<div class="grid_6 alpha">
<table width=100%>
<tr>
<th>Date:</th><td>{{ workout.date }}</td>
</tr><tr>
<th>Time:</th><td>{{ workout.starttime }}</td>
</tr><tr>
<th>Distance:</th><td>{{ workout.distance }}m</td>
</tr><tr>
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
</tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">http://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</table>
<table width=100%>
<tr>
<th>Date:</th><td>{{ workout.date }}</td>
</tr><tr>
<th>Time:</th><td>{{ workout.starttime }}</td>
</tr><tr>
<th>Distance:</th><td>{{ workout.distance }}m</td>
</tr><tr>
<th>Duration:</th><td>{{ workout.duration |durationprint:"%H:%M:%S.%f" }}</td>
</tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</table>
</div>
<div class="grid_6 alpha">
<div class="grid_2 alpha">
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/compare/{{ workout.id }}">Compare Workouts</a>
{% else %}
<a class="button blue small" href="/rowers/promembership/">Compare Workouts</a>
{% endif %}
<p>
Compare this workout to other workouts. Plot HR, SPM, or pace vs time or distance for the two workouts.
</p>
</div>
<div class="grid_2">
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/flexchart">
Flexible Interactive Plot
</a>
<p>
Flexible Interactive plot. Pick your own X and Y axis parameters.
</p>
</div>
<div class="grid_2 alpha">
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/compare/{{ workout.id }}">Compare Workouts</a>
{% else %}
<a class="button blue small" href="/rowers/promembership/">Compare Workouts</a>
{% endif %}
<p>
Compare this workout to other workouts. Plot HR, SPM, or pace vs time or distance for the two workouts.
</p>
</div>
<div class="grid_2">
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/flexchart">
Flexible Interactive Plot
</a>
<p>
Flexible Interactive plot. Pick your own X and Y axis parameters.
</p>
</div>
<div class="grid_2 omega tooltip">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/editintervals">Edit Intervals</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Edit Intervals</a>
{% endif %}
</p>
<span class="tooltiptext">Enter or change the interval and summary data for your workout</span>
<div class="grid_2 omega tooltip">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/editintervals">Edit Intervals</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Edit Intervals</a>
{% endif %}
</p>
<span class="tooltiptext">Enter or change the interval and summary data for your workout</span>
<p>
Enter or change the interval and summary data for your workout
</p>
</div>
</div>
<p>
Enter or change the interval and summary data for your workout
</p>
</div>
</div>
<div class="grid_6 alpha">
<div class="grid_2 alpha">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/adddistanceplot2">Dist Metrics Plot</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Dist Metrics Plot</a>
{% endif %}
</p>
<p>
Various advanced stroke metrics plotted versus distance.
</p>
</div>
<div class="grid_2">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/addtimeplot2">Time Metrics Plot</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Time Metrics Plot</a>
{% endif %}
</p>
<p>
Various advanced stroke metrics plotted versus time.
</p>
</div>
<div class="grid_2 omega">
<p>
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/interactiveplot">Big Interactive Plot</a>
</p>
<p>
See (and save) the big interactive plot
</p>
</div>
<div class="grid_2 alpha">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/adddistanceplot2">Dist Metrics Plot</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Dist Metrics Plot</a>
{% endif %}
</p>
<p>
Various advanced stroke metrics plotted versus distance.
</p>
</div>
<div class="grid_2">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/addtimeplot2">Time Metrics Plot</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Time Metrics Plot</a>
{% endif %}
</p>
<p>
Various advanced stroke metrics plotted versus time.
</p>
</div>
<div class="grid_2 omega">
<p>
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/interactiveplot">Big Interactive Plot</a>
</p>
<p>
See (and save) the big interactive plot
</p>
</div>
</div>
<div class="grid_6 alpha">
<div class="grid_2 suffix_4 alpha">
<p>
{% if user.rower.rowerplan == 'pro' %}
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/histo">Power Histogram</a>
{% else %}
<a class="button blue small" href="/rowers/promembership">Dist Metrics Plot</a>
{% endif %}
</p>
<p>
Plot the Power Histogram of this workout
</p>
</div>
</div>
</div>
@@ -155,4 +172,4 @@ Enter or change the interval and summary data for your workout
</div>
</div>
{% endblock %}
{% endblock %}

View File

@@ -42,7 +42,7 @@
</tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">http://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</table>
</div>

View File

@@ -6,8 +6,7 @@
{% block content %}
<div id="workouts" class="grid_4 alpha">
<div class="grid_4 alpha">
<h1>Workout {{ id }}</h1>
<table width=100%>
<tr>
@@ -30,6 +29,35 @@
<th>Weight Category:</th><td>{{ workout.weightcategory }}</td>
</tr>
</table>
</div>
<div class="grid_4 alpha">
<p>
<form id="searchform" action=""
method="get" accept-charset="utf-8">
<button class="button blue small" type="submit">
Search
</button>
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search">
</form>
</p>
</div>
Select start and end date for a date range:
<div class="grid_4 alpha">
<p>
<form enctype="multipart/form-data" action="/rowers/workout/compare/{{ id }}/" method="post">
<table>
{{ dateform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 suffix_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
</p>
</div>
</div>
<div id="comparison" class="grid_8 omega">
@@ -73,5 +101,21 @@
{% else %}
<p> No workouts found </p>
{% endif %}
<div class="grid_2 prefix_5 suffix_1 omega">
<span class="button gray small">
{% if workouts.has_previous %}
<a class="wh" href="/rowers/workout/compare/{{ id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}?page={{ workouts.previous_page_number }}">&lt;</a>
{% endif %}
<span>
Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}.
</span>
{% if workouts.has_next %}
<a class="wh" href="/rowers/workout/compare/{{ id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}?page={{ workouts.next_page_number }}">&gt;</a>
{% endif %}
</span>
</div>
</div>
{% endblock %}

View File

@@ -46,7 +46,7 @@
between {{ startdate|date }} and {{ enddate|date }}</p>
<p>Direct link for other Pro users:
<a href="/rowers/{{ id }}/histo/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">http://rowsandall.com/rowers/{{ id }}/histo/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
<a href="/rowers/{{ id }}/histo/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">https://rowsandall.com/rowers/{{ id }}/histo/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
</p>
</div>
<div id="form" class="grid_6 omega">
@@ -82,4 +82,4 @@
</div>
{% endblock %}
{% endblock %}

View File

@@ -0,0 +1,66 @@
{% extends "base.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block title %}View Workout {% endblock %}
{% block content %}
<script type="text/javascript" src="/static/js/bokeh-0.12.3.min.js"></script>
<script async="true" type="text/javascript">
Bokeh.set_log_level("info");
</script>
{{ interactiveplot |safe }}
<script>
// Set things up to resize the plot on a window resize. You can play with
// the arguments of resize_width_height() to change the plot's behavior.
var plot_resize_setup = function () {
var plotid = Object.keys(Bokeh.index)[0]; // assume we have just one plot
var plot = Bokeh.index[plotid];
var plotresizer = function() {
// arguments: use width, use height, maintain aspect ratio
plot.resize_width_height(true, false, false);
};
window.addEventListener('resize', plotresizer);
plotresizer();
};
window.addEventListener('load', plot_resize_setup);
</script>
<style>
/* Need this to get the page in "desktop mode"; not having an infinite height.*/
html, body {height: 100%; margin:5px;}
</style>
<div id="navigation" class="grid_12 alpha">
{% if user.is_authenticated and mayedit %}
<div class="grid_2 alpha">
<p>
<a class="button gray small" href="/rowers/workout/{{ id }}/edit">Edit Workout</a>
</p>
</div>
<div class="grid_2 suffix_8 omega">
<p>
<a class="button gray small" href="/rowers/workout/{{ id }}/advanced">Advanced Edit</a>
</p>
</div>
{% endif %}
</div>
<div id="title" class="grid_12 alpha">
<h1>Indoor Rower Power Histogram</h1>
</div>
<div id="graph" class="grid_12 alpha">
{{ the_div|safe }}
</div>
{% endblock %}

View File

@@ -42,7 +42,7 @@
<p>Summary of the past 12 months for {{ theuser.first_name }} {{ theuser.last_name }}</p>
<p>Direct link for other Pro users:
<a href="/rowers/{{ id }}/histo-all">http://rowsandall.com/rowers/{{ id }}/histo-all</a>
<a href="/rowers/{{ id }}/histo-all">https://rowsandall.com/rowers/{{ id }}/histo-all</a>
</p>
<div class="grid_12 alpha">

View File

@@ -6,6 +6,14 @@
{% block content %}
<h1>Recent Graphs</h1>
<form id="searchform" action="."
method="get" accept-charset="utf-8">
<button class="button blue small" type="submit">
Search
</button>
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search">
</form>
{% if graphs1 %}
<div class="grid_1 alpha">
<p>&nbsp;</p>

View File

@@ -5,8 +5,27 @@
{% block title %}Workouts{% endblock %}
{% block content %}
<div class="grid_12">
Select start and end date for a date range:
<div class="grid_4 alpha">
<form enctype="multipart/form-data" action="/rowers/list-workouts/" method="post">
<table>
{{ dateform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 suffix_6 omega">
<input name='daterange' class="button green" type="submit" value="Submit"> </form>
</div>
</div>
<h1>My Workouts</h1>
{% if workouts %}
{% if workouts %}
<table width="70%" class="listtable">
<thead>
<tr>
@@ -49,4 +68,35 @@
{% else %}
<p> No workouts found </p>
{% endif %}
</div>
<div class="grid_6 alpha">
<form id="searchform" action="/rowers/list-workouts/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}"
method="get" accept-charset="utf-8">
<div class="grid_3 prefix_1 alpha">
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search">
</div>
<div class="grid_1 suffix_1 omega">
<button class="button blue small" type="submit">
Search
</button>
</div>
</form>
</div>
<div class="grid_2 prefix_3 omega">
<span class="button gray small">
{% if workouts.has_previous %}
<a class="wh" href="?page={{ workouts.previous_page_number }}">&lt;</a>
{% endif %}
<span>
Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}.
</span>
{% if workouts.has_next %}
<a class="wh" href="?page={{ workouts.next_page_number }}">&gt;</a>
{% endif %}
</span>
{% endblock %}

View File

@@ -48,7 +48,7 @@
</tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">http://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</table>
</div>

View File

@@ -43,7 +43,7 @@
between {{ startdate|date }} and {{ enddate|date }}</p>
<p>Direct link for other users:
<a href="/rowers/{{ id }}/ote-bests/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">http://rowsandall.com/rowers/{{ id }}/ote-bests/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
<a href="/rowers/{{ id }}/ote-bests/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}">https://rowsandall.com/rowers/{{ id }}/ote-bests/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}</a>
</p>
<p>The table gives the best efforts achieved on the official Concept2 ranking pieces in the selected date range.</p>

View File

@@ -48,12 +48,12 @@
</tr><tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">http://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</tr><tr>
<th>Public link to interactive chart</th>
<td>
<a href="/rowers/workout/{{ workout.id }}/interactiveplot">http://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot</a>
<a href="/rowers/workout/{{ workout.id }}/interactiveplot">https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot</a>
<td>
</tr>
</table>

View File

@@ -48,12 +48,12 @@
</tr><tr>
<th>Public link to this workout</th>
<td>
<a href="/rowers/workout/{{ workout.id }}">http://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<a href="/rowers/workout/{{ workout.id }}">https://rowsandall.com/rowers/workout/{{ workout.id }}</a>
<td>
</tr><tr>
<th>Public link to interactive chart</th>
<td>
<a href="/rowers/workout/{{ workout.id }}/interactiveplot">http://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot</a>
<a href="/rowers/workout/{{ workout.id }}/interactiveplot">https://rowsandall.com/rowers/workout/{{ workout.id }}/interactiveplot</a>
<td>
</tr>
</table>

View File

@@ -425,6 +425,9 @@ class ViewTest(TestCase):
response = self.c.get('/rowers/workout/1/interactiveplot', form_data, follow=True)
self.assertEqual(response.status_code, 200)
response = self.c.get('/rowers/workout/1/histo', form_data, follow=True)
self.assertEqual(response.status_code, 200)
w = Workout.objects.get(id=1)

View File

@@ -26,6 +26,7 @@ urlpatterns = [
url(r'^list-workouts/c/(?P<message>\w+.*)/$',views.workouts_view),
url(r'^list-workouts/s/(?P<successmessage>\w+.*)/$',views.workouts_view),
url(r'^list-workouts/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.workouts_view),
url(r'^list-workouts/(?P<startdatestring>\w+.*)/(?P<enddatestring>\w+.*)$',views.workouts_view),
url(r'^list-workouts/$',views.workouts_view),
url(r'^list-graphs/$',views.graphs_view),
url(r'^dashboard/c/(?P<message>\w+.*)/$',views.dashboard_view),
@@ -55,6 +56,7 @@ urlpatterns = [
url(r'^graph/(\d+)/delete$',views.graph_delete_view),
url(r'^workout/upload/$',views.workout_upload_view),
url(r'^workout/upload/(.+.*)$',views.workout_upload_view),
url(r'^workout/(?P<id>\d+)/histo$',views.workout_histo_view),
url(r'^workout/(?P<id>\d+)/export/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.workout_export_view),
url(r'^workout/(?P<id>\d+)/export/c/(?P<message>\w+.*)$',views.workout_export_view),
url(r'^workout/(?P<id>\d+)/export/s/(?P<successmessage>\w+.*)$',views.workout_export_view),
@@ -63,6 +65,7 @@ urlpatterns = [
url(r'^workout/(\d+)/emailcsv$',views.workout_csvemail_view),
url(r'^workout/compare/(\d+)/$',views.workout_comparison_list),
url(r'^workout/compare2/(?P<id1>\d+)/(?P<id2>\d+)/(?P<xparam>\w+.*)/(?P<yparam>\w+.*)/$',views.workout_comparison_view),
url(r'^workout/compare/(?P<id>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\w+.*)$',views.workout_comparison_list),
url(r'^workout/(?P<id>\d+)/export/c/(?P<message>\w+.*)/s/(?P<successmessage>\w+.*)$',views.workout_edit_view),
url(r'^workout/(?P<id>\d+)/edit/c/(?P<message>.+.*)$',views.workout_edit_view),
url(r'^workout/(?P<id>\d+)/edit/s/(?P<successmessage>.+.*)$',views.workout_edit_view),

View File

@@ -1,11 +1,14 @@
import time
import operator
from django.views.generic.base import TemplateView
from django.db.models import Q
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth import authenticate, login, logout
from rowers.forms import LoginForm,DocumentsForm,UploadOptionsForm
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.conf import settings
from django.utils.datastructures import MultiValueDictKeyError
from django.utils import timezone,translation
@@ -1339,6 +1342,36 @@ def cum_flex(request,theuser=0,
'promember':promember,
})
@login_required()
def workout_histo_view(request,id=0):
row = Workout.objects.get(id=id)
promember=0
mayedit=0
if not request.user.is_anonymous():
r = Rower.objects.get(user=request.user)
result = request.user.is_authenticated() and r.rowerplan=='pro'
if result:
promember=1
if request.user == row.user.user:
mayedit=1
if not promember:
return HttpResponseRedirect("/rowers/about/")
res = interactive_histoall([row])
script = res[0]
div = res[1]
return render(request,
'histo_single.html',
{'interactiveplot':script,
'the_div':div,
'id':id,
'mayedit':mayedit,
})
@login_required()
def histo(request,theuser=0,
@@ -1569,8 +1602,8 @@ def rankings_view(request,theuser=0,
for rankingduration in rankingdurations:
workouts = Workout.objects.filter(user=r,duration=rankingduration,
workouttype='rower',
startdatetime__gte=startdate,
workouttype='rower',
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by('-distance')
if workouts:
thedistances.append(workouts[0].distance)
@@ -1764,29 +1797,133 @@ def workout_recalcsummary_view(request,id=0):
@login_required()
def workouts_view(request,message='',successmessage=''):
def workouts_view(request,message='',successmessage='',
startdatestring="",enddatestring="",
startdate=timezone.now()-datetime.timedelta(days=365),
enddate=timezone.now()):
try:
r = Rower.objects.get(user=request.user)
# res = mailprocessing.safeprocessattachments()
#if len(res)>0 and np.cumsum(np.array(res)).max()>0:
# successmessage = 'New Workouts have been created from email'
workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime")
if request.method == 'POST':
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
if startdatestring:
startdate = iso8601.parse_date(startdatestring)
if enddatestring:
enddate = iso8601.parse_date(enddatestring)
if enddate < startdate:
s = enddate
enddate = startdate
startdate = s
workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime")
query = request.GET.get('q')
if query:
query_list = query.split()
workouts = workouts.filter(
reduce(operator.and_,
(Q(name__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(notes__icontains=q) for q in query_list))
)
paginator = Paginator(workouts,20) # show 25 workouts per page
page = request.GET.get('page')
try:
workouts = paginator.page(page)
except PageNotAnInteger:
workouts = paginator.page(1)
except EmptyPage:
workouts = paginator.page(paginator.num_pages)
return render(request, 'list_workouts.html',
{'workouts': workouts,
'message': message,
'successmessage':successmessage,
'dateform':dateform,
'startdate':startdate,
'enddate':enddate,
})
except Rower.DoesNotExist:
return HttpResponse("Admin has no rower instance")
@user_passes_test(promember,login_url="/login")
def workout_comparison_list(request,id=0,message='',successmessage=''):
def workout_comparison_list(request,id=0,message='',successmessage='',
startdatestring="",enddatestring="",
startdate=timezone.now()-datetime.timedelta(days=365),
enddate=timezone.now()):
try:
r = Rower.objects.get(user=request.user)
u = User.objects.get(id=r.user.id)
workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime").exclude(id=id)
if request.method == 'POST':
dateform = DateRangeForm(request.POST)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'enddate':enddate,
})
if startdatestring:
startdate = iso8601.parse_date(startdatestring)
if enddatestring:
enddate = iso8601.parse_date(enddatestring)
startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
if enddate < startdate:
s = enddate
enddate = startdate
startdate = s
workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime").exclude(id=id)
query = request.GET.get('q')
if query:
query_list = query.split()
workouts = workouts.filter(
reduce(operator.and_,
(Q(name__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(notes__icontains=q) for q in query_list))
)
paginator = Paginator(workouts,15) # show 25 workouts per page
page = request.GET.get('page')
try:
workouts = paginator.page(page)
except PageNotAnInteger:
workouts = paginator.page(1)
except EmptyPage:
workouts = paginator.page(paginator.num_pages)
row = Workout.objects.get(id=id)
return render(request, 'comparison_list.html',
@@ -1797,6 +1934,9 @@ def workout_comparison_list(request,id=0,message='',successmessage=''):
'first_name':u.first_name,
'message': message,
'successmessage':successmessage,
'dateform':dateform,
'startdate':startdate,
'enddate':enddate,
})
except Rower.DoesNotExist:
return HttpResponse("Admin has no rower instance")
@@ -3942,6 +4082,16 @@ def graphs_view(request):
try:
r = Rower.objects.get(user=request.user)
workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime")
query = request.GET.get('q')
if query:
query_list = query.split()
workouts = workouts.filter(
reduce(operator.and_,
(Q(name__icontains=q) for q in query_list)) |
reduce(operator.and_,
(Q(notes__icontains=q) for q in query_list))
)
g = GraphImage.objects.filter(workout__in=workouts).order_by("-creationdatetime")
if (len(g)<=5):
return render(request, 'list_graphs.html',

View File

@@ -17,14 +17,19 @@ a {
text-decoration: none;
}
a:visited { color:#000; }
a:link { color: #000; }
a:hover {
text-decoration: underline;
}
h1 {
/* font-family: Georgia, serif; */
font-weight: normal;
@@ -471,4 +476,16 @@ a.button {
.flexplot {
position: relative;
z-index: 10;
}
}
a.wh:link {
color: #e9e9e9;
}
a.wh:visited {
color: #e9e9e9;
}
a.wh:hover {
color: #e9e9e9;
}