prof_api/helper_functions.py
def convert_to_general_overall(json_query):
    """
    Given a JSON query, typically with multiple courses, returns the
    general statistics of all courses under which the JSON query contains
    :param json_query:
    :return:
    """
    if len(json_query) == 0:
        return {}

    d = {
        'undergrad': {
            'grades': {},
            'average': 0,
            'stdev': 0,
            'median': 0,
            'pass': 0
        },
        'all': {
            'grades': {},
            'average': 0,
            'stdev': 0,
            'median': 0,
            'pass': 0
        }
    }

    pass_ratio_undergrad = 0
    undergrad_arr = []
    undergrad_std = []
    count_undergrad = 0

    pass_ratio_all = 0
    all_arr = []
    all_std = []
    count_all = 0

    for query in json_query:
        grades = query['grades']
        stats = query['stats']

        # Attempts to find whether or the course has an additional letter at the end
        # If it does, then we will use the condensed version
        try:
            course_no = int(query['course'])
        except ValueError:
            course_no = int(query['course'][0:3])

        # Check that there are actually statistics for this course before adding values in
        if stats['average'] == '':
            continue

        add_grade_values(course_no, d, grades)

        if course_no < 500:
            undergrad_arr.append(stats['average'])
            undergrad_std.append(stats['stdev'] ** 2)
            pass_ratio_undergrad += stats['pass']
            count_undergrad += (stats['pass'] + stats['fail'])

        all_arr.append(stats['average'])
        all_std.append(stats['stdev'] ** 2)
        pass_ratio_all += stats['pass']
        count_all += (stats['pass'] + stats['fail'])

    calculate_undergrad_to_json(d, pass_ratio_undergrad, undergrad_arr, undergrad_std, count_undergrad)
    calculate_all_to_json(all_arr, all_std, d, pass_ratio_all, count_all)

    return d

    Given a JSON query, typically with multiple courses, returns the
    general statistics of all courses under which the JSON query contains
    :param json_query:
    :return:
    
Given a JSON query, typically with multiple courses, returns the
general statistics of all courses under which the JSON query contains
Given a JSON query typically with multiple courses returns the general statistics of all courses under which the JSON query contains
def convert_to_general_overall(json_query):
    if len(json_query) == 0:
        return {}
    d = {
        'undergrad': {
            'grades': {},
            'average': 0,
            'stdev': 0,
            'median': 0,
            'pass': 0
        },
        'all': {
            'grades': {},
            'average': 0,
            'stdev': 0,
            'median': 0,
            'pass': 0
        }
    }
    pass_ratio_undergrad = 0
    undergrad_arr = []
    undergrad_std = []
    count_undergrad = 0
    pass_ratio_all = 0
    all_arr = []
    all_std = []
    count_all = 0
    for query in json_query:
        grades = query['grades']
        stats = query['stats']
        try:
            course_no = int(query['course'])
        except ValueError:
            course_no = int(query['course'][0:3])
        if stats['average'] == '':
            continue
        add_grade_values(course_no, d, grades)
        if course_no < 500:
            undergrad_arr.append(stats['average'])
            undergrad_std.append(stats['stdev'] ** 2)
            pass_ratio_undergrad += stats['pass']
            count_undergrad += (stats['pass'] + stats['fail'])
        all_arr.append(stats['average'])
        all_std.append(stats['stdev'] ** 2)
        pass_ratio_all += stats['pass']
        count_all += (stats['pass'] + stats['fail'])
    calculate_undergrad_to_json(d, pass_ratio_undergrad, undergrad_arr, undergrad_std, count_undergrad)
    calculate_all_to_json(all_arr, all_std, d, pass_ratio_all, count_all)
    return d
def convert_to_general_overall ( json_query ) : if len ( json_query ) == 0 : return { } d = { 'undergrad' : { 'grades' : { } , 'average' : 0 , 'stdev' : 0 , 'median' : 0 , 'pass' : 0 } , 'all' : { 'grades' : { } , 'average' : 0 , 'stdev' : 0 , 'median' : 0 , 'pass' : 0 } } pass_ratio_undergrad = 0 undergrad_arr = [ ] undergrad_std = [ ] count_undergrad = 0 pass_ratio_all = 0 all_arr = [ ] all_std = [ ] count_all = 0 for query in json_query : grades = query [ 'grades' ] stats = query [ 'stats' ] try : course_no = int ( query [ 'course' ] ) except ValueError : course_no = int ( query [ 'course' ] [ 0 : 3 ] ) if stats [ 'average' ] == '' : continue add_grade_values ( course_no , d , grades ) if course_no < 500 : undergrad_arr . append ( stats [ 'average' ] ) undergrad_std . append ( stats [ 'stdev' ] ** 2 ) pass_ratio_undergrad += stats [ 'pass' ] count_undergrad += ( stats [ 'pass' ] + stats [ 'fail' ] ) all_arr . append ( stats [ 'average' ] ) all_std . append ( stats [ 'stdev' ] ** 2 ) pass_ratio_all += stats [ 'pass' ] count_all += ( stats [ 'pass' ] + stats [ 'fail' ] ) calculate_undergrad_to_json ( d , pass_ratio_undergrad , undergrad_arr , undergrad_std , count_undergrad ) calculate_all_to_json ( all_arr , all_std , d , pass_ratio_all , count_all ) return d
Given a JSON query, typically with multiple courses, returns the
general statistics of all courses under which the JSON query contains
Given a JSON query typically with multiple courses returns the general statistics of all courses under which the JSON query contains
"""
    Given a JSON query, typically with multiple courses, returns the
    general statistics of all courses under which the JSON query contains
    :param json_query:
    :return:
    """ # Attempts to find whether or the course has an additional letter at the end # If it does, then we will use the condensed version # Check that there are actually statistics for this course before adding values in
None
json_query
None