added show_report functionality
authornishanth
Tue, 20 Apr 2010 09:55:46 +0530
changeset 11 afc41af983e5
parent 10 7535305b1104
child 12 81cd0140a0f2
added show_report functionality
feedback/utils.py
feedback/views.py
templates/admin.html
templates/show_report.html
urls.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/feedback/utils.py	Tue Apr 20 09:55:46 2010 +0530
@@ -0,0 +1,94 @@
+""" A collection of utilities for feedback app.
+"""
+
+from offline.feedback.models import *
+
+LONG_FIELD_NAME = {'topics': "Range of topics covered:",
+                   'depth': "Depth of coverage:",
+                   'methodology': "Effectiveness of methodology:",
+                   'pace': "Pace of coverage:",
+                   'applicability': "Applicability:",
+                   'problems': "Choice of problems:",
+                   'exercises': "Choice of Exercises:",
+                  }
+
+EXPAND_OPTION = {
+    "topics" : {
+        "1" : "%s%% of the people felt that the range of topics covered was very relevant",
+        "2" : "%s%% of the people felt that the range of topics covered was relevant",
+        "3" : "%s%% of the people felt that the range of topics covered was somewhat relevant",
+        "4" : "%s%% of the people felt that the range of topics covered was not relevant",
+    },
+
+    "depth" : {
+        "1" : "%s%% of the people felt that the depth of coverage was too detailed",
+        "2" : "%s%% of the people felt that the depth of coverage was detailed",
+        "3" : "%s%% of the people felt that the depth of coverage was not detailed enough",
+        "4" : "%s%% of the people felt that the depth of coverage was poorly detailed",
+    },
+
+    "methodology" : {
+        "1" : "%s%% of the people felt that the teaching methodology was extremely effective",
+        "2" : "%s%% of the people felt that the teaching methodology was effective",
+        "3" : "%s%% of the people felt that the teaching methodology was not very effective",
+        "4" : "%s%% of the people felt that the teaching methodology was ineffective",
+    },
+
+    "pace" : {
+        "1" : "%s%% of the people felt that the the pace of coverage was too fast",
+        "2" : "%s%% of the people felt that the the pace of coverage was fast",
+        "3" : "%s%% of the people felt that the the pace of coverage was just right",
+        "4" : "%s%% of the people felt that the the pace of coverage was slow",
+        "5" : "%s%% of the people felt that the the pace of coverage was too slow",
+    },
+
+    "applicability" : {
+        "1" : "%s%% of the people felt that they can apply what they have learnt immediately",
+        "2" : "%s%% of the people felt that they can apply what they have learnt somewhat immediately",
+        "3" : "%s%% of the people felt that they cannot apply what they have learnt immediately",
+        "4" : "%s%% of the people felt that they might never apply what they have learnt",
+    },
+
+    "problems" : {
+        "1" : "%s%% of the people felt that the problems were very interesting",
+        "2" : "%s%% of the people felt that the problems were interesting",
+        "3" : "%s%% of the people felt that the problems were somewhat interesting",
+        "4" : "%s%% of the people felt that the problems were not interesting",
+    },
+
+    "exercises" : {
+        "1" : "%s%% of the people felt that the exercises were very instructive",
+        "2" : "%s%% of the people felt that the exercises were instructive",
+        "3" : "%s%% of the people felt that the exercises were somewhat instructive",
+        "4" : "%s%% of the people felt that the exercises were not instructive",
+    },
+}
+
+def make_day_report(feeds):
+    """ take a list of feedback objects and return the percentage of each item in the form of a dict.
+    """
+
+    no_of_feeds = feeds.count()
+    if not no_of_feeds:
+        return []
+
+    day_report = []
+
+    for field in ['topics', 'depth', 'methodology', 'pace', 'applicability', 'problems', 'exercises']:
+        
+        choices = eval((field+'_choices').upper()) ## the choices are named accordingly in the models file
+        choices_dict = dict(choices)
+        
+        field_report = []
+        for option in sorted(choices_dict.keys()):
+            args_dict = {field : option}
+            option_percent = feeds.filter(**args_dict).count() / no_of_feeds * 100
+            if option_percent:
+                field_report.append((EXPAND_OPTION[field][option])%option_percent)
+        
+        if field_report:
+            day_report.extend( [LONG_FIELD_NAME[field], field_report] )
+
+    return day_report
+        
+    
--- a/feedback/views.py	Tue Apr 20 09:29:40 2010 +0530
+++ b/feedback/views.py	Tue Apr 20 09:55:46 2010 +0530
@@ -7,7 +7,7 @@
 
 from offline.feedback.models import Feedback
 from offline.feedback.forms import FeedbackForm
-
+from offline.feedback.utils import make_day_report
 
 def submit_feedback(request):
 
@@ -126,3 +126,31 @@
 
     return render_to_response('list_feedbacks.html',{'event':event, 'feeds_list':feeds_list})
 
+def view_report(request, admin_key):
+    """ compile the report and display it.
+    """
+
+    if not admin_key == ADMIN_KEY:
+        raise Http404
+
+    try:
+        event = Event.objects.all()[0]
+    except IndexError:
+        raise Http404
+
+    no_of_days = (event.stop_date - event.start_date).days
+    days = range(1,no_of_days+2)
+
+    workshop_report = []
+
+    for day in days:
+        day_num = str(day)
+        day_feeds = event.feedback.filter(day=day_num)
+
+        day_report = make_day_report(day_feeds) 
+        if day_report:
+            day_comments = [ feed.comments for feed in day_feeds if feed.comments ]
+            day_report.extend(["General comments:",day_comments])
+            workshop_report.extend( [ "Day %s"%day_num, day_report] )
+
+    return render_to_response("show_report.html", {"event":event, "workshop_report":workshop_report})
--- a/templates/admin.html	Tue Apr 20 09:29:40 2010 +0530
+++ b/templates/admin.html	Tue Apr 20 09:55:46 2010 +0530
@@ -8,4 +8,5 @@
 {% endifequal %}
 <br /><br />
 <a href="/feedback/list/{{admin_key}}">View the feedbacks submitted</a><br />
+<a href="/feedback/report/{{admin_key}}">View report of feedbacks submitted</a><br />
 {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/show_report.html	Tue Apr 20 09:55:46 2010 +0530
@@ -0,0 +1,6 @@
+{% extends "base.html" %}
+{% block content %}
+Report of the workshop {{event.title}} conducted from {{event.start_date|date:"d M Y"}} to {{event.stop_date|date:"d M Y"}}
+<br />
+	{{workshop_report|unordered_list}}
+{% endblock %}
--- a/urls.py	Tue Apr 20 09:29:40 2010 +0530
+++ b/urls.py	Tue Apr 20 09:55:46 2010 +0530
@@ -25,4 +25,5 @@
     (r'^feedback/open/(\w+)$', feed_views.open_feedback),
     (r'^feedback/close/(\w+)$', feed_views.close_feedback),
     (r'^feedback/list/(\w+)$', feed_views.list_feedbacks),
+    (r'^feedback/report/(\w+)$', feed_views.view_report),
 )