Private
Public Access
1
0

Merge branch 'feature/trendflexmultimodal' into develop

This commit is contained in:
Sander Roosendaal
2017-08-10 14:32:22 +02:00
8 changed files with 491 additions and 122 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ class UserAdmin(UserAdmin):
inlines = (RowerInline,) inlines = (RowerInline,)
class WorkoutAdmin(admin.ModelAdmin): class WorkoutAdmin(admin.ModelAdmin):
list_display = ('date','user','name','workouttype') list_display = ('date','user','name','workouttype','boattype')
class FavoriteChartAdmin(admin.ModelAdmin): class FavoriteChartAdmin(admin.ModelAdmin):
list_display = ('user','xparam','yparam1','yparam2','plottype','workouttype','reststrokes') list_display = ('user','xparam','yparam1','yparam2','plottype','workouttype','reststrokes')
+15 -22
View File
@@ -8,7 +8,7 @@ from django.forms.extras.widgets import SelectDateWidget
from django.utils import timezone,translation from django.utils import timezone,translation
from django.forms import ModelForm from django.forms import ModelForm
import dataprep import dataprep
import types
import datetime import datetime
# login form # login form
@@ -45,18 +45,6 @@ class StrokeDataForm(forms.Form):
# The form used for uploading files # The form used for uploading files
class DocumentsForm(forms.Form): class DocumentsForm(forms.Form):
filetypechoices = (
('csv' , 'Painsled iOS CSV'),
('tcx' , 'TCX'),
('tcxnohr' , 'TCX No HR'),
('rp' , 'RowPro CSV'),
('speedcoach' , 'SpeedCoach GPS CSV'),
('speedcoach2' , 'SpeedCoach GPS 2 CSV'),
('ergdata' , 'ErgData CSV'),
('ergstick' , 'ErgStick CSV'),
('painsleddesktop' , 'Painsled Desktop CSV'),
('zip','Zipped file'),
)
title = forms.CharField(required=False) title = forms.CharField(required=False)
file = forms.FileField(required=True, file = forms.FileField(required=True,
validators=[validate_file_extension]) validators=[validate_file_extension])
@@ -275,15 +263,21 @@ class IntervalUpdateForm(forms.Form):
self.fields['type_%s' % i].widget.attrs['style'] = 'width:156px; height: 22px;' 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') self.fields['intervald_%s' % i].widget = forms.TimeInput(format='%H:%M:%S.%f')
boattypes = ( boattypes = types.boattypes
('1x', '1x (single)'), workouttypes = types.workouttypes
('2x', '2x (double)'), ww = list(workouttypes)
('2-', '2- (pair)'), ww.append(tuple(('all','All')))
('4x', '4x (quad)'), workouttypes = tuple(ww)
('4-', '4- (four)'),
('8+', '8+ (eight)'),
)
# form to select modality and boat type for trend flex
class TrendFlexModalForm(forms.Form):
modality = forms.ChoiceField(choices=workouttypes,
label='Workout Type',
initial='all')
waterboattype = forms.MultipleChoiceField(choices=boattypes,
label='Water Boat Type',
initial = ['1x','2x','2-','4x','4-','8+'])
# This form sets options for the summary stats page # This form sets options for the summary stats page
class StatsOptionsForm(forms.Form): class StatsOptionsForm(forms.Form):
@@ -342,7 +336,6 @@ formaxlabelsmultiflex['workoutid'] = 'Workout'
parchoicesmultiflex = list(sorted(formaxlabelsmultiflex.items(), key = lambda x:x[1])) parchoicesmultiflex = list(sorted(formaxlabelsmultiflex.items(), key = lambda x:x[1]))
from utils import palettes from utils import palettes
#palettechoices = { key:key for key, value in palettes.iteritems() }
palettechoices = tuple((p,p) for p in palettes.keys()) palettechoices = tuple((p,p) for p in palettes.keys())
+29 -57
View File
@@ -22,6 +22,8 @@ import datetime
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from rowers.rows import validate_file_extension from rowers.rows import validate_file_extension
import types
from rowsandall_app.settings import ( from rowsandall_app.settings import (
TWEET_ACCESS_TOKEN_KEY, TWEET_ACCESS_TOKEN_KEY,
TWEET_ACCESS_TOKEN_SECRET, TWEET_ACCESS_TOKEN_SECRET,
@@ -353,53 +355,10 @@ def checkworkoutuser(user,workout):
# Workout # Workout
class Workout(models.Model): class Workout(models.Model):
workouttypes = ( workouttypes = types.workouttypes
('water','On-water'), workoutsources = types.workoutsources
('rower','Indoor Rower'), boattypes = types.boattypes
('skierg','Ski Erg'), privacychoices = types.privacychoices
('dynamic','Dynamic Indoor Rower'),
('slides','Indoor Rower on Slides'),
('paddle','Paddle Adapter'),
('snow','On-snow'),
('coastal','Coastal'),
('other','Other'),
)
workoutsources = (
('strava','strava'),
('concept2','concept2'),
('sporttracks','sporttracks'),
('runkeeper','runkeeper'),
('mapmyfitness','mapmyfitness'),
('csv','painsled'),
('tcx','tcx'),
('rp','rp'),
('mystery','mystery'),
('tcxnohr','tcx (no HR)'),
('rowperfect3','rowperfect3'),
('ergdata','ergdata'),
('boatcoach','boatcoach'),
('bcmike','boatcoach (develop)'),
('painsleddesktop','painsleddesktop'),
('speedcoach','speedcoach'),
('speedcoach2','speedcoach2'),
('ergstick','ergstick'),
('fit','fit'),
('unknown','unknown'))
boattypes = (
('1x', '1x (single)'),
('2x', '2x (double)'),
('2-', '2- (pair)'),
('4x', '4x (quad)'),
('4-', '4- (four)'),
('8+', '8+ (eight)'),
)
privacychoices = (
('private','Private'),
('visible','Visible'),
)
user = models.ForeignKey(Rower) user = models.ForeignKey(Rower)
team = models.ManyToManyField(Team,blank=True) team = models.ManyToManyField(Team,blank=True)
@@ -409,7 +368,7 @@ class Workout(models.Model):
workoutsource = models.CharField(choices=workoutsources,max_length=100, workoutsource = models.CharField(choices=workoutsources,max_length=100,
default='unknown') default='unknown')
boattype = models.CharField(choices=boattypes,max_length=50, boattype = models.CharField(choices=boattypes,max_length=50,
default='1x (single)', default='1x',
verbose_name = 'Boat Type') verbose_name = 'Boat Type')
starttime = models.TimeField(blank=True,null=True) starttime = models.TimeField(blank=True,null=True)
startdatetime = models.DateTimeField(blank=True,null=True) startdatetime = models.DateTimeField(blank=True,null=True)
@@ -446,17 +405,30 @@ class Workout(models.Model):
ownerfirst = self.user.user.first_name ownerfirst = self.user.user.first_name
ownerlast = self.user.user.last_name ownerlast = self.user.user.last_name
duration = self.duration duration = self.duration
boattype = self.boattype
workouttype = self.workouttype workouttype = self.workouttype
stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {ownerfirst} {ownerlast}'.format( if workouttype != 'water':
d = date.strftime('%Y-%m-%d'), stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {ownerfirst} {ownerlast}'.format(
n = name, d = date.strftime('%Y-%m-%d'),
dist = distance, n = name,
duration = duration, dist = distance,
workouttype = workouttype, duration = duration,
ownerfirst = ownerfirst, workouttype = workouttype,
ownerlast = ownerlast, ownerfirst = ownerfirst,
) ownerlast = ownerlast,
)
else:
stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {boattype} {ownerfirst} {ownerlast}'.format(
d = date.strftime('%Y-%m-%d'),
n = name,
dist = distance,
duration = duration,
workouttype = workouttype,
boattype=boattype,
ownerfirst = ownerfirst,
ownerlast = ownerlast,
)
return stri return stri
+70 -4
View File
@@ -13,6 +13,55 @@
checkboxes[i].checked = source.checked; checkboxes[i].checked = source.checked;
} }
} }
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
var hidden = $("#id_waterboattype");
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
if (Value=='water') {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script> </script>
@@ -23,21 +72,38 @@
<h3>{{ team.name }} Team Workouts</h3> <h3>{{ team.name }} Team Workouts</h3>
</div> </div>
<div class="grid_12 alpha"> <div class="grid_12 alpha">
<div class="grid_4 alpha"> <div class="grid_6 alpha">
{% if team %} {% if team %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/team/{{ team.id }}/" method="post"> <form enctype="multipart/form-data" action="/rowers/team-compare-select/team/{{ team.id }}/" method="post">
{% else %} {% else %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/" method="post"> <form enctype="multipart/form-data" action="/rowers/team-compare-select/" method="post">
{% endif %} {% endif %}
<div class="grid_4 alpha">
<table> <table>
{{ dateform.as_table }} {{ dateform.as_table }}
</table> </table>
{% csrf_token %} {% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit">
</div> </div>
<div class="grid_2"> </form>
<input name='daterange' class="button green" type="submit" value="Submit"> </form> {% if team %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/team/{{ team.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/team-compare-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div> </div>
<div class="grid_5 prefix_1 omega"> <div class="grid_5 prefix_1 omega">
{% if team %} {% if team %}
+82 -14
View File
@@ -12,6 +12,55 @@
checkboxes[i].checked = source.checked; checkboxes[i].checked = source.checked;
} }
} }
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
var hidden = $("#id_waterboattype");
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
if (Value=='water') {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script> </script>
@@ -45,23 +94,42 @@
</div> </div>
</div> </div>
<div class="grid_12 alpha"> <div class="grid_12 alpha">
<div class="grid_4 alpha"> <div class="grid_6 alpha">
{% if theuser %} {% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/user/{{ theuser.id }}/" method="post"> <form enctype="multipart/form-data" action="/rowers/user-boxplot-select/user/{{ theuser.id }}/" method="post">
{% else %} {% else %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post"> <form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post">
{% endif %} {% endif %}
<div class="grid_4 alpha">
<table>
{{ dateform.as_table }} <table>
</table> {{ dateform.as_table }}
{% csrf_token %} </table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit">
</div>
</form>
{% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/user/{{ theuser.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/user-boxplot-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div> </div>
<div class="grid_2">
<input name='daterange' class="button green" type="submit" value="Submit"> </form> <div class="grid_5 prefix_1 omega">
</div>
<div class="grid_5 prefix_1 omega">
<form id="searchform" action="" <form id="searchform" action=""
method="get" accept-charset="utf-8"> method="get" accept-charset="utf-8">
<div class="grid_3 prefix_1 alpha"> <div class="grid_3 prefix_1 alpha">
+82 -13
View File
@@ -12,6 +12,55 @@
checkboxes[i].checked = source.checked; checkboxes[i].checked = source.checked;
} }
} }
</script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(function() {
// Get the form fields and hidden div
var modality = $("#id_modality");
var hidden = $("#id_waterboattype");
// Hide the fields.
// Use JS to do this in case the user doesn't have JS
// enabled.
hidden.hide();
// Setup an event listener for when the state of the
// checkbox changes.
modality.change(function() {
// Check to see if the checkbox is checked.
// If it is, show the fields and populate the input.
// If not, hide the fields.
var Value = modality.val();
if (Value=='water') {
// Show the hidden fields.
hidden.show();
} else {
// Make sure that the hidden fields are indeed
// hidden.
hidden.hide();
// You may also want to clear the value of the
// hidden fields here. Just in case somebody
// shows the fields, enters data to them and then
// unticks the checkbox.
//
// This would do the job:
//
// $("#hidden_field").val("");
}
});
});
</script> </script>
@@ -45,22 +94,42 @@
</div> </div>
</div> </div>
<div class="grid_12 alpha"> <div class="grid_12 alpha">
<div class="grid_4 alpha"> <div class="grid_6 alpha">
{% if theuser %} {% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-multiflex-select/user/{{ theuser.id }}/" method="post"> <form enctype="multipart/form-data" action="/rowers/user-multiflex-select/user/{{ theuser.id }}/" method="post">
{% else %} {% else %}
<form enctype="multipart/form-data" action="/rowers/user-multiflex-select/" method="post"> <form enctype="multipart/form-data" action="/rowers/user-multiflex-select/" method="post">
{% endif %} {% endif %}
<div class="grid_4 alpha">
<table>
{{ dateform.as_table }} <table>
</table> {{ dateform.as_table }}
{% csrf_token %} </table>
</div> {% csrf_token %}
<div class="grid_2"> </div>
<input name='daterange' class="button green" type="submit" value="Submit"> </form> <div class="grid_2 omega">
<input name='daterange' class="button green" type="submit" value="Submit">
</div>
</form>
{% if theuser %}
<form enctype="multipart/form-data" action="/rowers/user-multiflex-select/user/{{ theuser.id }}/" method="post">
{% else %}
<form enctype="multipart/form-data" action="/rowers/user-multiflex-select/" method="post">
{% endif %}
<div class="grid_4 alpha">
<table>
{{ modalityform.as_table }}
</table>
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div> </div>
<div class="grid_5 prefix_1 omega"> <div class="grid_5 prefix_1 omega">
<form id="searchform" action="" <form id="searchform" action=""
method="get" accept-charset="utf-8"> method="get" accept-charset="utf-8">
+47
View File
@@ -0,0 +1,47 @@
workouttypes = (
('water','On-water'),
('rower','Indoor Rower'),
('skierg','Ski Erg'),
('dynamic','Dynamic Indoor Rower'),
('slides','Indoor Rower on Slides'),
('paddle','Paddle Adapter'),
('snow','On-snow'),
('coastal','Coastal'),
('other','Other'),
)
workoutsources = (
('strava','strava'),
('concept2','concept2'),
('sporttracks','sporttracks'),
('runkeeper','runkeeper'),
('mapmyfitness','mapmyfitness'),
('csv','painsled'),
('tcx','tcx'),
('rp','rp'),
('mystery','mystery'),
('tcxnohr','tcx (no HR)'),
('rowperfect3','rowperfect3'),
('ergdata','ergdata'),
('boatcoach','boatcoach'),
('bcmike','boatcoach (develop)'),
('painsleddesktop','painsleddesktop'),
('speedcoach','speedcoach'),
('speedcoach2','speedcoach2'),
('ergstick','ergstick'),
('fit','fit'),
('unknown','unknown'))
boattypes = (
('1x', '1x (single)'),
('2x', '2x (double)'),
('2-', '2- (pair)'),
('4x', '4x (quad)'),
('4-', '4- (four)'),
('8+', '8+ (eight)'),
)
privacychoices = (
('private','Private'),
('visible','Visible'),
)
+165 -11
View File
@@ -36,6 +36,7 @@ from rowers.forms import (
RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm, RegistrationFormUniqueEmail,CNsummaryForm,UpdateWindForm,
UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm, UpdateStreamForm,WorkoutMultipleCompareForm,ChartParamChoiceForm,
FusionMetricChoiceForm,BoxPlotChoiceForm,MultiFlexChoiceForm, FusionMetricChoiceForm,BoxPlotChoiceForm,MultiFlexChoiceForm,
TrendFlexModalForm,
) )
from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart from rowers.models import Workout, User, Rower, WorkoutForm,FavoriteChart
from rowers.models import ( from rowers.models import (
@@ -97,7 +98,7 @@ from scipy.signal import savgol_filter
from django.shortcuts import render_to_response from django.shortcuts import render_to_response
from Cookie import SimpleCookie from Cookie import SimpleCookie
from shutil import copyfile from shutil import copyfile
import types
from rowingdata import rower as rrower from rowingdata import rower as rrower
from rowingdata import main as rmain from rowingdata import main as rmain
from rowingdata import rowingdata as rrdata from rowingdata import rowingdata as rrdata
@@ -3169,19 +3170,67 @@ def team_comparison_select(request,
except Rower.DoesNotExist: except Rower.DoesNotExist:
raise Http404("Rower doesn't exist") raise Http404("Rower doesn't exist")
if 'startdate' in request.session:
startdate = iso8601.parse_date(request.session['startdate'])
if request.method == 'POST': if 'enddate' in request.session:
enddate = iso8601.parse_date(request.session['enddate'])
if 'waterboattype' in request.session:
waterboattype = request.session['waterboattype']
else:
waterboattype = ['1x','2x','2-','4x','4-','8+']
if 'modalities' in request.session:
modalities = request.session['modalities']
if len(modalities) > 1:
modality = 'all'
else:
modality = modalities[0]
else:
modalities = [m[0] for m in types.workouttypes]
if request.method == 'POST' and 'daterange' in request.POST:
dateform = DateRangeForm(request.POST) dateform = DateRangeForm(request.POST)
if dateform.is_valid(): if dateform.is_valid():
startdate = dateform.cleaned_data['startdate'] startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate'] enddate = dateform.cleaned_data['enddate']
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
else: else:
dateform = DateRangeForm(initial={ dateform = DateRangeForm(initial={
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
}) })
if request.method == 'POST' and 'modality' in request.POST:
modalityform = TrendFlexModalForm(request.POST)
if modalityform.is_valid():
modality = modalityform.cleaned_data['modality']
waterboattype = modalityform.cleaned_data['waterboattype']
if modality == 'all':
modalities = [m[0] for m in types.workouttypes]
else:
modalities = [modality]
if modality != 'water':
waterboattype = [b[0] for b in types.boattypes]
request.session['modalities'] = modalities
request.session['waterboattype'] = waterboattype
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
startdate = datetime.datetime.combine(startdate,datetime.time()) startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
enddate = enddate+datetime.timedelta(days=1) enddate = enddate+datetime.timedelta(days=1)
@@ -3207,18 +3256,21 @@ def team_comparison_select(request,
if theteam and (theteam.viewing == 'allmembers' or theteam.manager == request.user): if theteam and (theteam.viewing == 'allmembers' or theteam.manager == request.user):
workouts = Workout.objects.filter(team=theteam, workouts = Workout.objects.filter(team=theteam,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime") startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
elif theteam and theteam.viewing == 'coachonly': elif theteam and theteam.viewing == 'coachonly':
workouts = Workout.objects.filter(team=theteam,user=r, workouts = Workout.objects.filter(team=theteam,user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date","-starttime") startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date","-starttime").exclude(boattype__in=negtypes)
else: else:
theteam = None theteam = None
workouts = Workout.objects.filter(user=r, workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime") startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
query = request.GET.get('q') query = request.GET.get('q')
if query: if query:
@@ -3239,6 +3291,11 @@ def team_comparison_select(request,
theid = 0 theid = 0
chartform = ChartParamChoiceForm(initial={'teamid':0}) chartform = ChartParamChoiceForm(initial={'teamid':0})
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype
})
messages.info(request,successmessage) messages.info(request,successmessage)
messages.error(request,message) messages.error(request,message)
@@ -3251,6 +3308,7 @@ def team_comparison_select(request,
'team':theteam, 'team':theteam,
'form':form, 'form':form,
'chartform':chartform, 'chartform':chartform,
'modalityform':modalityform,
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
}) })
@@ -3374,6 +3432,7 @@ def user_multiflex_select(request,
except: except:
ploterrorbars = False ploterrorbars = False
if 'startdate' in request.session: if 'startdate' in request.session:
startdate = iso8601.parse_date(request.session['startdate']) startdate = iso8601.parse_date(request.session['startdate'])
@@ -3383,17 +3442,54 @@ def user_multiflex_select(request,
enddate = iso8601.parse_date(request.session['enddate']) enddate = iso8601.parse_date(request.session['enddate'])
if request.method == 'POST': if 'waterboattype' in request.session:
waterboattype = request.session['waterboattype']
else:
waterboattype = ['1x','2x','2-','4x','4-','8+']
if 'modalities' in request.session:
modalities = request.session['modalities']
if len(modalities) > 1:
modality = 'all'
else:
modality = modalities[0]
else:
modalities = [m[0] for m in types.workouttypes]
if request.method == 'POST' and 'daterange' in request.POST:
dateform = DateRangeForm(request.POST) dateform = DateRangeForm(request.POST)
if dateform.is_valid(): if dateform.is_valid():
startdate = dateform.cleaned_data['startdate'] startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate'] enddate = dateform.cleaned_data['enddate']
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
else: else:
dateform = DateRangeForm(initial={ dateform = DateRangeForm(initial={
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
}) })
if request.method == 'POST' and 'modality' in request.POST:
modalityform = TrendFlexModalForm(request.POST)
if modalityform.is_valid():
modality = modalityform.cleaned_data['modality']
waterboattype = modalityform.cleaned_data['waterboattype']
if modality == 'all':
modalities = [m[0] for m in types.workouttypes]
else:
modalities = [modality]
if modality != 'water':
waterboattype = [b[0] for b in types.boattypes]
request.session['modalities'] = modalities
request.session['waterboattype'] = waterboattype
startdate = datetime.datetime.combine(startdate,datetime.time()) startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
enddate = enddate+datetime.timedelta(days=1) enddate = enddate+datetime.timedelta(days=1)
@@ -3409,9 +3505,15 @@ def user_multiflex_select(request,
startdate = s startdate = s
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
workouts = Workout.objects.filter(user=r, workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime") startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
query = request.GET.get('q') query = request.GET.get('q')
if query: if query:
@@ -3432,6 +3534,11 @@ def user_multiflex_select(request,
'includereststrokes':includereststrokes, 'includereststrokes':includereststrokes,
}) })
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype
})
messages.info(request,successmessage) messages.info(request,successmessage)
messages.error(request,message) messages.error(request,message)
@@ -3448,6 +3555,7 @@ def user_multiflex_select(request,
'theuser':user, 'theuser':user,
'form':form, 'form':form,
'chartform':chartform, 'chartform':chartform,
'modalityform':modalityform,
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
}) })
@@ -3698,7 +3806,7 @@ def multiflex_view(request,userid=0,
clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min()) clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min())
else: else:
clegendy = df.index.min()+clegendx*(df.index.max()-df.index.min()) clegendy = df.index.min()+clegendx*(df.index.max()-df.index.min())
print clegendy
colorlegend = zip(range(6),clegendy,legcolors) colorlegend = zip(range(6),clegendy,legcolors)
@@ -3757,17 +3865,53 @@ def user_boxplot_select(request,
enddate = iso8601.parse_date(request.session['enddate']) enddate = iso8601.parse_date(request.session['enddate'])
if request.method == 'POST': if 'waterboattype' in request.session:
waterboattype = request.session['waterboattype']
else:
waterboattype = ['1x','2x','2-','4x','4-','8+']
if 'modalities' in request.session:
modalities = request.session['modalities']
if len(modalities) > 1:
modality = 'all'
else:
modality = modalities[0]
else:
modalities = [m[0] for m in types.workouttypes]
if request.method == 'POST' and 'daterange' in request.POST:
dateform = DateRangeForm(request.POST) dateform = DateRangeForm(request.POST)
if dateform.is_valid(): if dateform.is_valid():
startdate = dateform.cleaned_data['startdate'] startdate = dateform.cleaned_data['startdate']
enddate = dateform.cleaned_data['enddate'] enddate = dateform.cleaned_data['enddate']
startdatestring = startdate.strftime('%Y-%m-%d')
enddatestring = enddate.strftime('%Y-%m-%d')
request.session['startdate'] = startdatestring
request.session['enddate'] = enddatestring
else: else:
dateform = DateRangeForm(initial={ dateform = DateRangeForm(initial={
'startdate':startdate, 'startdate':startdate,
'enddate':enddate, 'enddate':enddate,
}) })
if request.method == 'POST' and 'modality' in request.POST:
modalityform = TrendFlexModalForm(request.POST)
if modalityform.is_valid():
modality = modalityform.cleaned_data['modality']
waterboattype = modalityform.cleaned_data['waterboattype']
if modality == 'all':
modalities = [m[0] for m in types.workouttypes]
else:
modalities = [modality]
if modality != 'water':
waterboattype = [b[0] for b in types.boattypes]
request.session['modalities'] = modalities
request.session['waterboattype'] = waterboattype
startdate = datetime.datetime.combine(startdate,datetime.time()) startdate = datetime.datetime.combine(startdate,datetime.time())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59)) enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
enddate = enddate+datetime.timedelta(days=1) enddate = enddate+datetime.timedelta(days=1)
@@ -3782,10 +3926,15 @@ def user_boxplot_select(request,
enddate = startdate enddate = startdate
startdate = s startdate = s
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
workouts = Workout.objects.filter(user=r, workouts = Workout.objects.filter(user=r,
startdatetime__gte=startdate, startdatetime__gte=startdate,
startdatetime__lte=enddate).order_by("-date", "-starttime") startdatetime__lte=enddate,
workouttype__in=modalities).order_by("-date", "-starttime").exclude(boattype__in=negtypes)
query = request.GET.get('q') query = request.GET.get('q')
if query: if query:
@@ -3801,6 +3950,10 @@ def user_boxplot_select(request,
form.fields["workouts"].queryset = workouts form.fields["workouts"].queryset = workouts
chartform = BoxPlotChoiceForm() chartform = BoxPlotChoiceForm()
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype
})
messages.info(request,successmessage) messages.info(request,successmessage)
messages.error(request,message) messages.error(request,message)
@@ -3818,6 +3971,7 @@ def user_boxplot_select(request,
'theuser':user, 'theuser':user,
'form':form, 'form':form,
'chartform':chartform, 'chartform':chartform,
'modalityform':modalityform,
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
}) })