diff --git a/rowers/interactiveplots.py b/rowers/interactiveplots.py index 3150b026..376e6c43 100644 --- a/rowers/interactiveplots.py +++ b/rowers/interactiveplots.py @@ -1638,22 +1638,33 @@ def getfatigues( fatigue = 0 fitness = 0 + impulses = [] + for f in fatigues: + impulses.append(0) + lambda_a = 2/(kfatigue+1) lambda_c = 2/(kfitness+1) nrdays = (enddate-startdate).days + + factor = 1.0 + if metricchoice == 'rscore': + factor = 2.0 + for i in range(nrdays): date = startdate+datetime.timedelta(days=i) ws = Workout.objects.filter(user=user.rower,date=date,duplicate=False) weight = 0 for w in ws: - weight += getattr(w,metricchoice) + weight += factor*getattr(w,metricchoice) if getattr(w,metricchoice) == 0: if metricchoice == 'rscore' and w.hrtss != 0: - weight+= w.hrtss + weight+= factor*w.hrtss else: trimp,hrtss = dataprep.workout_trimp(w) rscore,normp = dataprep.workout_rscore(w) + impulses.append(weight) + fatigue = (1-lambda_a)*fatigue+weight*lambda_a fitness = (1-lambda_c)*fitness+weight*lambda_c @@ -1663,7 +1674,7 @@ def getfatigues( dates.append(datetime.datetime.combine(date,datetime.datetime.min.time())) testpower.append(np.nan) - return fatigues,fitnesses,dates,testpower + return fatigues,fitnesses,dates,testpower,impulses def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, metricchoice='trimp',doform=False,dofatigue=False): @@ -1684,7 +1695,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, - fatigues,fitnesses,dates,testpower = getfatigues(fatigues, + fatigues,fitnesses,dates,testpower,impulses = getfatigues(fatigues, fitnesses, dates, testpower, @@ -1699,6 +1710,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, 'testpower':testpower, 'fatigue':fatigues, 'fitness':fitnesses, + 'impulse':impulses, }) @@ -1724,12 +1736,13 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, fitness = df['fitness'], fatigue = df['fatigue'], form = df['form'], + impulse = df['impulse'] ) ) plot = Figure(tools=TOOLS,x_axis_type='datetime', - plot_width=900, + plot_width=900,plot_height=300, toolbar_location="above", toolbar_sticky=False) @@ -1783,7 +1796,7 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, #plot.circle('date','testpower',source=source,fill_color='green',size=10, # legend_label=legend_label.format(fitnesstest=fitnesstest)) - plot.xaxis.axis_label = 'Date' + plot.xaxis.axis_label = None plot.yaxis.axis_label = yaxlabel @@ -1816,27 +1829,29 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, plot.legend.location = "top_left" - plot.xaxis.formatter = DatetimeTickFormatter( - days=["%d %B %Y"], - months=["%d %B %Y"], - years=["%d %B %Y"], - ) + #plot.xaxis.formatter = DatetimeTickFormatter( + # days=["%d %B %Y"], + # months=["%d %B %Y"], + # years=["%d %B %Y"], + # ) - plot.xaxis.major_label_orientation = pi/4 - plot.sizing_mode = 'stretch_both' + #plot.xaxis.major_label_orientation = pi/4 + plot.sizing_mode = 'scale_both' #plot.y_range = Range1d(0,1.5*max(df['testpower'])) startdate = datetime.datetime.combine(startdate,datetime.datetime.min.time()) enddate = datetime.datetime.combine(enddate,datetime.datetime.min.time()) - plot.x_range = Range1d( - startdate,enddate+datetime.timedelta(days=5), + xrange = Range1d( + startdate,enddate, ) + plot.x_range = xrange plot.y_range = Range1d( start=0,end=y1rangemax, ) plot.title.text = 'Performance Manager '+user.first_name + hover = plot.select(dict(type=HoverTool)) hover.tooltips = OrderedDict([ @@ -1847,8 +1862,25 @@ def performance_chart(user,startdate=None,enddate=None,kfitness=42,kfatigue=7, (formlabel,'@form') ]) + plot2 = Figure(tools=TOOLS,x_axis_type='datetime', + plot_width=900,plot_height=150, + toolbar_location=None, + toolbar_sticky=False) + + plot2.x_range = xrange + plot2.y_range = Range1d(0,df['impulse'].max()) + + plot2.vbar(x = df['date'], top = df['impulse'],color='gray') + + plot2.sizing_mode = 'scale_both' + plot2.yaxis.axis_label = 'Impulse' + plot2.xaxis.axis_label = 'Date' + + layout = layoutcolumn([plot,plot2]) + layout.sizing_mode = 'stretch_both' + try: - script,div = components(plot) + script,div = components(layout) except Exception as e: df.dropna(inplace=True,axis=0,how='any') return ( @@ -1913,7 +1945,7 @@ def fitnessfit_chart(workouts,user,workoutmode='water',startdate=None, fatigues = df['fatigue'].values.tolist() fitnesses = df['fitness'].values.tolist() - fatigues,fitnesses,dates,testpower = getfatigues( + fatigues,fitnesses,dates,testpower,impulses = getfatigues( fatigues,fitnesses,dates,testpower, startdate,enddate,user,metricchoice,kfatigue,kfitness ) diff --git a/rowers/templates/analysis.html b/rowers/templates/analysis.html index d0684f55..593b55ce 100644 --- a/rowers/templates/analysis.html +++ b/rowers/templates/analysis.html @@ -11,6 +11,7 @@
    +
  • Compare Workouts

    {% if team %}