execution chart without plan
This commit is contained in:
@@ -242,6 +242,9 @@ def interactive_planchart(data,startdate,enddate):
|
||||
yaxmaximum = data['executed'].max()
|
||||
if data['planned'].max() > yaxmaximum:
|
||||
yaxmaximum = data['planned'].max()
|
||||
|
||||
if yaxmaximum == 0:
|
||||
yaxmaximum = 250
|
||||
|
||||
yrange1 = Range1d(start=0,end=1.1*yaxmaximum)
|
||||
|
||||
|
||||
@@ -145,13 +145,13 @@ def checkscores(r,macrocycles):
|
||||
m.save()
|
||||
|
||||
|
||||
|
||||
def get_execution_report(rower,startdate,enddate,plan=None):
|
||||
if plan:
|
||||
macros = TrainingMacroCycle.objects.filter(plan=plan).order_by("startdate")
|
||||
checkscores(rower,macros)
|
||||
mesos = TrainingMesoCycle.objects.filter(plan__in=macros).order_by("startdate")
|
||||
micros = TrainingMicroCycle.objects.filter(plan__in=mesos).order_by("startdate")
|
||||
micros = micros.exclude(enddate__lte=startdate).exclude(startdate__gte=enddate)
|
||||
else:
|
||||
plans = TrainingPlan.objects.filter(startdate__lte=startdate,enddate__gte=startdate)
|
||||
plans2 = TrainingPlan.objects.filter(enddate__lte=enddate,startdate__lte=enddate)
|
||||
@@ -161,7 +161,18 @@ def get_execution_report(rower,startdate,enddate,plan=None):
|
||||
|
||||
if not plans:
|
||||
# make week cycles here
|
||||
return(0,'no plan found')
|
||||
# get monday before startdate
|
||||
startdate += timedelta(days=1-startdate.isoweekday())
|
||||
startdate = startdate-timedelta(days=7)
|
||||
micros = []
|
||||
while startdate <= enddate:
|
||||
micro = type('micros',(object,),
|
||||
{
|
||||
'startdate':startdate,
|
||||
'enddate':startdate+timedelta(days=7)
|
||||
})
|
||||
micros.append(micro)
|
||||
startdate += timedelta(days=7)
|
||||
else:
|
||||
plan = plans[0]
|
||||
macros = TrainingMacroCycle.objects.filter(plan=plan).order_by("startdate")
|
||||
|
||||
@@ -2336,46 +2336,77 @@ def rower_trainingplan_execution_view(request,
|
||||
id=0,
|
||||
userid=0):
|
||||
|
||||
startdate,enddate = get_dates_timeperiod(request)
|
||||
|
||||
try:
|
||||
plan = TrainingPlan.objects.get(id=id)
|
||||
except TrainingPlan.DoesNotExist:
|
||||
raise Http4040("Training Plan Does Not Exist")
|
||||
|
||||
startdate = request.GET.get('startdate')
|
||||
enddate = request.GET.get('enddate')
|
||||
|
||||
r = getrequestrower(request,userid=userid)
|
||||
|
||||
if not checkaccessuser(request.user,plan.manager):
|
||||
if request.user.rower not in plan.rowers.all():
|
||||
raise PermissionDenied("Access denied")
|
||||
|
||||
if int(id):
|
||||
try:
|
||||
plan = TrainingPlan.objects.get(id=id)
|
||||
except TrainingPlan.DoesNotExist:
|
||||
raise Http404("Training Plan Does Not Exist")
|
||||
if not checkaccessuser(request.user,plan.manager):
|
||||
if request.user.rower not in plan.rowers.all():
|
||||
raise PermissionDenied("Access denied")
|
||||
|
||||
data,message = get_execution_report(r,plan.startdate,plan.enddate,plan=plan)
|
||||
if not startdate or not enddate:
|
||||
startdate = plan.startdate
|
||||
enddate = plan.enddate
|
||||
else:
|
||||
startdate,enddate = get_dates_timeperiod(request)
|
||||
|
||||
script, div = interactive_planchart(data,plan.startdate,plan.enddate)
|
||||
|
||||
breadcrumbs = [
|
||||
{
|
||||
'url':reverse(plannedsessions_view,
|
||||
kwargs={'userid':userid}),
|
||||
'name': 'Plan'
|
||||
},
|
||||
{
|
||||
'url':reverse(rower_trainingplan_view,
|
||||
kwargs={'userid':userid,
|
||||
'id':id}),
|
||||
'name': plan.name
|
||||
if int(id):
|
||||
data,message = get_execution_report(r,startdate,enddate,plan=plan)
|
||||
else:
|
||||
data,message = get_execution_report(r,startdate,enddate)
|
||||
|
||||
if not data.empty:
|
||||
script, div = interactive_planchart(data,startdate,enddate)
|
||||
else:
|
||||
script = ''
|
||||
div = ''
|
||||
messages.error(request,'The plan does not cover this time range')
|
||||
|
||||
if int(id):
|
||||
breadcrumbs = [
|
||||
{
|
||||
'url':reverse(plannedsessions_view,
|
||||
kwargs={'userid':userid}),
|
||||
'name': 'Plan'
|
||||
},
|
||||
{
|
||||
'url':reverse(rower_trainingplan_execution_view,
|
||||
kwargs={'userid':userid,
|
||||
'id':id}),
|
||||
'name': 'Execution'
|
||||
{
|
||||
'url':reverse(rower_trainingplan_view,
|
||||
kwargs={'userid':userid,
|
||||
'id':id}),
|
||||
'name': plan.name
|
||||
},
|
||||
{
|
||||
'url':reverse(rower_trainingplan_execution_view,
|
||||
kwargs={'userid':userid,
|
||||
'id':id}),
|
||||
'name': 'Execution'
|
||||
}
|
||||
]
|
||||
else:
|
||||
breadcrumbs = [
|
||||
{
|
||||
'url':reverse(plannedsessions_view,
|
||||
kwargs={'userid':userid}),
|
||||
'name': 'Plan'
|
||||
},
|
||||
{
|
||||
'url':reverse(rower_trainingplan_execution_view,
|
||||
kwargs={'userid':userid,
|
||||
'id':id}),
|
||||
'name': 'Execution'
|
||||
}
|
||||
]
|
||||
|
||||
return render(request,'trainingplan_chart.html',
|
||||
{
|
||||
'plan':plan,
|
||||
'todays_date': timezone.now().date(),
|
||||
'active': 'nav-plan',
|
||||
'breadcrumbs':breadcrumbs,
|
||||
|
||||
Reference in New Issue
Block a user