feedback/utils.py
author nishanth
Thu, 15 Apr 2010 18:23:21 +0530
changeset 53 0a4b2c49f718
parent 44 7d748db0c7c3
child 62 b7e47cc39342
permissions -rw-r--r--
changed feedback model since we now take feedback only from logged in users .
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     1
""" A collection of utilities for feedback app.
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     2
"""
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     3
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     4
from workshop.feedback.models import *
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     5
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     6
LONG_FIELD_NAME = {'topics': "Range of topics covered:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     7
                   'depth': "Depth of coverage:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     8
                   'methodology': "Effectiveness of methodology:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
     9
                   'pace': "Pace of coverage:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    10
                   'applicability': "Applicability:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    11
                   'problems': "Choice of problems:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    12
                   'exercises': "Choice of Exercises:",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    13
                  }
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    14
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    15
EXPAND_OPTION = {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    16
    "topics" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    17
        "1" : "%s%% of the people felt that the range of topics covered was very relevant",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    18
        "2" : "%s%% of the people felt that the range of topics covered was relevant",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    19
        "3" : "%s%% of the people felt that the range of topics covered was somewhat relevant",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    20
        "4" : "%s%% of the people felt that the range of topics covered was not relevant",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    21
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    22
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    23
    "depth" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    24
        "1" : "%s%% of the people felt that the depth of coverage was too detailed",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    25
        "2" : "%s%% of the people felt that the depth of coverage was detailed",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    26
        "3" : "%s%% of the people felt that the depth of coverage was not detailed enough",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    27
        "4" : "%s%% of the people felt that the depth of coverage was poorly detailed",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    28
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    29
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    30
    "methodology" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    31
        "1" : "%s%% of the people felt that the teaching methodology was extremely effective",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    32
        "2" : "%s%% of the people felt that the teaching methodology was effective",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    33
        "3" : "%s%% of the people felt that the teaching methodology was not very effective",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    34
        "4" : "%s%% of the people felt that the teaching methodology was ineffective",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    35
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    36
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    37
    "pace" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    38
        "1" : "%s%% of the people felt that the the pace of coverage was too fast",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    39
        "2" : "%s%% of the people felt that the the pace of coverage was fast",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    40
        "3" : "%s%% of the people felt that the the pace of coverage was just right",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    41
        "4" : "%s%% of the people felt that the the pace of coverage was slow",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    42
        "5" : "%s%% of the people felt that the the pace of coverage was too slow",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    43
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    44
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    45
    "applicability" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    46
        "1" : "%s%% of the people felt that they can apply what they have learnt immediately",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    47
        "2" : "%s%% of the people felt that they can apply what they have learnt somewhat immediately",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    48
        "3" : "%s%% of the people felt that they cannot apply what they have learnt immediately",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    49
        "4" : "%s%% of the people felt that they might never apply what they have learnt",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    50
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    51
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    52
    "problems" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    53
        "1" : "%s%% of the people felt that the problems were very interesting",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    54
        "2" : "%s%% of the people felt that the problems were interesting",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    55
        "3" : "%s%% of the people felt that the problems were somewhat interesting",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    56
        "4" : "%s%% of the people felt that the problems were not interesting",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    57
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    58
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    59
    "exercises" : {
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    60
        "1" : "%s%% of the people felt that the exercises were very instructive",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    61
        "2" : "%s%% of the people felt that the exercises were instructive",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    62
        "3" : "%s%% of the people felt that the exercises were somewhat instructive",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    63
        "4" : "%s%% of the people felt that the exercises were not instructive",
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    64
    },
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    65
}
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    66
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    67
def make_day_report(feeds):
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    68
    """ take a list of feedback objects and return the percentage of each item in the form of a dict.
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    69
    """
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    70
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    71
    no_of_feeds = feeds.count()
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    72
    if not no_of_feeds:
44
7d748db0c7c3 now show report page does not show report if there are no feedbacks .
nishanth
parents: 42
diff changeset
    73
        return []
42
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    74
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    75
    day_report = []
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    76
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    77
    for field in ['topics', 'depth', 'methodology', 'pace', 'applicability', 'problems', 'exercises']:
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    78
        
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    79
        choices = eval((field+'_choices').upper()) ## the choices are named accordingly in the models file
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    80
        choices_dict = dict(choices)
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    81
        
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    82
        field_report = []
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    83
        for option in sorted(choices_dict.keys()):
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    84
            args_dict = {field : option}
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    85
            option_percent = feeds.filter(**args_dict).count() / no_of_feeds * 100
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    86
            if option_percent:
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    87
                field_report.append((EXPAND_OPTION[field][option])%option_percent)
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    88
        
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    89
        if field_report:
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    90
            day_report.extend( [LONG_FIELD_NAME[field], field_report] )
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    91
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    92
    return day_report
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    93
        
0f926874a695 added the files I forgot to add in previous commit
nishanth
parents:
diff changeset
    94