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