working on low level plannedsession
This commit is contained in:
@@ -36,7 +36,7 @@ from rowingdata import (
|
|||||||
summarydata, get_file_type,
|
summarydata, get_file_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
from rowers.metrics import axes
|
from rowers.metrics import axes,calc_trimp
|
||||||
from async_messages import messages as a_messages
|
from async_messages import messages as a_messages
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -2212,3 +2212,40 @@ def dataprep(rowdatadf, id=0, bands=True, barchart=True, otwpower=True,
|
|||||||
conn.close()
|
conn.close()
|
||||||
engine.dispose()
|
engine.dispose()
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def workout_trimp(workout):
|
||||||
|
r = workout.user
|
||||||
|
df,row = getrowdata_db(id=workout.id)
|
||||||
|
df = clean_df_stats(df)
|
||||||
|
if df.empty:
|
||||||
|
df,row = getrowdata_db(id=workout.id)
|
||||||
|
df = clean_df_stats(df,workstrokesonly=False)
|
||||||
|
trimp = calc_trimp(df,r.sex,r.max,r.rest)
|
||||||
|
trimp = int(trimp)
|
||||||
|
|
||||||
|
return trimp
|
||||||
|
|
||||||
|
def workout_rscore(w):
|
||||||
|
r = workout.user
|
||||||
|
df,row = getrowdata_db(id=workout.id)
|
||||||
|
df = clean_df_stats(df)
|
||||||
|
if df.empty:
|
||||||
|
df,row = getrowdata_db(id=workout.id)
|
||||||
|
df = clean_df_stats(df,workstrokesonly=False)
|
||||||
|
|
||||||
|
duration = df['time'].max()-df['time'].min()
|
||||||
|
duration /= 1.0e3
|
||||||
|
pwr4 = df['power']**(4.0)
|
||||||
|
normp = (pwr4.mean())**(0.25)
|
||||||
|
if not np.isnan(normp):
|
||||||
|
ftp = float(r.ftp)
|
||||||
|
if w.workouttype in ('water','coastal'):
|
||||||
|
ftp = ftp*(100.-r.otwslack)/100.
|
||||||
|
|
||||||
|
intensityfactor = df['power'].mean()/float(ftp)
|
||||||
|
intensityfactor = normp/float(ftp)
|
||||||
|
tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp))
|
||||||
|
else:
|
||||||
|
tss = 0
|
||||||
|
|
||||||
|
return tss
|
||||||
|
|||||||
@@ -307,6 +307,7 @@ This value should be fairly constant across all stroke rates.""",
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def calc_trimp(df,sex,hrmax,hrmin):
|
def calc_trimp(df,sex,hrmax,hrmin):
|
||||||
if sex == 'male':
|
if sex == 'male':
|
||||||
f = 1.92
|
f = 1.92
|
||||||
@@ -321,6 +322,7 @@ def calc_trimp(df,sex,hrmax,hrmin):
|
|||||||
|
|
||||||
return trimp
|
return trimp
|
||||||
|
|
||||||
|
|
||||||
def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
def getagegrouprecord(age,sex='male',weightcategory='hwt',
|
||||||
distance=2000,duration=None,indf=pd.DataFrame()):
|
distance=2000,duration=None,indf=pd.DataFrame()):
|
||||||
|
|
||||||
|
|||||||
@@ -761,7 +761,9 @@ class PlannedSession(models.Model):
|
|||||||
|
|
||||||
sessionmodechoices = (
|
sessionmodechoices = (
|
||||||
('distance','Distance'),
|
('distance','Distance'),
|
||||||
('time','Time')
|
('time','Time'),
|
||||||
|
('rScore','rScore'),
|
||||||
|
('TRIMP','TRIMP'),
|
||||||
)
|
)
|
||||||
|
|
||||||
criteriumchoices = (
|
criteriumchoices = (
|
||||||
@@ -779,7 +781,8 @@ class PlannedSession(models.Model):
|
|||||||
sessionunitchoices = (
|
sessionunitchoices = (
|
||||||
('min','minutes'),
|
('min','minutes'),
|
||||||
('km','km'),
|
('km','km'),
|
||||||
('m','meters')
|
('m','meters'),
|
||||||
|
('None',None),
|
||||||
)
|
)
|
||||||
|
|
||||||
manager = models.ForeignKey(User)
|
manager = models.ForeignKey(User)
|
||||||
|
|||||||
@@ -20,20 +20,76 @@ from rowers.models import (
|
|||||||
TrainingPlan,
|
TrainingPlan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import metrics
|
||||||
|
import numpy as np
|
||||||
|
import dataprep
|
||||||
|
|
||||||
# Low Level functions - to be called by higher level methods
|
# Low Level functions - to be called by higher level methods
|
||||||
|
|
||||||
# dummies for now
|
# dummies for now
|
||||||
def submit_workout(w,ps):
|
def add_workouts_plannedsession(ws,ps):
|
||||||
|
for w in ws:
|
||||||
|
w.plannedsession = ps
|
||||||
|
w.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def remove_workout_plannedsession(w,ps):
|
def remove_workout_plannedsession(w,ps):
|
||||||
return 1
|
if w.plannedsession == ps:
|
||||||
|
w.plannedsession = None
|
||||||
|
w.save()
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def clone_planned_session(ps):
|
||||||
|
ps.save()
|
||||||
|
ps.pk = None # creates new instance
|
||||||
|
ps.save()
|
||||||
|
|
||||||
|
def timefield_to_seconds_duration(t):
|
||||||
|
duration = t.hour*3600.
|
||||||
|
duration += t.minute * 60.
|
||||||
|
duration += t.second
|
||||||
|
duration += t.microsecond/1.e6
|
||||||
|
|
||||||
|
return duration
|
||||||
|
|
||||||
|
def is_session_complete(ps):
|
||||||
|
ws = Workout.objects.filter(plannedsession=ps)
|
||||||
|
score = 0
|
||||||
|
for w in ws:
|
||||||
|
if ps.sessionmode == 'distance':
|
||||||
|
score += w.distance
|
||||||
|
elif ps.sessionmode == 'time':
|
||||||
|
durationseconds = timefield_to_seconds_duration(w.duration)
|
||||||
|
score += durationseconds
|
||||||
|
elif ps.sessionmode == 'TRIMP':
|
||||||
|
trimp = dataprep.workout_trimp(w)
|
||||||
|
score += trimp
|
||||||
|
elif ps.sessionmode == 'rScore':
|
||||||
|
rscore = dataprep.workout_rscore(w)
|
||||||
|
score += rscore
|
||||||
|
|
||||||
|
ratio = score/float(ps.value)
|
||||||
|
|
||||||
|
if ratio>0.8 and ratio<1.2:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def rank_results(ps):
|
def rank_results(ps):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def add_team(t,ps):
|
def add_team(t,ps):
|
||||||
|
ps.team.add(t)
|
||||||
|
ps.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def add_rower(r,ps):
|
def add_rower(r,ps):
|
||||||
|
ps.rower.add(r)
|
||||||
|
ps.save()
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -7496,7 +7496,6 @@ def workout_stats_view(request,id=0,message="",successmessage=""):
|
|||||||
if w.workouttype in ('water','coastal'):
|
if w.workouttype in ('water','coastal'):
|
||||||
ftp = ftp*(100.-r.otwslack)/100.
|
ftp = ftp*(100.-r.otwslack)/100.
|
||||||
|
|
||||||
intensityfactor = datadf['power'].mean()/float(ftp)
|
|
||||||
intensityfactor = normp/float(ftp)
|
intensityfactor = normp/float(ftp)
|
||||||
tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp))
|
tss = 100.*((duration*normp*intensityfactor)/(3600.*ftp))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user