Profile
Pastes: 76354
Members: 1487

Paste

Plain view | Edit code: here. | Add this to your website. | Report abuse.

Short URL: http://goo.gl/9TQ9b

Pasted as Plain Text by Bishnu on Monday, July 1st, 2013 4:21pm ( 1 year ago )

  1. views.py includes
  2.  
  3. def graph(request):
  4.     age = ['below 20', '20-22','22-24','24-26','26-28','28-30','30-40','above 40']
  5.     avg_call_group =  [0, 0, 0, 0, 0, 0, 0, 0]
  6.    
  7.     cursor = connection.cursor()
  8.     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 ")
  9.     numrows = int(cursor.rowcount)
  10.     for x in range(numrows):
  11.         row = cursor.fetchone()
  12.         avg_call_group[x] =  row[1]
  13.    
  14.     cursor.close()
  15.    
  16.     import matplotlib.pyplot as plt
  17.     f=plt.figure(figsize = (3,3))
  18.     exploding = [.04, .04, .04, .04 , .04, .04, .04, .04]
  19.     age = ['below 20', '20-22','22-24','24-26','26-28','28-30','30-40','40-50']
  20.     plt.pie(avg_call_group, labels= age, autopct='%1.3f%%', explode = exploding)
  21.     canvas = FigureCanvasAgg(f)
  22.     response = HttpResponse(content_type='image/png')
  23.     canvas.print_png(response)
  24.     return response
  25.  
  26.  
  27. urls.py includes
  28.  
  29. from django.conf.urls import patterns, include, url
  30. from welcome.views import *
  31. from django.contrib import admin
  32. admin.autodiscover()
  33.  
  34. urlpatterns = patterns('',
  35.     url(r'^admin/', include(admin.site.urls)),
  36.     url(r'^hello/', hello, name = 'nhello'),
  37.     url(r'^graph/', graph, name = 'ngraph'),
  38. )
  39.  
  40.  
  41. home.html includes
  42.  
  43. <div >
  44. <a href = "{% url 'ngraph' %}">Customer Count</a>
  45. </div>

Revise this Paste
Your Name:
Code Language:
 
Security Image:
Text seen in Image:
Comments

Nothing has been added as yet. Post a comment.