<a href = "{% url 'ngraph' %}">Customer Count</a>
When I click on customer count it works only once and to make it work I have to run the program again, what is the problem here ? And what I have noticed is once the link localhost:8000/graph is (customer count) clicked, works but makes busy to localhost:8000 and doesn't work that link. How to solve it ?
def graph(request):
age = ['below 20', '20-22','22-24','24-26','26-28','28-30','30-40','above 40']
avg_call_group = [0, 0, 0, 0, 0, 0, 0, 0]
cursor = connection.cursor()
cursor.execute("select p.age_group,sum(c.avg_duration) as age_avg_dur from demo p,(select card_no as card_n, avg(duration) as avg_duration from call_details where service_key = 1 and card_no =calling_no group by card_no) as c where p.card_no = c.card_n group by p.age_group ")
numrows = int(cursor.rowcount)
for x in range(numrows):
row = cursor.fetchone()
avg_call_group[x] = row[1]
cursor.close()
import matplotlib.pyplot as plt
f=plt.figure(figsize = (3,3))
exploding = [.04, .04, .04, .04 , .04, .04, .04, .04]
age = ['below 20', '20-22','22-24','24-26','26-28','28-30','30-40','40-50']
plt.pie(avg_call_group, labels= age, autopct='%1.3f%%', explode = exploding)
canvas = FigureCanvasAgg(f)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
return response
from django.conf.urls import patterns, include, url
from welcome.views import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^hello/', hello, name = 'nhello'),
url(r'^graph/', graph, name = 'ngraph'),
)
<div >
<a href = "{% url 'ngraph' %}">Customer Count</a>
</div>
Alternative source code location: click here
I don't know if you still need an answer but I solved the exact problem like this:
matplotlib.use('Agg') # After you import
# And these lines at the end
fig.clf()
plt.close()
plt.clf()
del var_grid
gc.collect()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With