Private
Public Access
1
0

modality and boat type selection working on multiflex

This commit is contained in:
Sander Roosendaal
2017-08-10 13:58:47 +02:00
parent 8156034ae1
commit c74b08d966
5 changed files with 132 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ class UserAdmin(UserAdmin):
inlines = (RowerInline,)
class WorkoutAdmin(admin.ModelAdmin):
list_display = ('date','user','name','workouttype')
list_display = ('date','user','name','workouttype','boattype')
class FavoriteChartAdmin(admin.ModelAdmin):
list_display = ('user','xparam','yparam1','yparam2','plottype','workouttype','reststrokes')

View File

@@ -265,11 +265,15 @@ class IntervalUpdateForm(forms.Form):
boattypes = types.boattypes
workouttypes = types.workouttypes
ww = list(workouttypes)
ww.append(tuple(('all','All')))
workouttypes = tuple(ww)
# form to select modality and boat type for trend flex
class TrendFlexModalForm(forms.Form):
modality = forms.ChoiceField(choices=workouttypes,
label='Workout Type')
label='Workout Type',
initial='all')
waterboattype = forms.MultipleChoiceField(choices=boattypes,
label='Water Boat Type',
initial = ['1x','2x','2-','4x','4-','8+'])

View File

@@ -368,7 +368,7 @@ class Workout(models.Model):
workoutsource = models.CharField(choices=workoutsources,max_length=100,
default='unknown')
boattype = models.CharField(choices=boattypes,max_length=50,
default='1x (single)',
default='1x',
verbose_name = 'Boat Type')
starttime = models.TimeField(blank=True,null=True)
startdatetime = models.DateTimeField(blank=True,null=True)
@@ -405,8 +405,10 @@ class Workout(models.Model):
ownerfirst = self.user.user.first_name
ownerlast = self.user.user.last_name
duration = self.duration
boattype = self.boattype
workouttype = self.workouttype
if workouttype != 'water':
stri = u'{d} {n} {dist}m {duration:%H:%M:%S} {workouttype} {ownerfirst} {ownerlast}'.format(
d = date.strftime('%Y-%m-%d'),
n = name,
@@ -416,6 +418,17 @@ class Workout(models.Model):
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

View File

@@ -12,6 +12,55 @@
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>
@@ -75,7 +124,7 @@
{% csrf_token %}
</div>
<div class="grid_2 omega">
<input name='modality' class="button green" type="submit" value="Submit">
<input name='modalityform' class="button green" type="submit" value="Submit">
</div>
</form>
</div>

View File

@@ -98,7 +98,7 @@ from scipy.signal import savgol_filter
from django.shortcuts import render_to_response
from Cookie import SimpleCookie
from shutil import copyfile
import types
from rowingdata import rower as rrower
from rowingdata import main as rmain
from rowingdata import rowingdata as rrdata
@@ -3376,6 +3376,7 @@ def user_multiflex_select(request,
ploterrorbars = False
if 'startdate' in request.session:
startdate = iso8601.parse_date(request.session['startdate'])
@@ -3384,17 +3385,55 @@ def user_multiflex_select(request,
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)
if dateform.is_valid():
startdate = dateform.cleaned_data['startdate']
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
print 'nootje',enddatestring,request.session['enddate']
else:
dateform = DateRangeForm(initial={
'startdate':startdate,
'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())
enddate = datetime.datetime.combine(enddate,datetime.time(23,59,59))
enddate = enddate+datetime.timedelta(days=1)
@@ -3410,9 +3449,15 @@ def user_multiflex_select(request,
startdate = s
negtypes = []
for b in types.boattypes:
if b[0] not in waterboattype:
negtypes.append(b[0])
workouts = Workout.objects.filter(user=r,
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')
if query:
@@ -3433,7 +3478,10 @@ def user_multiflex_select(request,
'includereststrokes':includereststrokes,
})
modalityform = TrendFlexModalForm()
modalityform = TrendFlexModalForm(initial={
'modality':modality,
'waterboattype':waterboattype
})
messages.info(request,successmessage)
messages.error(request,message)
@@ -3702,7 +3750,7 @@ def multiflex_view(request,userid=0,
clegendy = df['groupval'].min()+clegendx*(df['groupval'].max()-df['groupval'].min())
else:
clegendy = df.index.min()+clegendx*(df.index.max()-df.index.min())
print clegendy
colorlegend = zip(range(6),clegendy,legcolors)