added buttons to fusion
This commit is contained in:
@@ -6,6 +6,8 @@ from django.contrib.auth.models import User
|
||||
from django.contrib.admin.widgets import AdminDateWidget
|
||||
from django.forms.extras.widgets import SelectDateWidget
|
||||
from django.utils import timezone,translation
|
||||
from django.forms import ModelForm
|
||||
import dataprep
|
||||
|
||||
import datetime
|
||||
|
||||
@@ -261,7 +263,7 @@ from rowers.interactiveplots import axlabels
|
||||
|
||||
formaxlabels = axlabels.copy()
|
||||
formaxlabels.pop('None')
|
||||
parchoices = list(sorted(axlabels.items(), key = lambda x:x[1]))
|
||||
parchoices = list(sorted(formaxlabels.items(), key = lambda x:x[1]))
|
||||
|
||||
|
||||
class ChartParamChoiceForm(forms.Form):
|
||||
@@ -275,9 +277,13 @@ class ChartParamChoiceForm(forms.Form):
|
||||
teamid = forms.IntegerField(widget=forms.HiddenInput())
|
||||
|
||||
formaxlabels.pop('time')
|
||||
metricchoices = list(sorted(axlabels.items(), key = lambda x:x[1]))
|
||||
metricchoices = list(sorted(formaxlabels.items(), key = lambda x:x[1]))
|
||||
|
||||
class FusionMetricChoiceForm(forms.Form):
|
||||
class FusionMetricChoiceForm(ModelForm):
|
||||
class Meta:
|
||||
model = Workout
|
||||
fields = []
|
||||
|
||||
posneg = (
|
||||
('pos','Workout 2 starts after Workout 1'),
|
||||
('neg','Workout 2 starts before Workout 1'),
|
||||
@@ -287,3 +293,17 @@ class FusionMetricChoiceForm(forms.Form):
|
||||
widget=forms.CheckboxSelectMultiple())
|
||||
posneg = forms.ChoiceField(choices=posneg,initial='pos')
|
||||
offset = forms.DurationField(label='Time Offset',initial=datetime.timedelta())
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(FusionMetricChoiceForm, self).__init__(*args, **kwargs)
|
||||
# need to add code to remove "empty" fields
|
||||
|
||||
id = self.instance.id
|
||||
df = dataprep.getrowdata_db(id=id)
|
||||
|
||||
labeldict = {key:value for key,value in metricchoices}
|
||||
|
||||
for label in labeldict:
|
||||
if df[label].std() == 0:
|
||||
self.fields['columns'].choices.remove((label, labeldict[label]))
|
||||
|
||||
|
||||
@@ -121,7 +121,7 @@
|
||||
</div>
|
||||
<div class="grid_6 alpha">
|
||||
|
||||
<div class="grid_2 suffix_4 alpha">
|
||||
<div class="grid_2 alpha">
|
||||
<p>
|
||||
{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %}
|
||||
<a class="button blue small" href="/rowers/workout/{{ workout.id }}/histo">Power Histogram</a>
|
||||
@@ -133,9 +133,20 @@
|
||||
Plot the Power Histogram of this workout
|
||||
</p>
|
||||
</div>
|
||||
<div class="grid_2 suffix_2 omega">
|
||||
<p>
|
||||
{% if user.rower.rowerplan == 'pro' or user.rower.rowerplan == 'coach' %}
|
||||
<a class="button blue small" href="/rowers/workout/fusion/{{ workout.id }}/">Sensor Fusion</a>
|
||||
{% else %}
|
||||
<a class="button blue small" href="/rowers/promembership">Dist Metrics Plot</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
<p>
|
||||
Merge data from another source into this workout
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="advancedplots" class="grid_6 omega">
|
||||
<div class="grid_6 alpha">
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<div class="grid_12 alpha">
|
||||
<div class="grid_6 alpha">
|
||||
<p>
|
||||
Adding sensor data from workout {{ workout2.id }} into workout {{ workout1.id2 }}.
|
||||
Adding sensor data from workout {{ workout2.id }} into workout {{ workout1.id }}.
|
||||
This will create a new workout. After you submit the form, you will be
|
||||
taken to the newly created workout. If you are happy with the result, you
|
||||
can delete the two original workouts manually.
|
||||
|
||||
121
rowers/templates/fusion_list.html
Normal file
121
rowers/templates/fusion_list.html
Normal file
@@ -0,0 +1,121 @@
|
||||
{% extends "base.html" %}
|
||||
{% load staticfiles %}
|
||||
{% load rowerfilters %}
|
||||
|
||||
{% block title %}Workouts{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="workouts" class="grid_4 alpha">
|
||||
<div class="grid_4 alpha">
|
||||
<h1>Workout {{ id }}</h1>
|
||||
<table width=100%>
|
||||
<tr>
|
||||
<th>Rower:</th><td>{{ first_name }} {{ last_name }}</td>
|
||||
</tr><tr>
|
||||
<tr>
|
||||
<th>Name:</th><td>{{ workout.name }}</td>
|
||||
</tr><tr>
|
||||
<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><tr>
|
||||
<th>Type:</th><td>{{ workout.workouttype }}</td>
|
||||
</tr><tr>
|
||||
<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/fusion/{{ 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="fusion" class="grid_8 omega">
|
||||
<h1>Fuse this workout with data from:</h1>
|
||||
{% if workouts %}
|
||||
<table width="100%" class="listtable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> Date</th>
|
||||
<th> Time</th>
|
||||
<th> Name</th>
|
||||
<th> Type</th>
|
||||
<th> Distance </th>
|
||||
<th> Duration </th>
|
||||
<th> Avg HR </th>
|
||||
<th> Max HR </th>
|
||||
<th> Fusion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</tbody>
|
||||
{% for cworkout in workouts %}
|
||||
<tr>
|
||||
<td> {{ cworkout.date }} </td>
|
||||
<td> {{ cworkout.starttime }} </td>
|
||||
<td> <a href="/rowers/workout/{{ workout.id }}/edit">{{ cworkout.name }}</a> </td>
|
||||
<td> {{ cworkout.workouttype }} </td>
|
||||
<td> {{ cworkout.distance }}m</td>
|
||||
<td> {{ cworkout.duration |durationprint:"%H:%M:%S.%f" }} </td>
|
||||
<td> {{ cworkout.averagehr }} </td>
|
||||
<td> {{ cworkout.maxhr }} </td>
|
||||
{% if id == cworkout.id %}
|
||||
<td> </td>
|
||||
{% else %}
|
||||
<td> <a class="button blue small" href="/rowers/workout/fusion/{{ id }}/{{ cworkout.id }}">Fusion</a> </td>
|
||||
{% endif %}
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{% 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/fusion/{{ id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}?page={{ workouts.previous_page_number }}"><</a>
|
||||
{% endif %}
|
||||
|
||||
<span>
|
||||
Page {{ workouts.number }} of {{ workouts.paginator.num_pages }}.
|
||||
</span>
|
||||
|
||||
{% if workouts.has_next %}
|
||||
<a class="wh" href="/rowers/workout/fusion/{{ id }}/{{ startdate|date:"Y-m-d" }}/{{ enddate|date:"Y-m-d" }}?page={{ workouts.next_page_number }}">></a>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -190,6 +190,9 @@ urlpatterns = [
|
||||
url(r'^workout/(\d+)/view$',views.workout_view),
|
||||
url(r'^workout/(\d+)$',views.workout_view),
|
||||
url(r'^workout/fusion/(?P<id1>\d+)/(?P<id2>\d+)$',views.workout_fusion_view),
|
||||
url(r'^workout/fusion/(\d+)/$',views.workout_fusion_list),
|
||||
url(r'^workout/fusion/(?P<id>\d+)/(?P<startdatestring>\d+-\d+-\d+)/(?P<enddatestring>\w+.*)$',views.workout_fusion_list),
|
||||
|
||||
url(r'^physics$',TemplateView.as_view(template_name='physics.html'),name='physics'),
|
||||
url(r'^workout/(\d+)/$',views.workout_view),
|
||||
url(r'^workout/(\d+)/addtimeplot$',views.workout_add_timeplot_view),
|
||||
|
||||
@@ -2320,6 +2320,85 @@ def workout_comparison_list(request,id=0,message='',successmessage='',
|
||||
except Rower.DoesNotExist:
|
||||
raise Http404("User has no rower instance")
|
||||
|
||||
# List of workouts to compare a selected workout to
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def workout_fusion_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)
|
||||
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))
|
||||
enddate = enddate+datetime.timedelta(days=1)
|
||||
|
||||
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)
|
||||
try:
|
||||
row = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
|
||||
return render(request, 'fusion_list.html',
|
||||
{'id':id,
|
||||
'workout':row,
|
||||
'workouts': workouts,
|
||||
'last_name':u.last_name,
|
||||
'first_name':u.first_name,
|
||||
'message': message,
|
||||
'successmessage':successmessage,
|
||||
'dateform':dateform,
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
})
|
||||
except Rower.DoesNotExist:
|
||||
raise Http404("User has no rower instance")
|
||||
|
||||
# Basic 'EDIT' view of workout
|
||||
def workout_view(request,id=0):
|
||||
try:
|
||||
@@ -5048,7 +5127,7 @@ def workout_fusion_view(request,id1=0,id2=1):
|
||||
'workout2':w2,
|
||||
})
|
||||
|
||||
|
||||
|
||||
form = FusionMetricChoiceForm(instance=w2)
|
||||
|
||||
return render(request, 'fusion.html',
|
||||
|
||||
Reference in New Issue
Block a user