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

        expected = [1, 2]
        id_list = utils.get_item_ids(data)

        assert id_list == expected
    def test_with_item_excludes(self):
        data = {
            "student_list": [{
                "id":
                1,
                "item_responses": [{
                    "item_id": "1",
                    "response": 1
                }, {
                    "item_id": "2",
                    "response": 0
                }, {
                    "item_id": "3",
                    "response": 1
                }, {
                    "item_id": "4",
                    "response": 0
                }]
            }, {
                "id":
                2,
                "item_responses": [{
                    "item_id": "1",
                    "response": 1
                }]
            }],
            "exclude_items": ["4"]
        }

        expected = ["1", "2", "3"]
        id_list = utils.get_item_ids(data)

        assert id_list == expected
def get_assumptions(param):
    """
    A function to get the items for which a
    student was assumed to have a response
    of 0:
    It gets a list of all item ids listed from
    every student's responses, then iterates
    through every student. If a student doesn't
    have a response for an item in the id list,
    then that item is assumed to have a response
    of 0 for that student.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of dictionaries:
             a dictionary with student ids as keys
             and a list of item ids as values
    """
    service_key = get_service_config(13)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    student_list = get_student_list(inp)
    id_list = get_item_ids(inp)
    assumptions_dict = {}

    for i in student_list:  # For each student i
        checklist = id_list.copy()
        dupes = []
        for k in i[get_keyword_value("item_responses")]:  # For each question k
            for j in id_list:  # For each item ID j
                if k[get_keyword_value("item_id")] == j:  # If item IDs match
                    if j in checklist:
                        checklist.remove(j)
                    else:
                        dupes.append(j)
        if dupes:
            assumptions_dict[i[get_keyword_value("id")]] = {}
            assumptions_dict[i[get_keyword_value("id")]][get_keyword_value(
                "dupes")] = dupes

        if len(checklist) != 0:
            assumptions_dict[i[get_keyword_value("id")]] = {}
            assumptions_dict[i[get_keyword_value("id")]][get_keyword_value(
                "assumed")] = checklist.copy()

    if not assumptions_dict:
        return {service_key: get_keyword_value("no_assumptions")}

    return {service_key: assumptions_dict}
Beispiel #4
0
def calculate_difficulty(param):
    """
    A function to get the difficulty of 
    each item on the exam:
    It calculates how many students got an
    item correct, and then divides it by
    the total number of students.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of floats: a dictionary
             with item ids as keys and the
             difficulty as values
    """
    service_key = get_service_config(3)
    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)
    num_students = len(sorted_resp)
    num_items = len(sorted_resp[0])
    id_list = get_item_ids(inp)
    difficulty_list = []
    difficulty_dict = {}

    for i in range(0, num_items):  # For each question i
        numRight = 0
        for k in range(0, num_students):  # For each student k
            studentAnswer = sorted_resp[k][i]
            numRight += studentAnswer
        difficulty = 1 - numRight / num_students
        difficulty = round(difficulty, 3)
        difficulty_list.append(difficulty)

    k = 0
    for i in id_list:
        difficulty_dict[i] = difficulty_list[k]
        k += 1

    return {service_key: difficulty_dict}
Beispiel #5
0
def calculate_idr(param):
    """
    A function to get the idr of each item:
    For every item, it calculates the mean score
    of students who got the answer right and subtracts
    it by the mean score of those who got it wrong.
    Then it multiplies that by the square root of 
    the number of students who got the item right
    multiplied by the total of those who got it wrong.
    Then it divides that by the number of students
    multiplied by the std of the students' scores.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of floats: a dictionary with
             item ids as keys and idr as values
    """
    service_key = get_service_config(2)
    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)
    num_students = len(sorted_resp)
    num_items = len(sorted_resp[0])
    id_list = get_item_ids(inp)
    score_std = get_score_std(inp)
    idr_list = []
    idr_dict = {}

    if score_std < 0:
        return {service_key: get_keyword_value("bad_std")}

    for i in range(0, num_items):  # For each question i
        right_list = []
        wrong_list = []
        num_right = 0
        num_wrong = 0
        for k in range(0, num_students):  # For each student k
            if sorted_resp[k][i] == 1:  # If student k gets question i correct
                score = sum(sorted_resp[k]) / num_items
                right_list.append(
                    score)  # Then add their score to the "right" list
                num_right += 1
            elif sorted_resp[k][i] == 0:  # If student k gets question i wrong
                score = sum(sorted_resp[k]) / num_items
                wrong_list.append(
                    score)  # Then add their score to the "wrong" list
                num_wrong += 1

        if num_right == num_students or num_wrong == num_students:
            idr_list.append(0)
            continue
        if len(right_list) == 1:
            right_mean = right_list[0]
        elif len(right_list) > 1:
            right_mean = mean(right_list)
        if len(wrong_list) == 1:
            wrong_mean = wrong_list[0]
        elif len(wrong_list) > 1:
            wrong_mean = mean(wrong_list)
        if not right_mean or not wrong_mean:
            return {service_key: get_keyword_value("bad_mean")}

        idr = ((right_mean - wrong_mean) *
               sqrt(num_right * num_wrong)) / num_students * score_std
        idr = round(idr, 3)
        idr_list.append(idr)

    k = 0
    for i in id_list:
        idr_dict[i] = idr_list[k]
        k += 1

    return {service_key: idr_dict}
    def test_get_item_ids(self):
        expected = ["1", "2", "3", "4", "5", "6", "7", "8"]
        item_ids = utils.get_item_ids(self.data)

        assert item_ids == expected