예제 #1
0
파일: views.py 프로젝트: cyroxx/EvaP
def course_detail(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    
    # staff can see preview of results even when course is not published
    if request.user.is_staff:
        course = get_object_or_404(semester.course_set.filter(state__in=['inEvaluation', 'evaluated', 'reviewed', 'published']), id=course_id)
    # everyone else can only see published results
    else:
        course = get_object_or_404(semester.course_set.filter(state="published"), id=course_id)

    sections = calculate_results(course, request.user.is_staff)

    if (request.user.is_staff == False): # if user is not a student representative
    # remove TextResults if user is neither the evaluated person (or a delegate) nor responsible for the course (or a delegate)
        for section in sections:
            if not user_can_see_textresults(request.user, course, section):
                for index, result in list(enumerate(section.results))[::-1]:
                    if isinstance(section.results[index], TextResult):
                        del section.results[index]

    # remove empty sections and group by contributor
    course_sections = []
    contributor_sections = {}
    for section in sections:
        if not section.results:
            continue
        if section.contributor == None:
            course_sections.append(section)
        else:
            if section.contributor not in contributor_sections:
                contributor_sections[section.contributor] = []
            contributor_sections[section.contributor].append(section)

    # show a warning if course is still in evaluation (for staff preview)
    evaluation_warning = course.state != 'published'

    # check whether course has a sufficient number of votes for publishing it
    sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE

    # results for a course might not be visible because there are not enough answers
    # but it can still be "published" e.g. to show the comment results to lecturers
    # the FSR can still see all results but gets a warning message
    sufficient_votes_warning = (not sufficient_votes) and request.user.is_staff

    course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)

    return render_to_response(
        "results_course_detail.html",
        dict(
            course=course,
            course_sections=course_sections,
            contributor_sections=contributor_sections,
            evaluation_warning=evaluation_warning,
            sufficient_votes_warning=sufficient_votes_warning,
            staff=request.user.is_staff
        ),
        context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: Nef10/EvaP
def course_detail(request, semester_id, course_id):
    semester = get_object_or_404(Semester, id=semester_id)
    course = get_object_or_404(semester.course_set, id=course_id)

    if not course.can_user_see_results(request.user):
        raise PermissionDenied

    sections = calculate_results(course, request.user.is_staff)

    if not request.user.is_staff:
        # remove TextResults if user is neither the evaluated person (or a delegate) nor responsible for the course (or a delegate)
        for section in sections:
            if not user_can_see_textresults(request.user, course, section):
                for i, result in list(enumerate(section.results))[::-1]:
                    if isinstance(result, TextResult):
                        del section.results[i]

    # remove empty sections and group by contributor
    course_sections = []
    contributor_sections = OrderedDict()
    for section in sections:
        if not section.results:
            continue
        if section.contributor is None:
            course_sections.append(section)
        else:
            if section.contributor not in contributor_sections:
                contributor_sections[section.contributor] = []
            contributor_sections[section.contributor].append(section)

    # show a warning if course is still in evaluation (for staff preview)
    evaluation_warning = course.state != 'published'

    # check whether course has a sufficient number of votes for publishing it
    sufficient_votes = course.num_voters >= settings.MIN_ANSWER_COUNT and float(course.num_voters) / course.num_participants >= settings.MIN_ANSWER_PERCENTAGE

    # results for a course might not be visible because there are not enough answers
    # but it can still be "published" e.g. to show the comment results to lecturers.
    # users who can open the results page see a warning message in this case
    sufficient_votes_warning = not sufficient_votes

    course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)

    return render_to_response(
        "results_course_detail.html",
        dict(
            course=course,
            course_sections=course_sections,
            contributor_sections=contributor_sections,
            evaluation_warning=evaluation_warning,
            sufficient_votes_warning=sufficient_votes_warning,
            staff=request.user.is_staff
        ),
        context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: janno42/EvaP
def semester_detail(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    courses = list(semester.course_set.filter(state="published"))

    # annotate each course object with its grades
    for course in courses:
        # first, make sure that there are no preexisting grade attributes
        course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)

    template_data = dict(semester=semester, courses=courses, staff=request.user.is_staff)
    return render(request, "results_semester_detail.html", template_data)
예제 #4
0
파일: views.py 프로젝트: piepmatz/EvaP
def semester_detail(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    courses = list(semester.course_set.filter(state="published"))

    # annotate each course object with its grades
    for course in courses:
        # first, make sure that there are no preexisting grade attributes
        course.avg_grade, course.med_grade = calculate_average_and_medium_grades(course)

    return render_to_response(
        "results_semester_detail.html",
        dict(
            semester=semester,
            courses=courses
        ),
        context_instance=RequestContext(request))
예제 #5
0
파일: exporters.py 프로젝트: cyroxx/EvaP
    def export(self, response, all=False):
        courses_with_results = list()
        for course in self.semester.course_set.filter(state="published").all():
            results = SortedDict()
            for questionnaire, contributor, data, avg_likert, med_likert, avg_grade, med_grade, avg_total, med_total in calculate_results(course):
                results.setdefault(questionnaire.id, []).append((contributor, data, avg_total, med_total))
            courses_with_results.append((course, results))

        courses_with_results.sort(key=lambda cr: cr[0].kind)

        qn_frequencies = defaultdict(int)
        for course, results in courses_with_results:
            for questionnaire, results in results.items():
                qn_frequencies[questionnaire] += 1

        qn_relevant = qn_frequencies.items()
        qn_relevant.sort(key=lambda t: -t[1])

        questionnaires = [Questionnaire.objects.get(id=t[0]) for t in qn_relevant]

        self.workbook = xlwt.Workbook()
        self.sheet = self.workbook.add_sheet(_(u"Results"))
        self.row = 0
        self.col = 0

        
        self.add_color_palette_to_workbook(self.workbook)

        self.writec(_(u"Evaluation {0} - created on {1}").format(self.semester.name, datetime.date.today()), "headline")
        for course, results in courses_with_results:
            if course.state == "published":
                self.writec(course.name, "course", cols=2)
            else:
                self.writec(course.name, "course_unfinished", cols=2)

        self.writen()
        for course, results in courses_with_results:
            self.writec("Average", "avg")
            self.writec("Variance", "border_top_bottom_right")

        for questionnaire in questionnaires:
            self.writen(questionnaire.name, "bold")
            for course, results in courses_with_results:
                self.write_two_empty_cells_with_borders()

            for question_index, question in enumerate(questionnaire.question_set.all()):
                if question.is_text_question():
                    continue

                self.writen(question.text)

                for course, results in courses_with_results:
                    qn_results = results.get(questionnaire.id, None)
                    if qn_results:
                        values = []
                        variances = []
                        enough_answers = True
                        for contributor, data, avg_grade, med_grade in qn_results:
                            for grade_result in data:
                                if grade_result.question.id == question.id:
                                    if grade_result.average:
                                        values.append(grade_result.average)
                                        variances.append(grade_result.variance)
                                        if not grade_result.show:
                                            enough_answers = False
                                    break
                        if values and (enough_answers or all):
                            avg = sum(values) / len(values)
                            self.writec(avg, ExcelExporter.grade_to_style(avg));

                            var = sum(variances) / len(variances)
                            self.writec(var, ExcelExporter.variance_to_style(var))
                        else:
                            self.write_two_empty_cells_with_borders()
                    else:
                        self.write_two_empty_cells_with_borders()
            self.writen(None)
            for course, results in courses_with_results:
                    self.write_two_empty_cells_with_borders()

        self.writen(_(u"Overall Average Grade"), "bold")
        for course, results in courses_with_results:
            avg, med = calculate_average_and_medium_grades(course)
            if avg:
                self.writec(avg, ExcelExporter.grade_to_style(avg), cols=2)
            else:
                self.write_two_empty_cells_with_borders()

        self.writen(_(u"Overall Median Grade"), "bold")
        for course, results in courses_with_results:
            avg, med = calculate_average_and_medium_grades(course)
            if med:
                self.writec(med, ExcelExporter.grade_to_style(med), cols=2)
            else:
                self.write_two_empty_cells_with_borders()

        self.writen(_(u"Total Answers"), "bold")
        for course, results in courses_with_results:
            self.writec(course.num_voters, "total_answers", cols=2)

        self.workbook.save(response)
예제 #6
0
    def export(self, response, all=False):
        courses_with_results = list()
        for course in self.semester.course_set.filter(state="published").all():
            results = SortedDict()
            for questionnaire, contributor, data, avg_grade, med_grade in calculate_results(
                    course):
                results.setdefault(questionnaire.id, []).append(
                    (contributor, data, avg_grade, med_grade))
            courses_with_results.append((course, results))

        courses_with_results.sort(key=lambda cr: cr[0].kind)

        qn_frequencies = defaultdict(int)
        for course, results in courses_with_results:
            for questionnaire, results in results.items():
                qn_frequencies[questionnaire] += 1

        qn_relevant = qn_frequencies.items()
        qn_relevant.sort(key=lambda t: -t[1])

        questionnaires = [
            Questionnaire.objects.get(id=t[0]) for t in qn_relevant
        ]

        self.workbook = xlwt.Workbook()
        self.sheet = self.workbook.add_sheet(_(u"Results"))
        self.row = 0
        self.col = 0

        # Adding evaP colors to palette
        xlwt.add_palette_colour("custom_dark_green", 0x20)
        self.workbook.set_colour_RGB(0x20, 120, 241, 89)
        xlwt.add_palette_colour("custom_light_green", 0x21)
        self.workbook.set_colour_RGB(0x21, 188, 241, 89)
        xlwt.add_palette_colour("custom_yellow", 0x22)
        self.workbook.set_colour_RGB(0x22, 241, 226, 89)
        xlwt.add_palette_colour("custom_orange", 0x23)
        self.workbook.set_colour_RGB(0x23, 241, 158, 89)
        xlwt.add_palette_colour("custom_red", 0x24)
        self.workbook.set_colour_RGB(0x24, 241, 89, 89)

        # formatting for average grades
        avg_style = xlwt.easyxf(
            'alignment: horiz centre; font: bold on; borders: left medium, top medium, bottom medium'
        )
        avg_style_very_good = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_dark_green; alignment: horiz centre; font: bold on; borders: left medium',
            num_format_str="0.0")
        avg_style_good = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_light_green; alignment: horiz centre; font: bold on; borders: left medium',
            num_format_str="0.0")
        avg_style_medium = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_yellow; alignment: horiz centre; font: bold on; borders: left medium',
            num_format_str="0.0")
        avg_style_bad = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_orange; alignment: horiz centre; font: bold on; borders: left medium',
            num_format_str="0.0")
        avg_style_very_bad = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_red; alignment: horiz centre; font: bold on; borders: left medium',
            num_format_str="0.0")

        # formatting for variances
        var_style_good = xlwt.easyxf(
            'alignment: horiz centre; borders: right medium',
            num_format_str="0.0")
        var_style_medium = xlwt.easyxf(
            'pattern: pattern solid, fore_colour gray25; alignment: horiz centre; borders: right medium',
            num_format_str="0.0")
        var_style_bad = xlwt.easyxf(
            'pattern: pattern solid, fore_colour gray40; alignment: horiz centre; borders: right medium',
            num_format_str="0.0")

        # formatting for overall grades
        over_style_very_good = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_dark_green; alignment: horiz centre; font: bold on; borders: left medium, right medium',
            num_format_str="0.0")
        over_style_good = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_light_green; alignment: horiz centre; font: bold on; borders: left medium, right medium',
            num_format_str="0.0")
        over_style_medium = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_yellow; alignment: horiz centre; font: bold on; borders: left medium, right medium',
            num_format_str="0.0")
        over_style_bad = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_orange; alignment: horiz centre; font: bold on; borders: left medium, right medium',
            num_format_str="0.0")
        over_style_very_bad = xlwt.easyxf(
            'pattern: pattern solid, fore_colour custom_red; alignment: horiz centre; font: bold on; borders: left medium, right medium',
            num_format_str="0.0")

        # formatting for special fields
        headline_style = xlwt.easyxf(
            'font: bold on, height 400; alignment: horiz centre, vert centre, wrap on',
            num_format_str="0.0")
        course_style = xlwt.easyxf(
            'alignment: horiz centre, wrap on, rota 90; borders: left medium, top medium'
        )
        course_unfinished_style = xlwt.easyxf(
            'alignment: horiz centre, wrap on, rota 90; borders: left medium, top medium; font: italic on'
        )
        total_answers_style = xlwt.easyxf(
            'alignment: horiz centre; borders: left medium, bottom medium, right medium'
        )

        # general formattings
        bold_style = xlwt.easyxf('font: bold on')
        border_left_style = xlwt.easyxf('borders: left medium')
        border_right_style = xlwt.easyxf('borders: right medium')
        border_top_bottom_right_style = xlwt.easyxf(
            'borders: top medium, bottom medium, right medium')

        self.writec(
            _(u"Evaluation {0} - created on {1}").format(
                self.semester.name, datetime.date.today()), headline_style)
        for course, results in courses_with_results:
            if course.state == "published":
                self.writec(course.name, course_style, cols=2)
            else:
                self.writec(course.name, course_unfinished_style, cols=2)

        self.writen()
        for course, results in courses_with_results:
            self.writec("Average", avg_style)
            self.writec("Variance", border_top_bottom_right_style)

        for questionnaire in questionnaires:
            self.writen(questionnaire.name, bold_style)
            for course, results in courses_with_results:
                self.writec(None, border_left_style)
                self.writec(None, border_right_style)

            for question_index, question in enumerate(
                    questionnaire.question_set.all()):
                if question.is_text_question():
                    continue

                self.writen(question.text)

                for course, results in courses_with_results:
                    qn_results = results.get(questionnaire.id, None)
                    if qn_results:
                        values = []
                        variances = []
                        enough_answers = True
                        for contributor, data, avg_grade, med_grade in qn_results:
                            for grade_result in data:
                                if grade_result.question.id == question.id:
                                    if grade_result.average:
                                        values.append(grade_result.average)
                                        variances.append(grade_result.variance)
                                        if not grade_result.show:
                                            enough_answers = False
                                    break
                        if values and (enough_answers or all):
                            avg = sum(values) / len(values)
                            if avg < 1.5:
                                self.writec(avg, avg_style_very_good)
                            elif avg < 2.5:
                                self.writec(avg, avg_style_good)
                            elif avg < 3.5:
                                self.writec(avg, avg_style_medium)
                            elif avg < 4.5:
                                self.writec(avg, avg_style_bad)
                            else:
                                self.writec(avg, avg_style_very_bad)

                            var = sum(variances) / len(variances)
                            if var < 0.5:
                                self.writec(var, var_style_good)
                            elif var < 1:
                                self.writec(var, var_style_medium)
                            else:
                                self.writec(var, var_style_bad)
                        else:
                            self.writec(None, border_left_style)
                            self.writec(None, border_right_style)
                    else:
                        self.writec(None, border_left_style)
                        self.writec(None, border_right_style)
            self.writen(None)
            for course, results in courses_with_results:
                self.writec(None, border_left_style)
                self.writec(None, border_right_style)

        self.writen(_(u"Overall Average Grade"), bold_style)
        for course, results in courses_with_results:
            avg, med = calculate_average_and_medium_grades(course)
            if avg:
                if avg < 1.5:
                    self.writec(avg, over_style_very_good, cols=2)
                elif avg < 2.5:
                    self.writec(avg, over_style_good, cols=2)
                elif avg < 3.5:
                    self.writec(avg, over_style_medium, cols=2)
                elif avg < 4.5:
                    self.writec(avg, over_style_bad, cols=2)
                else:
                    self.writec(avg, over_style_very_bad, cols=2)
            else:
                self.writec(None, border_left_style)
                self.writec(None, border_right_style)

        self.writen(_(u"Overall Median Grade"), bold_style)
        for course, results in courses_with_results:
            avg, med = calculate_average_and_medium_grades(course)
            if med:
                if med < 2:
                    self.writec(med, over_style_good, cols=2)
                elif avg < 3:
                    self.writec(med, over_style_medium, cols=2)
                else:
                    self.writec(med, over_style_bad, cols=2)
            else:
                self.writec(None, border_left_style)
                self.writec(None, border_right_style)

        self.writen(_(u"Total Answers"), bold_style)
        for course, results in courses_with_results:
            self.writec(course.num_voters, total_answers_style, cols=2)

        self.workbook.save(response)