def test_idr(self):
        expected = {
            "1": 0.0,
            "2": 0.0,
            "3": 0.082,
            "4": 0.082,
            "5": 0.082,
            "6": 0.0,
            "7": -0.082
        }
        idr = calculate_idr(self.data)["idr"]

        assert idr == expected
Beispiel #2
0
def analyze_test(param):
    """
    A function to get an exam's analysis:
    It calls every service used to analyze
    an exam and then returns the analysis.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of dictionaries:
             a dictionary with the results
             of the services as values
    """
    service_key = get_service_config(6)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    # use microservice calls here when all are hosted
    val_kr20 = calculate_kr20(inp)
    val_idr = calculate_idr(inp)
    val_difficulty = calculate_difficulty(inp)
    val_scores = calculate_scores(inp)
    val_average = calculate_average(inp)
    val_weighted_s = calculate_weighted_scores(inp)
    val_weighted_avg = calculate_weighted_average(inp)
    val_excludes = get_exclude_recos(inp)
    val_diff_avg = calculate_difficulty_average(inp)
    val_idr_avg = calculate_idr_average(inp)
    val_num_correct = calculate_num_correct(inp)
    val_assumptions = get_assumptions(inp)
    val_topic_rights = calculate_topic_rights(inp)
    val_topic_avgs = calculate_topic_averages(inp)
    val_group_analysis = analyze_groups(inp)

    # join all results
    result = {}
    items = [
        val_kr20, val_idr, val_difficulty, val_scores, val_average,
        val_weighted_s, val_weighted_avg, val_excludes, val_diff_avg,
        val_idr_avg, val_num_correct, val_assumptions, val_topic_rights,
        val_group_analysis, val_topic_avgs
    ]
    for item in items:
        result.update(item)

    return {service_key: result}
Beispiel #3
0
def get_exclude_recos(param):
    """
    A function to get a recommendation of
    items to exclude from the exam based on
    their idr values:
    It get every item's idr, and if it's less than
    0.09, it adds it to the exclude recommendations.
    If the number of recommendations is greater
    than half the number of items, only recommend
    items with idr values less than 0.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a list of strings: a list of item ids
    """
    service_key = get_service_config(9)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    idr_dict = list(calculate_idr(inp).values())[0]
    if idr_dict == get_keyword_value("bad_mean"):
        return {service_key: get_keyword_value("bad_mean")}
    exclude_list = []
    for i in idr_dict:
        if idr_dict[i] <= get_keyword_value("exclude_threshold_1"):
            exclude_list.append(i)
    
    if len(exclude_list) >= len(idr_dict)*get_keyword_value("exclude_length_1"):
        exclude_list = []
        for i in idr_dict:
            if idr_dict[i] < get_keyword_value("exclude_threshold_2"):
                exclude_list.append(i)
    
    # if len(exclude_list) >= len(idr_dict)*get_keyword_value("exclude_length_2"):
    #     return {service_key: get_keyword_value("bad_exam")}
        
    return {service_key: exclude_list}
Beispiel #4
0
def analyze_groups(param):
    """
    A function to get an exam's analysis by 
    students' group:
    It groups all students by group and 
    then iterates over the groups, calling
    every service used to analyze an exam. 

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of nested dictionaries:
             a dictionary with groups as
             keys and the exam analysis as values
    """
    service_key = get_service_config(14)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    assumptions_key = get_service_config(13)
    assumptions = get_assumptions(inp)[assumptions_key]
    students_dict = sort_students_by_group(inp)
    group_list = get_group_list(inp)
    group_analysis = {}

    if group_list == get_keyword_value("no_group"):
        return {service_key: get_keyword_value("no_group")}

    for i in students_dict:
        curr_students = students_dict[i]
        catch_error = get_error(curr_students)
        if catch_error[0]:
            group_analysis[i] = catch_error[1]
            continue
        student_list = get_student_list(curr_students)

        val_kr20 = calculate_kr20(curr_students)
        val_idr = calculate_idr(curr_students)
        val_difficulty = calculate_difficulty(curr_students)
        val_scores = calculate_scores(curr_students)
        val_average = calculate_average(curr_students)
        val_weighted_s = calculate_weighted_scores(curr_students)
        val_weighted_avg = calculate_weighted_average(curr_students)
        val_excludes = get_exclude_recos(curr_students)
        val_diff_avg = calculate_difficulty_average(curr_students)
        val_idr_avg = calculate_idr_average(curr_students)
        val_num_correct = calculate_num_correct(curr_students)
        val_topic_rights = calculate_topic_rights(curr_students)
        val_topic_avgs = calculate_topic_averages(curr_students)

        curr_assumptions = {}
        for k in assumptions:
            for j in student_list:
                if k == j[get_keyword_value("id")]:
                    curr_assumptions[k] = assumptions[k]
        val_assumptions = {assumptions_key: curr_assumptions}

        result = {
            'overall_quiz': {
                'average': val_average['average'],
                'kr20': val_kr20['kr20'],
                'weighted_avg': val_weighted_avg['weighted_avg']
            },
            'overall_items': {
                'diff_avg': val_diff_avg['diff_avg'],
                'idr_avg': val_idr_avg['idr_avg']
            },
            'item_analysis': [],
            'student_scores': []
        }

        for k in val_difficulty['difficulty']:
            curr_idr = val_idr['idr']
            if curr_idr is not str:
                curr_idr = val_idr['idr'][k]
            result['item_analysis'].append({
                'item_id':
                k,
                'difficulty':
                val_difficulty['difficulty'][k],
                'idr':
                curr_idr,
                'num_correct':
                val_num_correct['num_correct'][k]
            })

        for k in val_scores['scores']:
            result['student_scores'].append({
                'student':
                k,
                'score':
                val_scores['scores'][k],
                'weighted_score':
                val_weighted_s['weighted_scores'][k]
            })

        items = [
            val_excludes, val_assumptions, val_topic_rights, val_topic_avgs
        ]
        for item in items:
            result.update(item)

        group_analysis[i] = result

    return {service_key: group_analysis}
