Private
Public Access
1
0

Merge branch 'release/v3.55'

This commit is contained in:
Sander Roosendaal
2017-08-10 15:35:59 +02:00
11 changed files with 542 additions and 136 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')
+2 -2
View File
@@ -1269,13 +1269,13 @@ def datafusion(id1,id2,columns,offset):
return df return df
def fix_newtons(id=0): def fix_newtons(id=0,limit=3000):
# rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False) # rowdata,row = getrowdata_db(id=id,doclean=False,convertnewtons=False)
rowdata = getsmallrowdata_db(['peakforce'],ids=[id],doclean=False) rowdata = getsmallrowdata_db(['peakforce'],ids=[id],doclean=False)
try: try:
#avgforce = rowdata['averageforce'] #avgforce = rowdata['averageforce']
peakforce = rowdata['peakforce'] peakforce = rowdata['peakforce']
if peakforce.mean() > 3000: if peakforce.mean() > limit:
w = Workout.objects.get(id=id) w = Workout.objects.get(id=id)
print "fixing ",id print "fixing ",id
rowdata = rdata(w.csvfilename) rowdata = rdata(w.csvfilename)
+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())
+6 -2
View File
@@ -1809,7 +1809,11 @@ def interactive_flex_chart2(id=0,promember=0,
rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True, rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True,
workstrokesonly=workstrokesonly) workstrokesonly=workstrokesonly)
if rowdata.empty:
rowdata = dataprep.getsmallrowdata_db(columns,ids=[id],doclean=True,
workstrokesonly=False)
workstrokesonly=False
try: try:
tests = rowdata[yparam2] tests = rowdata[yparam2]
except KeyError: except KeyError:
@@ -2250,7 +2254,7 @@ def interactive_flex_chart2(id=0,promember=0,
js_resources = INLINE.render_js() js_resources = INLINE.render_js()
css_resources = INLINE.render_css() css_resources = INLINE.render_css()
return [script,div,js_resources,css_resources] return [script,div,js_resources,css_resources,workstrokesonly]
def interactive_bar_chart(id=0,promember=0): def interactive_bar_chart(id=0,promember=0):
+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'),
)
+9
View File
@@ -5,6 +5,15 @@ import colorsys
lbstoN = 4.44822 lbstoN = 4.44822
def absolute(request):
urls = {
'ABSOLUTE_ROOT': request.build_absolute_uri('/')[:-1].strip("/"),
'ABSOLUTE_ROOT_URL': request.build_absolute_uri('/').strip("/"),
'PATH':request.build_absolute_uri(),
}
return urls
def trcolors(r1,g1,b1,r2,g2,b2): def trcolors(r1,g1,b1,r2,g2,b2):
r1 = r1/255. r1 = r1/255.
r2 = r2/255. r2 = r2/255.
+199 -21
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
@@ -273,7 +274,7 @@ def splitstdata(lijst):
from utils import ( from utils import (
geo_distance,serialize_list,deserialize_list,uniqify, geo_distance,serialize_list,deserialize_list,uniqify,
str2bool,range_to_color_hex str2bool,range_to_color_hex,absolute
) )
import datautils import datautils
@@ -2106,10 +2107,13 @@ def cum_flex(request,theuser=0,
workouttypes = options['workouttypes'] workouttypes = options['workouttypes']
includereststrokes = options['includereststrokes'] includereststrokes = options['includereststrokes']
waterboattype = options['waterboattype']
workstrokesonly = not includereststrokes workstrokesonly = not includereststrokes
checktypes = ['water','rower','dynamic','slides','skierg', checktypes = ['water','rower','dynamic','slides','skierg',
'paddle','snow','coastal','other'] 'paddle','snow','coastal','other']
waterboattype = ['1x','2x','2-','4x','4-','8+']
if deltadays>0: if deltadays>0:
startdate = enddate-datetime.timedelta(days=int(deltadays)) startdate = enddate-datetime.timedelta(days=int(deltadays))
@@ -2181,7 +2185,8 @@ def cum_flex(request,theuser=0,
for type in checktypes: for type in checktypes:
if optionsform.cleaned_data[type]: if optionsform.cleaned_data[type]:
workouttypes.append(type) workouttypes.append(type)
options = { options = {
'includereststrokes':includereststrokes, 'includereststrokes':includereststrokes,
'workouttypes':workouttypes, 'workouttypes':workouttypes,
@@ -3169,19 +3174,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 +3260,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 +3295,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 +3312,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 +3436,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 +3446,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 +3509,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 +3538,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 +3559,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 +3810,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 +3869,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 +3930,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 +3954,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 +3975,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),
}) })
@@ -4005,6 +4163,7 @@ def workouts_view(request,message='',successmessage='',
startdate=timezone.now()-datetime.timedelta(days=365), startdate=timezone.now()-datetime.timedelta(days=365),
enddate=timezone.now()+datetime.timedelta(days=1), enddate=timezone.now()+datetime.timedelta(days=1),
teamid=0): teamid=0):
request.session['referer'] = absolute(request)['PATH']
try: try:
r = getrower(request.user) r = getrower(request.user)
except Rower.DoesNotExist: except Rower.DoesNotExist:
@@ -4287,6 +4446,8 @@ def workout_fusion_list(request,id=0,message='',successmessage='',
# Basic 'EDIT' view of workout # Basic 'EDIT' view of workout
def workout_view(request,id=0): def workout_view(request,id=0):
request.session['referer'] = absolute(request)['PATH']
try: try:
# check if valid ID exists (workout exists) # check if valid ID exists (workout exists)
row = Workout.objects.get(id=id) row = Workout.objects.get(id=id)
@@ -5582,7 +5743,7 @@ def workout_flexchart3_view(request,*args,**kwargs):
# create interactive plot # create interactive plot
try: try:
script,div,js_resources,css_resources = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1, script,div,js_resources,css_resources,workstrokesonly = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
yparam2=yparam2, yparam2=yparam2,
promember=promember,plottype=plottype, promember=promember,plottype=plottype,
workstrokesonly=workstrokesonly) workstrokesonly=workstrokesonly)
@@ -5944,6 +6105,8 @@ def workout_comment_view(request,id=0):
@login_required() @login_required()
def workout_edit_view(request,id=0,message="",successmessage=""): def workout_edit_view(request,id=0,message="",successmessage=""):
request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE request.session[translation.LANGUAGE_SESSION_KEY] = USER_LANGUAGE
request.session['referer'] = absolute(request)['PATH']
try: try:
# check if valid ID exists (workout exists) # check if valid ID exists (workout exists)
@@ -7576,10 +7739,12 @@ def workout_delete_confirm_view(request, id=0):
if (checkworkoutuser(request.user,row)==False): if (checkworkoutuser(request.user,row)==False):
raise PermissionDenied("You are not allowed to delete this workout") raise PermissionDenied("You are not allowed to delete this workout")
else: else:
url = request.META.get('HTTP_REFERER','/')
return render(request,'workout_delete_confirm.html', return render(request,'workout_delete_confirm.html',
{'id':int(id), {'id':int(id),
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
'workout':row}) 'workout':row,
'url':url})
except Workout.DoesNotExist: except Workout.DoesNotExist:
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
@@ -7596,8 +7761,12 @@ def workout_delete_view(request,id=0):
row.delete() row.delete()
messages.info(request,'Workout deleted') messages.info(request,'Workout deleted')
url = reverse(workouts_view) try:
url = request.session['referer']
except KeyError:
url = reverse(workouts_view)
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
except Workout.DoesNotExist: except Workout.DoesNotExist:
@@ -7612,10 +7781,16 @@ def graph_delete_confirm_view(request, id=0):
if (checkworkoutuser(request.user,row)==False): if (checkworkoutuser(request.user,row)==False):
raise PermissionDenied("You are not allowed to delete this workout") raise PermissionDenied("You are not allowed to delete this workout")
else: else:
try:
url = request.session['referer']
except KeyError:
url = '/rowers/list-graphs'
request.session['referer'] = url
return render(request,'graphimage_delete_confirm.html', return render(request,'graphimage_delete_confirm.html',
{'id':int(id), {'id':int(id),
'teams':get_my_teams(request.user), 'teams':get_my_teams(request.user),
'graph':img}) 'graph':img,
'url':url})
except Workout.DoesNotExist: except Workout.DoesNotExist:
raise Http404("Workout doesn't exist") raise Http404("Workout doesn't exist")
@@ -7633,8 +7808,10 @@ def graph_delete_view(request,id=0):
else: else:
img.delete() img.delete()
messages.info(request,'Graph deleted') messages.info(request,'Graph deleted')
try:
url = reverse(workouts_view) url = request.session['referer']
except KeyError:
url = reverse(graphs_view)
return HttpResponseRedirect(url) return HttpResponseRedirect(url)
except GraphImage.DoesNotExist: except GraphImage.DoesNotExist:
@@ -7645,6 +7822,7 @@ def graph_delete_view(request,id=0):
# A page with all the recent graphs (searchable on workout name) # A page with all the recent graphs (searchable on workout name)
@login_required() @login_required()
def graphs_view(request): def graphs_view(request):
request.session['referer'] = reverse(graphs_view)
try: try:
r = getrower(request.user) r = getrower(request.user)
workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime") workouts = Workout.objects.filter(user=r).order_by("-date", "-starttime")