attaching workout to planned session
This commit is contained in:
@@ -1251,7 +1251,10 @@ def dataprep(rowdatadf,id=0,bands=True,barchart=True,otwpower=True,
|
|||||||
data.to_sql('strokedata',engine,if_exists='append',index=False)
|
data.to_sql('strokedata',engine,if_exists='append',index=False)
|
||||||
except:
|
except:
|
||||||
data.drop(columns=['rhythm'],inplace=True)
|
data.drop(columns=['rhythm'],inplace=True)
|
||||||
|
try:
|
||||||
data.to_sql('strokedata',engine,if_exists='append',index=False)
|
data.to_sql('strokedata',engine,if_exists='append',index=False)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
|
|||||||
@@ -2452,7 +2452,7 @@ class WorkoutForm(ModelForm):
|
|||||||
# duration = forms.TimeInput(format='%H:%M:%S.%f')
|
# duration = forms.TimeInput(format='%H:%M:%S.%f')
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Workout
|
model = Workout
|
||||||
fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece','duplicate']
|
fields = ['name','date','starttime','timezone','duration','distance','workouttype','boattype','weightcategory','notes','rankingpiece','duplicate','plannedsession']
|
||||||
widgets = {
|
widgets = {
|
||||||
'date': AdminDateWidget(),
|
'date': AdminDateWidget(),
|
||||||
'notes': forms.Textarea,
|
'notes': forms.Textarea,
|
||||||
@@ -2475,6 +2475,21 @@ class WorkoutForm(ModelForm):
|
|||||||
else:
|
else:
|
||||||
self.fields['private'].initial = True
|
self.fields['private'].initial = True
|
||||||
|
|
||||||
|
workout = self.instance
|
||||||
|
sps = PlannedSession.objects.filter(
|
||||||
|
rower__in=[workout.user],
|
||||||
|
startdate__lte=workout.date,
|
||||||
|
enddate__gte=workout.date,
|
||||||
|
).order_by("preferreddate","startdate","enddate").exclude(
|
||||||
|
sessiontype='race')
|
||||||
|
|
||||||
|
if not sps:
|
||||||
|
del self.fields['plannedsession']
|
||||||
|
else:
|
||||||
|
self.fields['plannedsession'].queryset = sps
|
||||||
|
else:
|
||||||
|
del self.fields['plannedsession']
|
||||||
|
|
||||||
# Used for the rowing physics calculations
|
# Used for the rowing physics calculations
|
||||||
class AdvancedWorkoutForm(ModelForm):
|
class AdvancedWorkoutForm(ModelForm):
|
||||||
quick_calc = forms.BooleanField(initial=True,required=False)
|
quick_calc = forms.BooleanField(initial=True,required=False)
|
||||||
|
|||||||
@@ -610,6 +610,7 @@ def handle_calctrimp(id,
|
|||||||
intensityfactor = normp/float(ftp)
|
intensityfactor = normp/float(ftp)
|
||||||
tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp))
|
tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp))
|
||||||
|
|
||||||
|
|
||||||
if sex == 'male':
|
if sex == 'male':
|
||||||
f = 1.92
|
f = 1.92
|
||||||
else:
|
else:
|
||||||
@@ -646,6 +647,24 @@ def handle_calctrimp(id,
|
|||||||
if not np.isfinite(normw):
|
if not np.isfinite(normw):
|
||||||
normw = 0
|
normw = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
dum = int(tss)
|
||||||
|
except ValueError:
|
||||||
|
tss = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
dum = int(normp)
|
||||||
|
except ValueError:
|
||||||
|
normp = 0
|
||||||
|
try:
|
||||||
|
dump = int(trimp)
|
||||||
|
except ValueError:
|
||||||
|
trimp = 0
|
||||||
|
try:
|
||||||
|
dump = int(hrtss)
|
||||||
|
except ValueError:
|
||||||
|
hrtss = 0
|
||||||
|
|
||||||
query = 'UPDATE rowers_workout SET rscore = {tss}, normp = {normp}, trimp={trimp}, hrtss={hrtss}, normv={normv}, normw={normw} WHERE id={id}'.format(
|
query = 'UPDATE rowers_workout SET rscore = {tss}, normp = {normp}, trimp={trimp}, hrtss={hrtss}, normv={normv}, normw={normw} WHERE id={id}'.format(
|
||||||
tss = int(tss),
|
tss = int(tss),
|
||||||
normp = int(normp),
|
normp = int(normp),
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ $('#id_workouttype').change();
|
|||||||
{{ form.as_table }}
|
{{ form.as_table }}
|
||||||
</table>
|
</table>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input class="button green" type="submit" value="Save">
|
<input type="submit" value="Save">
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li class="grid_2">
|
<li class="grid_2">
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ from django.core.cache import cache
|
|||||||
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
from django_mailbox.models import Message,Mailbox,MessageAttachment
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Utility to get stroke data in a JSON response
|
# Utility to get stroke data in a JSON response
|
||||||
class JSONResponse(HttpResponse):
|
class JSONResponse(HttpResponse):
|
||||||
def __init__(self, data, **kwargs):
|
def __init__(self, data, **kwargs):
|
||||||
@@ -3369,6 +3370,11 @@ def addmanual_view(request):
|
|||||||
avghr = metricsform.cleaned_data['avghr']
|
avghr = metricsform.cleaned_data['avghr']
|
||||||
avgpwr = metricsform.cleaned_data['avgpwr']
|
avgpwr = metricsform.cleaned_data['avgpwr']
|
||||||
avgspm = metricsform.cleaned_data['avgspm']
|
avgspm = metricsform.cleaned_data['avgspm']
|
||||||
|
try:
|
||||||
|
ps = form.cleaned_data['plannedsession']
|
||||||
|
except KeyError:
|
||||||
|
ps = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
boattype = request.POST['boattype']
|
boattype = request.POST['boattype']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -3426,10 +3432,14 @@ def addmanual_view(request):
|
|||||||
w.privacy = privacy
|
w.privacy = privacy
|
||||||
w.weightcategory = weightcategory
|
w.weightcategory = weightcategory
|
||||||
w.notes = notes
|
w.notes = notes
|
||||||
|
w.plannedsession = ps
|
||||||
w.name = name
|
w.name = name
|
||||||
w.workouttype = workouttype
|
w.workouttype = workouttype
|
||||||
w.boattype = boattype
|
w.boattype = boattype
|
||||||
w.save()
|
w.save()
|
||||||
|
if ps:
|
||||||
|
add_workouts_plannedsession([w],ps,w.user)
|
||||||
|
|
||||||
messages.info(request,'New workout created')
|
messages.info(request,'New workout created')
|
||||||
else:
|
else:
|
||||||
return render(request,'manualadd.html',
|
return render(request,'manualadd.html',
|
||||||
@@ -9970,6 +9980,11 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
notes = form.cleaned_data['notes']
|
notes = form.cleaned_data['notes']
|
||||||
thetimezone = form.cleaned_data['timezone']
|
thetimezone = form.cleaned_data['timezone']
|
||||||
|
|
||||||
|
try:
|
||||||
|
ps = form.cleaned_data['plannedsession']
|
||||||
|
except KeyError:
|
||||||
|
ps = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
boattype = request.POST['boattype']
|
boattype = request.POST['boattype']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -10031,10 +10046,17 @@ def workout_edit_view(request,id=0,message="",successmessage=""):
|
|||||||
row.privacy = privacy
|
row.privacy = privacy
|
||||||
row.rankingpiece = rankingpiece
|
row.rankingpiece = rankingpiece
|
||||||
row.timezone = thetimezone
|
row.timezone = thetimezone
|
||||||
|
row.plannedsession = ps
|
||||||
|
|
||||||
try:
|
try:
|
||||||
row.save()
|
row.save()
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if ps:
|
||||||
|
add_workouts_plannedsession([row],ps,row.user)
|
||||||
|
|
||||||
|
|
||||||
# change data in csv file
|
# change data in csv file
|
||||||
|
|
||||||
r = rdata(row.csvfilename)
|
r = rdata(row.csvfilename)
|
||||||
|
|||||||
Reference in New Issue
Block a user