added static plot of in stroke from geeky page
This commit is contained in:
@@ -16,7 +16,8 @@ from django.db.models import Q
|
||||
from django import template
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from matplotlib.backends.backend_agg import FigureCanvas
|
||||
import gc
|
||||
|
||||
from django.shortcuts import render
|
||||
from django.http import (
|
||||
@@ -6445,6 +6446,10 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
|
||||
|
||||
form = WorkoutForm(instance=row)
|
||||
g = GraphImage.objects.filter(workout=row).order_by("-creationdatetime")
|
||||
rowdata = rrdata(csvfile=row.csvfilename)
|
||||
instrokemetrics = rowdata.get_instroke_columns()
|
||||
|
||||
|
||||
for i in g:
|
||||
try:
|
||||
width,height = Image.open(i.filename).size
|
||||
@@ -6486,6 +6491,7 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
|
||||
{'workout':row,
|
||||
'teams':get_my_teams(request.user),
|
||||
'interactiveplot':script,
|
||||
'instrokemetrics':instrokemetrics,
|
||||
'the_div':div})
|
||||
else:
|
||||
return render(request,
|
||||
@@ -6495,6 +6501,60 @@ def workout_geeky_view(request,id=0,message="",successmessage=""):
|
||||
'interactiveplot':script,
|
||||
'the_div':div})
|
||||
|
||||
# generate instroke chart
|
||||
@login_required()
|
||||
def instroke_chart(request,id=0,metric=''):
|
||||
try:
|
||||
w = Workout.objects.get(id=id)
|
||||
except Workout.DoesNotExist:
|
||||
raise Http404("Workout doesn't exist")
|
||||
|
||||
if (checkworkoutuser(request.user,w)==False):
|
||||
message = "You are not allowed to edit this workout"
|
||||
messages.error(request,message)
|
||||
url = reverse(workouts_view)
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
rowdata = rrdata(csvfile=w.csvfilename)
|
||||
instrokemetrics = rowdata.get_instroke_columns()
|
||||
|
||||
if metric in instrokemetrics:
|
||||
f1 = w.csvfilename[6:-4]
|
||||
timestr = strftime("%Y%m%d-%H%M%S")
|
||||
imagename = f1+timestr+'.png'
|
||||
fullpathimagename = 'static/plots/'+imagename
|
||||
u = w.user.user
|
||||
r = getrower(u)
|
||||
title = w.name
|
||||
fig1 = rowdata.get_plot_instroke(metric)
|
||||
canvas = FigureCanvas(fig1)
|
||||
canvas.print_figure('static/plots/'+imagename)
|
||||
plt.close(fig1)
|
||||
fig1.clf()
|
||||
gc.collect()
|
||||
|
||||
try:
|
||||
width,height = Image.open(fullpathimagename).size
|
||||
except:
|
||||
width = 1200
|
||||
height = 600
|
||||
|
||||
i = GraphImage(workout=w,
|
||||
creationdatetime=timezone.now(),
|
||||
filename=fullpathimagename,
|
||||
width=width,height=height)
|
||||
|
||||
i.save()
|
||||
print i.id,'aap'
|
||||
|
||||
url = reverse(workout_geeky_view,
|
||||
kwargs = {
|
||||
'id':id,
|
||||
})
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# Cumulative stats page
|
||||
@login_required()
|
||||
def cumstats(request,theuser=0,
|
||||
|
||||
Reference in New Issue
Block a user