def test_without_student_excludes(self):
        data = {
            "student_list": [{
                "id":
                1,
                "item_responses": [{
                    "item_id": 1,
                    "response": 1
                }, {
                    "item_id": 2,
                    "response": 0
                }]
            }, {
                "id":
                2,
                "item_responses": [{
                    "item_id": 1,
                    "response": 1
                }, {
                    "item_id": 2,
                    "response": 0
                }]
            }]
        }

        expected = [1, 2]
        stud_ids = utils.get_student_ids(data)

        assert stud_ids == expected
def calculate_weighted_scores(param):
    """
    A function to get the weighted score of each student:
    For each student, it gets the weight of every item
    they got correct by getting its difficulty and dividing
    it by the sum of all items' difficulties.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of floats: a dictionary with
             student ids as keys and their weighted score 
             as values
    """
    service_key = get_service_config(7)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    student_ids = get_student_ids(inp)
    sorted_resp = get_sorted_responses(inp)
    scoring_method = get_scoring_method(inp)
    num_items = len(sorted_resp[0])
    difficulty_list = list(
        list(calculate_difficulty(inp).values())[0].values())
    difficulty_sum = sum(difficulty_list)
    weighted_scores_dict = {}

    for curr_id in student_ids:
        weighted_scores_dict[curr_id] = None

    j = 0
    for i in weighted_scores_dict:
        weighted = 0
        for k in range(0, num_items):
            if sorted_resp[j][k] == 1:
                weighted += difficulty_list[k]
        weighted /= difficulty_sum
        if scoring_method[0] == get_keyword_value("percentage"):
            weighted = round(weighted * 100, 3)
        elif scoring_method[0] == get_keyword_value("absolute"):
            weighted = round(weighted * num_items, 3)
        elif scoring_method[0] == get_keyword_value("scaled"):
            weighted = round(weighted * scoring_method[1], 3)
        else:
            weighted = round(weighted, 3)
        weighted_scores_dict[i] = weighted
        j += 1

    return {service_key: weighted_scores_dict}
Exemple #3
0
def calculate_scores(param):
    """
    A function to get the score of each student:
    For each student, it gets the number of correct
    responses and divides it by the number of questions.

    :param: a json in the Reliability Measures
            standard json format
    :return: a dictionary of floats: a dictionary with
             student ids as keys and their score as values
    """
    service_key = get_service_config(4)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    sorted_resp = get_sorted_responses(inp)
    student_ids = get_student_ids(inp)
    scoring_method = get_scoring_method(inp)
    num_items = len(sorted_resp[0])
    score_dict = {}

    for curr_id in student_ids:
        score_dict[curr_id] = None

    k = 0
    for i in score_dict:
        num_right = sum(sorted_resp[k])
        score = num_right / num_items
        if scoring_method[0] == get_keyword_value("percentage"):
            score = round(score * 100, 3)
        elif scoring_method[0] == get_keyword_value("absolute"):
            score = round(score * num_items, 3)
        elif scoring_method[0] == get_keyword_value("scaled"):
            score = round(score * scoring_method[1], 3)
        else:
            score = round(score, 3)
        score_dict[i] = score
        k += 1

    return {service_key: score_dict}
    def test_with_student_excludes(self):
        data = {
            "student_list": [{
                "id":
                "1",
                "item_responses": [{
                    "item_id": "1",
                    "response": 1
                }, {
                    "item_id": "2",
                    "response": 0
                }]
            }, {
                "id":
                "2",
                "item_responses": [{
                    "item_id": "1",
                    "response": 1
                }, {
                    "item_id": "2",
                    "response": 0
                }]
            }, {
                "id":
                "3",
                "item_responses": [{
                    "item_id": "1",
                    "response": 1
                }, {
                    "item_id": "2",
                    "response": 0
                }]
            }],
            "exclude_students": ["1"]
        }

        expected = ["2", "3"]
        stud_ids = utils.get_student_ids(data)

        assert stud_ids == expected
    def test_get_student_ids(self):
        expected = ["1234", "1235", "1236"]
        stud_ids = utils.get_student_ids(self.data)

        assert stud_ids == expected