Ejemplo n.º 1
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        # TODO: complete the body of this method
        num1 = 0
        num2 = 0
        if len(grouping.get_groups()) == 0:
            return 0.0

        for g in grouping.get_groups():
            score = self.score_students(g.get_members())
            num1 = num1 + score
            num2 = num2 + 1
        return num1 / num2
Ejemplo n.º 2
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        if len(grouping) == 0:
            return 0.0
        else:
            total_score = 0.0
            amount_of_scores = 0
            for group in grouping.get_groups():
                total_score += self.score_students(group.get_members())
                amount_of_scores += 1
        return total_score / amount_of_scores
Ejemplo n.º 3
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        if len(grouping) == 0:
            return 0.0
        lst_of_group_scores = []
        for group in grouping.get_groups():
            lst_of_studs = group.get_members()
            # the students in each group
            score_of_group = self.score_students(lst_of_studs)
            # the score for the group
            lst_of_group_scores.append(score_of_group)
        try:
            return sum(lst_of_group_scores) / len(lst_of_group_scores)
        except ZeroDivisionError:
            return 0.0
Ejemplo n.º 4
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        if grouping.__len__() == 0:
            return 0.0
        list_of_score = []
        for group in grouping.get_groups():
            s = group.get_members()
            list_of_score.append(self.score_students(s))
        sum = 0
        for score in list_of_score:
            sum += score
        return sum / len(list_of_score)
Ejemplo n.º 5
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        # Get groups from grouping
        groups_to_score = grouping.get_groups()
        num_groups = len(groups_to_score)
        total_score = 0

        # If grouping comes back empty
        if len(groups_to_score) == 0:
            return 0.0

        # for each group
        for group_to_score in groups_to_score:
            students_to_score = group_to_score.get_members()
            total_score += self.score_students(students_to_score)

        average_score = total_score / num_groups
        return average_score
Ejemplo n.º 6
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        score = 0.0
        count = 0
        group_list = grouping.get_groups()

        for group in group_list:
            student_list = group.get_members()
            score += self.score_students(student_list)
            count += 1

        if count == 0:
            return 0.0
        return score / count
Ejemplo n.º 7
0
def get_member_ids(grouping: grouper.Grouping) -> Set[FrozenSet[int]]:
    member_ids = set()
    for group in grouping.get_groups():
        ids = []
        for member in group.get_members():
            ids.append(member.id)
        member_ids.add(frozenset(ids))
    return member_ids
Ejemplo n.º 8
0
def test_grouper_grouping_get_groups() -> None:
    """A test for get_groups() in class Grouping."""
    s1 = Student(1, 'A')
    s2 = Student(2, 'B')
    s3 = Student(3, 'C')
    s4 = Student(4, 'D')
    g1 = Group([s1, s2])
    g2 = Group([s3, s4])
    grouping = Grouping()
    grouping.add_group(g1)
    grouping.add_group(g2)
    result = grouping.get_groups()
    assert g1 in result
    assert g2 in result
Ejemplo n.º 9
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        student_list = []
        # total score
        group_score = 0

        # check if grouping is empty
        if len(grouping.get_groups()) == 0:
            return 0

        # get average of all questions for each group
        try:
            for group in grouping.get_groups():
                # make a list of students in each group
                student_list = []
                for student in group.get_members():
                    student_list.append(student)
                group_score += self.score_students(student_list)

            return group_score / len(grouping.get_groups())

        except InvalidAnswerError:
            return 0
Ejemplo n.º 10
0
    def score_grouping(self, grouping: Grouping) -> float:
        """ Return a score for <grouping> calculated based on the answers of
        each student in each group in <grouping> to the questions in <self>.

        If there are no groups in <grouping> this score is 0.0. Otherwise, this
        score is determined using the following algorithm:

        1. For each group in <grouping>, get the score for the members of this
           group calculated based on their answers to the questions in this
           survey.
        2. Return the average of all the scores calculated in step 1.

        === Precondition ===
        All students in the groups in <grouping> have an answer to all questions
            in this survey
        """
        # TODO: complete the body of this method
        if grouping._groups == []:
            return 0

        scores = []
        for group in grouping.get_groups():
            scores.append(self.score_students(group.get_members()))
        return sum(scores) / len(scores)
Ejemplo n.º 11
0
def grouping_to_list_of_list_flatten(grouping: grouper.Grouping):
    r = []
    for g in grouping.get_groups():
        r.extend([x.id for x in g.get_members()])
    r.sort()
    return r
Ejemplo n.º 12
0
def grouping_to_list_of_list(grouping: grouper.Grouping):
    r = []
    for g in grouping.get_groups():
        r.append(sorted([x.id for x in g.get_members()]))
    r.sort()
    return r
Ejemplo n.º 13
0
def test_grouper() -> None:
    assert windows([3, 4, 6, 2, 3], 2) == [[3, 4], [4, 6], [6, 2], [2, 3]]
    assert windows(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [1, 6.0, False]]
    assert slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]]
    assert slice_list(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [False]]

    g = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")])
    g_1 = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")])
    g_2 = Group([Student(5, "roney"), Student(6, "tim"), Student(7, "allen")])
    assert len(g) == 3
    assert Student(1, "roney") in g
    assert "roney" in str(g)
    gr = Grouping()
    assert gr.add_group(g)
    assert not gr.add_group(g_1)
    assert gr.add_group(g_2)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = AlphaGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = AlphaGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = RandomGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    course_0.enroll_students(
        [Student(1, "a"), Student(2, "b"), Student(3, "c")])
    s = Survey([YesNoQuestion(1, "Is earth round")])
    ag = RandomGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    ag = GreedyGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    ag = GreedyGrouper(3)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 1
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 3, 2]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3])
    s = Survey([q])
    s.set_criterion(LonelyMemberCriterion(), q)
    ag = GreedyGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 3]
    assert groups[1]._member_id == [2]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(True))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(True))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(LonelyMemberCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HeterogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(True))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HomogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [1, 2]
    assert groups[1]._member_id == [3, 4]

    course_0 = Course("Snake")
    s1 = Student(1, "a")
    s2 = Student(2, "b")
    s3 = Student(3, "c")
    s4 = Student(4, "d")
    q = YesNoQuestion(1, "Is earth round")
    s1.set_answer(q, Answer(True))
    s2.set_answer(q, Answer(False))
    s3.set_answer(q, Answer(False))
    s4.set_answer(q, Answer(False))
    course_0.enroll_students([s1, s2, s3, s4])
    s = Survey([q])
    s.set_criterion(HomogeneousCriterion(), q)
    ag = WindowGrouper(2)
    gr = ag.make_grouping(course_0, s)
    assert len(gr) == 2
    groups = gr.get_groups()
    assert groups[0]._member_id == [2, 3]
    assert groups[1]._member_id == [1, 4]