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