コード例 #1
0
ファイル: tests.py プロジェクト: tedkirkpatrick/coursys
    def test_sort_letter(self):
        """
        Test sorting letter grades
        """
        s, c = create_offering()
        
        a = LetterActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, due_date=None, group=False)
        a.save()

        ms = []
        for i in range(10):
            p = Person.objects.get(userid="0aaa%i"%i)
            m = Member(person=p, offering=c, role="STUD", added_reason="UNK")
            m.save()
            ms.append(m)
        
        g = LetterGrade(activity=a, member=ms[0], letter_grade="B+", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[1], letter_grade="A", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[2], letter_grade="D", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[3], letter_grade="B-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[4], letter_grade="P", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[5], letter_grade="GN", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[6], letter_grade="F", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[7], letter_grade="DE", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[8], letter_grade="C-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[9], letter_grade="N", flag="GRAD")
        g.save(entered_by='ggbaker')
        
        g_objs = LetterGrade.objects.filter(activity=a)
        gs = [g.letter_grade for g in g_objs]
        gs_sort = sorted_letters(gs)
        self.assertEquals(gs_sort, ['A', 'B+', 'B-', 'C-', 'D', 'P', 'F', 'DE', 'N', 'GN'])
        
        # pre-sort by userid for median testing (so we know which subsets we're grabbing)
        gs = [(int(g.member.person.userid[4:]), g.letter_grade) for g in g_objs]
        gs.sort()
        gs = [g for u,g in gs]

        # odd-length case
        self.assertEquals(median_letters(sorted_letters(gs[0:5])), "B-")
        # even length with median at boundary
        self.assertEquals(median_letters(sorted_letters(gs[0:6])), "B-/D")
        # empty list
        self.assertEquals(median_letters([]), u"\u2014")
コード例 #2
0
    def test_sort_letter(self):
        """
        Test sorting letter grades
        """
        s, c = create_offering()
        
        a = LetterActivity(name="Assignment 1", short_name="A1", status="RLS", offering=c, position=2, due_date=None, group=False)
        a.save()

        ms = []
        for i in range(10):
            p = Person.objects.get(userid="0aaa%i"%i)
            m = Member(person=p, offering=c, role="STUD", added_reason="UNK")
            m.save()
            ms.append(m)
        
        g = LetterGrade(activity=a, member=ms[0], letter_grade="B+", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[1], letter_grade="A", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[2], letter_grade="D", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[3], letter_grade="B-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[4], letter_grade="P", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[5], letter_grade="GN", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[6], letter_grade="F", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[7], letter_grade="DE", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[8], letter_grade="C-", flag="GRAD")
        g.save(entered_by='ggbaker')
        g = LetterGrade(activity=a, member=ms[9], letter_grade="N", flag="GRAD")
        g.save(entered_by='ggbaker')
        
        g_objs = LetterGrade.objects.filter(activity=a)
        gs = [g.letter_grade for g in g_objs]
        gs_sort = sorted_letters(gs)
        self.assertEqual(gs_sort, ['A', 'B+', 'B-', 'C-', 'D', 'P', 'F', 'DE', 'N', 'GN'])
        
        # pre-sort by userid for median testing (so we know which subsets we're grabbing)
        gs = [(int(g.member.person.userid[4:]), g.letter_grade) for g in g_objs]
        gs.sort()
        gs = [g for u,g in gs]

        # odd-length case
        self.assertEqual(median_letters(sorted_letters(gs[0:5])), "B-")
        # even length with median at boundary
        self.assertEqual(median_letters(sorted_letters(gs[0:6])), "B-/D")
        # empty list
        self.assertEqual(median_letters([]), "\u2014")
コード例 #3
0
ファイル: utils.py プロジェクト: avacariu/coursys
def generate_letter_activity_stat(activity, role):
    """
    This function fetch statistics of the numeric activity.
    """
    if role == 'STUD' and activity.status != 'RLS':
        return None, 'Summary statistics disabled for unreleased activities.'

    student_grade_list = fetch_students_letter_grade(activity)
    sorted_grades = sorted_letters(student_grade_list) 
    if not sorted_grades:
        if role == 'STUD':
            return None, 'Summary statistics disabled for small classes.'
        else:
            return None, 'No grades assigned.'
    if role == 'STUD' and not activity.showstats():
        return None, 'Summary stats disabled by instructor.'

    student_grade_list_count = len(student_grade_list)
    if role == 'STUD' and not activity.showhisto():
        grade_range_stat_list = []
    else:
        grade_range_stat_list = generate_grade_range_stat_lettergrade(student_grade_list)
    median=median_letters(sorted_grades)
    max=max_letters(sorted_grades)
    min=min_letters(sorted_grades)

    stats = ActivityStatlettergrade(grade_range_stat_list, student_grade_list_count,median,min,max)

    reason_msg = ''
    if role == 'STUD' and (stats is None or stats.count < STUD_NUM_TO_DISP_ACTSTAT):
        reason_msg = 'Summary statistics disabled for small classes.'
        stats = None

    return stats, reason_msg
コード例 #4
0
ファイル: utils.py プロジェクト: xhacker/coursys
def generate_letter_activity_stat(activity, role):
    """
    This function fetch statistics of the numeric activity.
    """
    if role == 'STUD' and activity.status != 'RLS':
        return None, 'Summary statistics disabled for unreleased activities.'

    student_grade_list = fetch_students_letter_grade(activity)
    sorted_grades = sorted_letters(student_grade_list)
    if not sorted_grades:
        if role == 'STUD':
            return None, 'Summary statistics disabled for small classes.'
        else:
            return None, 'No grades assigned.'
    if role == 'STUD' and not activity.showstats():
        return None, 'Summary stats disabled by instructor.'

    student_grade_list_count = len(student_grade_list)
    if role == 'STUD' and not activity.showhisto():
        grade_range_stat_list = []
    else:
        grade_range_stat_list = generate_grade_range_stat_lettergrade(
            student_grade_list)
    median = median_letters(sorted_grades)
    max = max_letters(sorted_grades)
    min = min_letters(sorted_grades)

    stats = ActivityStatlettergrade(grade_range_stat_list,
                                    student_grade_list_count, median, min, max)

    reason_msg = ''
    if role == 'STUD' and (stats is None
                           or stats.count < STUD_NUM_TO_DISP_ACTSTAT):
        reason_msg = 'Summary statistics disabled for small classes.'
        stats = None

    return stats, reason_msg