feedback/utils.py
changeset 11 afc41af983e5
child 56 d8d4387b3281
equal deleted inserted replaced
10:7535305b1104 11:afc41af983e5
       
     1 """ A collection of utilities for feedback app.
       
     2 """
       
     3 
       
     4 from offline.feedback.models import *
       
     5 
       
     6 LONG_FIELD_NAME = {'topics': "Range of topics covered:",
       
     7                    'depth': "Depth of coverage:",
       
     8                    'methodology': "Effectiveness of methodology:",
       
     9                    'pace': "Pace of coverage:",
       
    10                    'applicability': "Applicability:",
       
    11                    'problems': "Choice of problems:",
       
    12                    'exercises': "Choice of Exercises:",
       
    13                   }
       
    14 
       
    15 EXPAND_OPTION = {
       
    16     "topics" : {
       
    17         "1" : "%s%% of the people felt that the range of topics covered was very relevant",
       
    18         "2" : "%s%% of the people felt that the range of topics covered was relevant",
       
    19         "3" : "%s%% of the people felt that the range of topics covered was somewhat relevant",
       
    20         "4" : "%s%% of the people felt that the range of topics covered was not relevant",
       
    21     },
       
    22 
       
    23     "depth" : {
       
    24         "1" : "%s%% of the people felt that the depth of coverage was too detailed",
       
    25         "2" : "%s%% of the people felt that the depth of coverage was detailed",
       
    26         "3" : "%s%% of the people felt that the depth of coverage was not detailed enough",
       
    27         "4" : "%s%% of the people felt that the depth of coverage was poorly detailed",
       
    28     },
       
    29 
       
    30     "methodology" : {
       
    31         "1" : "%s%% of the people felt that the teaching methodology was extremely effective",
       
    32         "2" : "%s%% of the people felt that the teaching methodology was effective",
       
    33         "3" : "%s%% of the people felt that the teaching methodology was not very effective",
       
    34         "4" : "%s%% of the people felt that the teaching methodology was ineffective",
       
    35     },
       
    36 
       
    37     "pace" : {
       
    38         "1" : "%s%% of the people felt that the the pace of coverage was too fast",
       
    39         "2" : "%s%% of the people felt that the the pace of coverage was fast",
       
    40         "3" : "%s%% of the people felt that the the pace of coverage was just right",
       
    41         "4" : "%s%% of the people felt that the the pace of coverage was slow",
       
    42         "5" : "%s%% of the people felt that the the pace of coverage was too slow",
       
    43     },
       
    44 
       
    45     "applicability" : {
       
    46         "1" : "%s%% of the people felt that they can apply what they have learnt immediately",
       
    47         "2" : "%s%% of the people felt that they can apply what they have learnt somewhat immediately",
       
    48         "3" : "%s%% of the people felt that they cannot apply what they have learnt immediately",
       
    49         "4" : "%s%% of the people felt that they might never apply what they have learnt",
       
    50     },
       
    51 
       
    52     "problems" : {
       
    53         "1" : "%s%% of the people felt that the problems were very interesting",
       
    54         "2" : "%s%% of the people felt that the problems were interesting",
       
    55         "3" : "%s%% of the people felt that the problems were somewhat interesting",
       
    56         "4" : "%s%% of the people felt that the problems were not interesting",
       
    57     },
       
    58 
       
    59     "exercises" : {
       
    60         "1" : "%s%% of the people felt that the exercises were very instructive",
       
    61         "2" : "%s%% of the people felt that the exercises were instructive",
       
    62         "3" : "%s%% of the people felt that the exercises were somewhat instructive",
       
    63         "4" : "%s%% of the people felt that the exercises were not instructive",
       
    64     },
       
    65 }
       
    66 
       
    67 def make_day_report(feeds):
       
    68     """ take a list of feedback objects and return the percentage of each item in the form of a dict.
       
    69     """
       
    70 
       
    71     no_of_feeds = feeds.count()
       
    72     if not no_of_feeds:
       
    73         return []
       
    74 
       
    75     day_report = []
       
    76 
       
    77     for field in ['topics', 'depth', 'methodology', 'pace', 'applicability', 'problems', 'exercises']:
       
    78         
       
    79         choices = eval((field+'_choices').upper()) ## the choices are named accordingly in the models file
       
    80         choices_dict = dict(choices)
       
    81         
       
    82         field_report = []
       
    83         for option in sorted(choices_dict.keys()):
       
    84             args_dict = {field : option}
       
    85             option_percent = feeds.filter(**args_dict).count() / no_of_feeds * 100
       
    86             if option_percent:
       
    87                 field_report.append((EXPAND_OPTION[field][option])%option_percent)
       
    88         
       
    89         if field_report:
       
    90             day_report.extend( [LONG_FIELD_NAME[field], field_report] )
       
    91 
       
    92     return day_report
       
    93         
       
    94