Beispiel #5
0
def analyze_test(param):
    """
    A function to get an exam's analysis:
    It calls every service used to analyze
    an exam and then returns the analysis.

    :param: a json in the Reliabilty Measures
            standard json format
    :return: a dictionary of dictionaries:
             a dictionary with the results
             of the services as values
    """
    service_key = get_service_config(6)
    catch_error = get_error(param)
    if catch_error[0]:
        return {service_key: catch_error[1]}
    inp = update_input(param)
    # use microservice calls here when all are hosted
    val_kr20 = calculate_kr20(inp)
    val_idr = calculate_idr(inp)
    val_difficulty = calculate_difficulty(inp)
    val_scores = calculate_scores(inp)
    val_average = calculate_average(inp)
    val_weighted_s = calculate_weighted_scores(inp)
    val_weighted_avg = calculate_weighted_average(inp)
    val_excludes = get_exclude_recos(inp)
    val_diff_avg = calculate_difficulty_average(inp)
    val_idr_avg = calculate_idr_average(inp)
    val_num_correct = calculate_num_correct(inp)
    val_assumptions = get_assumptions(inp)
    val_topic_rights = calculate_topic_rights(inp)
    val_topic_avgs = calculate_topic_averages(inp)
    val_group_analysis = analyze_groups(inp)

    # join all results
    result = {
        'overall_quiz': {
            'average': val_average['average'],
            'kr20': val_kr20['kr20'],
            'weighted_avg': val_weighted_avg['weighted_avg']
        },
        'overall_items': {
            'diff_avg': val_diff_avg['diff_avg'],
            'idr_avg': val_idr_avg['idr_avg']
        },
        'item_analysis': [],
        'student_scores': []
    }

    for i in val_difficulty['difficulty']:
        curr_idr = val_idr['idr']
        if type(curr_idr) is not str:
            curr_idr = val_idr['idr'][i]
        result['item_analysis'].append({
            'item_id':
            i,
            'difficulty':
            val_difficulty['difficulty'][i],
            'idr':
            curr_idr,
            'num_correct':
            val_num_correct['num_correct'][i]
        })

    for i in val_scores['scores']:
        result['student_scores'].append({
            'student':
            i,
            'score':
            val_scores['scores'][i],
            'weighted_score':
            val_weighted_s['weighted_scores'][i]
        })

    items = [
        val_excludes, val_assumptions, val_topic_rights, val_group_analysis,
        val_topic_avgs
    ]
    for item in items:
        result.update(item)

    return {service_key: result}
    def test_item_excludes_difference(self):
        data_1 = {
            "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": 0},
                        {"item_id": 2, "response": 1},
                        {"item_id": 3, "response": 0},
                        {"item_id": 4, "response": 1}
                    ]
                },
                { 
                    "id": 3,
                    "item_responses": [
                        {"item_id": 1, "response": 0},
                        {"item_id": 2, "response": 0},
                        {"item_id": 3, "response": 1},
                        {"item_id": 4, "response": 1}
                    ]
                },
                { 
                    "id": 4,
                    "item_responses": [
                        {"item_id": 1, "response": 1},
                        {"item_id": 2, "response": 1},
                        {"item_id": 3, "response": 0},
                        {"item_id": 4, "response": 0}
                    ]
                }
            ],
            "exclude_items": [4]
        }
        data_2 = {
            "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": 0},
                        {"item_id": 2, "response": 1},
                        {"item_id": 3, "response": 0},
                        {"item_id": 4, "response": 1}
                    ]
                },
                { 
                    "id": 3,
                    "item_responses": [
                        {"item_id": 1, "response": 0},
                        {"item_id": 2, "response": 0},
                        {"item_id": 3, "response": 1},
                        {"item_id": 4, "response": 1}
                    ]
                },
                { 
                    "id": 4,
                    "item_responses": [
                        {"item_id": 1, "response": 1},
                        {"item_id": 2, "response": 1},
                        {"item_id": 3, "response": 0},
                        {"item_id": 4, "response": 0}
                    ]
                }
            ],
            "exclude_items": [1,3]
        }

        idr_1 = calculate_idr(data_1)
        idr_2 = calculate_idr(data_2)

        assert idr_1 != idr_2