def test_scaled_method(self):
        data = {
            "exam": {
                "scoring_method": "scaled",
                "scaled_factor": .79
            },
            "student_list": [
                {
                    "item_responses": [
                        {"item_id": 1, "response": 1},
                        {"item_id": 2, "response": 0},
                        {"item_id": 3, "response": 1},
                        {"item_id": 4, "response": 1}
                    ]
                },
                {
                    "item_responses": [
                        {"item_id": 1, "response": 1}
                    ]
                }
            ]
        }

        expected = ({"scores": {"1": 0.593, "2": 0.198}}, {"average": 0.395}, 
                    {"weighted_scores": {"1": 0.395, "2": 0.0}}, {"weighted_avg": 0.198})
        scoring = (calculate_scores(data), calculate_average(data), 
                   calculate_weighted_scores(data), calculate_weighted_average(data))

        assert scoring == expected
    def test_absolute_method(self):
        data = {
            "exam": {
                "scoring_method": "absolute"
            },
            "student_list": [
                {
                    "item_responses": [
                        {"item_id": 1, "response": 1},
                        {"item_id": 2, "response": 0},
                        {"item_id": 3, "response": 1},
                        {"item_id": 4, "response": 1}
                    ]
                },
                {
                    "item_responses": [
                        {"item_id": 1, "response": 1}
                    ]
                }
            ]
        }

        expected = ({"scores": {"1": 3.0, "2": 1.0}}, {"average": 2.0}, 
                    {"weighted_scores": {"1": 2.0, "2": 0.0}}, {"weighted_avg": 1.0})
        scoring = (calculate_scores(data), calculate_average(data), 
                   calculate_weighted_scores(data), calculate_weighted_average(data))

        assert scoring == expected
Example #3
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}
    def test_weighted_avg(self):
        expected = 0.444
        weighted_average = calculate_weighted_average(
            self.data)["weighted_avg"]

        assert weighted_average == expected
Example #5
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}
Example #6
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}