adding critical stroke rate chart
This commit is contained in:
@@ -294,6 +294,8 @@ def analysis_new(request,
|
||||
df = comparisondata(tw, options)
|
||||
elif function == 'cp': # pragma: no cover
|
||||
df = cpdata(tw, options)
|
||||
elif function == 'cr': # pragma: no cover
|
||||
df = crdata(tw, options)
|
||||
options['savedata'] = False
|
||||
request.session['options'] = options
|
||||
try:
|
||||
@@ -661,7 +663,7 @@ def cpdata(workouts, options):
|
||||
r = u.rower
|
||||
|
||||
|
||||
delta, cpvalue, avgpower, workoutnames, urls = dataprep.fetchcp_new(
|
||||
delta, cpvalue, crvalue, avgpower, workoutnames, urls = dataprep.fetchcp_new(
|
||||
r, workouts)
|
||||
|
||||
powerdf = pl.DataFrame({
|
||||
@@ -811,6 +813,139 @@ def cpdata(workouts, options):
|
||||
|
||||
return (script, html_content)
|
||||
|
||||
def crdata(workouts, options):
|
||||
start = timezone.now()
|
||||
userid = options['userid']
|
||||
cpfit = options['cpfit']
|
||||
cpoverlay = options['cpoverlay']
|
||||
|
||||
u = User.objects.get(id=userid)
|
||||
r = u.rower
|
||||
|
||||
|
||||
delta, cpvalue, crvalue, avgpower, workoutnames, urls = dataprep.fetchcp_new(
|
||||
r, workouts)
|
||||
|
||||
powerdf = pl.DataFrame({
|
||||
'Delta': delta,
|
||||
'CR': crvalue,
|
||||
'workout': workoutnames,
|
||||
'url': urls,
|
||||
})
|
||||
|
||||
savedata = options.get('savedata',False)
|
||||
if savedata: # pragma: no cover
|
||||
return powerdf.to_pandas()
|
||||
|
||||
if powerdf.is_empty(): # pragma: no cover
|
||||
return('', '<p>No valid data found</p>')
|
||||
|
||||
|
||||
powerdf = powerdf.lazy().filter(pl.col("CR")>0)
|
||||
powerdf = powerdf.sort(["Delta", "CR"], descending=[False, True])
|
||||
powerdf = powerdf.unique(subset="Delta", keep="first")
|
||||
powerdf = powerdf.fill_nan(None).drop_nulls()
|
||||
powerdf = powerdf.collect()
|
||||
|
||||
rowername = r.user.first_name+" "+r.user.last_name
|
||||
|
||||
wcdurations = []
|
||||
wcpower = []
|
||||
|
||||
if len(powerdf) != 0:
|
||||
datefirst = pd.Series(w.date for w in workouts).min()
|
||||
datelast = pd.Series(w.date for w in workouts).max()
|
||||
title = 'Critical Stroke Rate chart for {name}, from {d1} to {d2}'.format(
|
||||
name=rowername,
|
||||
d1=datefirst,
|
||||
d2=datelast,
|
||||
)
|
||||
wtype = 'water'
|
||||
if workouts[0].workouttype in mytypes.otetypes: # pragma: no cover
|
||||
wtype = 'erg'
|
||||
if workouts[0].workouttype == 'bikeerg': # pragma: no cover
|
||||
# for Mike
|
||||
wtype = 'erg'
|
||||
|
||||
|
||||
res = interactive_otwcrchart(powerdf, promember=True, rowername=rowername, r=r,
|
||||
cpfit=cpfit, title=title, type=wtype,)
|
||||
|
||||
script = res[0]
|
||||
div = res[1]
|
||||
p1 = res[2]
|
||||
ratio = res[3]
|
||||
else: # pragma: no cover
|
||||
script = ''
|
||||
div = '<p>No ranking pieces found.</p>'
|
||||
p1 = [1, 1, 1, 1]
|
||||
ratio = 1
|
||||
|
||||
|
||||
|
||||
|
||||
minutes = options['piece']
|
||||
if minutes != 0:
|
||||
# minutes = 77
|
||||
try:
|
||||
hourvalue, tvalue = divmod(minutes, 60)
|
||||
except: # pragma: no cover
|
||||
hourvalue = 0
|
||||
tvalue = minutes
|
||||
# hourvalue = 1, tvalue = 17
|
||||
try:
|
||||
hourvalue = int(hourvalue)
|
||||
except TypeError: # pragma: no cover
|
||||
hourvalue = 0
|
||||
try:
|
||||
minutevalue = int(tvalue)
|
||||
except TypeError: # pragma: no cover
|
||||
minutevalue = 0
|
||||
|
||||
tvalue = int(60*(tvalue-minutevalue))
|
||||
|
||||
if hourvalue >= 24: # pragma: no cover
|
||||
hourvalue = 23
|
||||
pieceduration = datetime.time(
|
||||
minute=minutevalue,
|
||||
hour=hourvalue,
|
||||
second=tvalue,
|
||||
)
|
||||
|
||||
pieceseconds = 3600.*pieceduration.hour+60. * \
|
||||
pieceduration.minute+pieceduration.second
|
||||
# CP model
|
||||
pwr = p1[0]/(1+pieceseconds/p1[2])
|
||||
pwr += p1[1]/(1+pieceseconds/p1[3])
|
||||
|
||||
if pwr <= 0: # pragma: no cover
|
||||
pwr = 50.
|
||||
|
||||
if not np.isnan(pwr):
|
||||
try:
|
||||
pwr2 = pwr*ratio
|
||||
except: # pragma: no cover
|
||||
pwr2 = pwr
|
||||
|
||||
duration = timedeltaconv(pieceseconds)
|
||||
power = int(pwr)
|
||||
upper = int(pwr2)
|
||||
else: # pragma: no cover
|
||||
duration = timedeltaconv(0)
|
||||
power = 0
|
||||
upper = 0
|
||||
|
||||
htmly = env.get_template('otwcr.html')
|
||||
html_content = htmly.render({
|
||||
'script': script,
|
||||
'the_div': div,
|
||||
'duration': duration,
|
||||
'power': power,
|
||||
'upper': upper,
|
||||
})
|
||||
|
||||
return (script, html_content)
|
||||
|
||||
|
||||
def statsdata(workouts, options):
|
||||
#try:
|
||||
@@ -1063,6 +1198,8 @@ def analysis_view_data(request, userid=0):
|
||||
script, div = comparisondata(workouts, options)
|
||||
elif function == 'cp': # pragma: no cover
|
||||
script, div = cpdata(workouts, options)
|
||||
elif function == 'cr': # pragma: no cover
|
||||
script, div = crdata(workouts, options)
|
||||
else: # pragma: no cover
|
||||
script = ''
|
||||
div = 'Unknown analysis functions'
|
||||
|
||||
Reference in New Issue
Block a user