Beispiel #1
0
def test_get_all_options():
    all_options = set([x["course_code"] for x in course_details.get_all(level, True, False)])
    one_option = set([x["course_code"] for x in course_details.get_all(level, False, False)])
    diff = len(all_options - one_option)
    diff_row = [x for x in cur.execute(*sql_get_level()).fetchall() if x["options"] != 0]
    options = len(set([x["options"] for x in diff_row]))
    assert diff == len(diff_row) - options
Beispiel #2
0
def test_get_all_inactive():
    cur.execute(*sql_ins_course())
    conn.commit()
    curr_actives = set([x["course_code"] for x in course_details.get_all(None, True, False)])
    curr_all = set([x["course_code"] for x in course_details.get_all(None, True, True)])
    curr_inactives = curr_all - curr_actives
    assert inv_crs_val[0] in curr_inactives
    cur.execute(*sql_del_course())
    conn.commit()
Beispiel #3
0
def test_get_all_level():
    lvl_courses = course_details.get_all(level, True, False)
    lvl_courses_row = cur.execute(*sql_get_level()).fetchall()
    lvl_codes = set([x["course_code"] for x in lvl_courses_row])
    for course in lvl_courses:
       lvl_codes.remove(course["course_code"])
    assert len(lvl_codes) == 0
Beispiel #4
0
def get_optional_courses(level=None):
    if level and level > 500:
        level = 500
    level_courses = course_details.get_all(level=level, options=True)
    first_sem_options = multisort([(x['code'], x['credit'], x['options'])
                                   for x in level_courses
                                   if x['semester'] == 1 and x['options'] == 1
                                   ])
    second_sem_options = multisort([(x['code'], x['credit'], x['options'])
                                    for x in level_courses
                                    if x['semester'] == 2 and x['options'] == 2
                                    ])
    return first_sem_options, second_sem_options
Beispiel #5
0
def compute_gpa(mat_no, lpad=True):
    entry_session = get_DB(mat_no)
    grade_weight = get_grading_point(entry_session)
    mode_of_entry = personal_info.get(mat_no)["mode_of_entry"]
    level_credits = get_credits(mode_of_entry=mode_of_entry,
                                session=entry_session,
                                lpad=True)
    gpas = [0] * 5
    courses = course_details.get_all(inactive=True,
                                     mode_of_entry=mode_of_entry)
    course_levels = {x["code"]: x["level"] for x in courses}
    res_stmt = result_statement.get(mat_no)
    categories = res_stmt["categories"]
    for idx, result in enumerate(res_stmt["results"]):
        probated, more = categories[idx] == "C", categories[idx + 1:]
        if not (probated and 200 <= result["level"] <= 400 and more):
            for record in (result["first_sem"] + result["second_sem"]):
                (course, credit, grade) = (record[0], record[2], record[4])
                product = grade_weight[grade] * credit
                lvl_idx = ltoi(course_levels[course])
                gpas[lvl_idx] += (product / level_credits[lvl_idx])
    if lpad:
        return gpas[mode_of_entry - 1:]
    return gpas
Beispiel #6
0
def test_get_course_details():
    assert course_details.get_course_details(valid_course) == ([course_details.get(valid_course)], 200)
    assert course_details.get_course_details(inv_crs_val[0]) == (None, 404)
    assert course_details.get_course_details() == (course_details.get_all(), 200)
Beispiel #7
0
def test_get_all_default():
    all_courses = course_details.get_all()
    sql_all_courses = cur.execute(*sql_all_courses_active).fetchall()
    assert len(sql_all_courses) == len(all_courses)
Beispiel #8
0
def render_html(item,
                acad_session,
                index_to_display,
                file_dir,
                first_sem_only=False):
    level, mat_nos = item
    color_map = {'F': 'red', 'F *': 'red', 'ABS': 'blue', 'ABS *': 'blue'}
    dept = get_dept()
    dept_title_case = ' '.join(map(str.capitalize, dept.split(' ')))
    empty_value = ' '

    # get semester courses (with one placeholder option)
    level_courses = course_details.get_all(level=level, options=False)
    first_sem_courses = multisort([(x['code'], x['credit'], x['options'])
                                   for x in level_courses
                                   if x['semester'] == 1])
    second_sem_courses = multisort([(x['code'], x['credit'], x['options'])
                                    for x in level_courses
                                    if x['semester'] == 2])

    # get optional courses
    first_sem_options, second_sem_options = get_optional_courses(level)

    courses = {
        'first_sem': dictify(first_sem_courses + first_sem_options),
        'second_sem': dictify(second_sem_courses + second_sem_options)
    }
    students, len_first_sem_carrys, len_second_sem_carrys = enrich_mat_no_list(
        mat_nos, acad_session, level, courses)
    students = tuple(students.items())

    fix_table_column_width_error = 8 if first_sem_only else 4
    len_first_sem_carrys = max(len_first_sem_carrys,
                               fix_table_column_width_error)
    len_second_sem_carrys = max(len_second_sem_carrys,
                                fix_table_column_width_error)

    if first_sem_only or len_first_sem_carrys + len_second_sem_carrys < 18:
        pagination = 15
    elif len(second_sem_courses) == 1:
        pagination = 15
    else:
        pagination = 18

    iters = len(students) // pagination

    for ite in range(iters + 1):
        left = ite * pagination
        right = (ite + 1) * pagination
        paginated_students = dict(students[left:right])

        with current_app.app_context():
            html = render_template(
                'broad_sheet.html',
                enumerate=enumerate,
                sum=sum,
                int=int,
                url_for=url_for,
                start_index=left,
                len_first_sem_carryovers=len_first_sem_carrys,
                len_second_sem_carryovers=len_second_sem_carrys,
                index_to_display=index_to_display,
                empty_value=empty_value,
                color_map=color_map,
                first_sem_courses=first_sem_courses,
                second_sem_courses=second_sem_courses,
                first_sem_options=first_sem_options,
                second_sem_options=second_sem_options,
                students=paginated_students,
                session=acad_session,
                level=level,
                first_sem_only=first_sem_only,
                dept_title_case=dept_title_case,
            )
            open(
                os.path.join(CACHE_BASE_DIR, file_dir,
                             '{}_{}_render.html'.format(level, ite + 1)),
                'w').write(html)
Beispiel #9
0
from sms.src import utils, personal_info, course_details, result_statement

start = 2003
stop = 2019

crs_lvl = [0, 0, 0, 0]
for i in range(1, 4):
    crs_lvl[i] = course_details.get_all(inactive=True, mode_of_entry=i)
    crs_lvl[i] = {x["code"]: x["level"] for x in crs_lvl[i]}


def rule_2_3():
    bad_mat_1 = set()
    bad_mat_2 = set()
    for session in range(start, stop):
        sess = utils.load_session(session)
        mats = [x.mat_no for x in sess.PersonalInfo.query.all()]
        for mat_no in mats:
            # print(mat_no)
            catg = result_statement.get(mat_no)["categories"]
            if catg.count("C") > 1:
                bad_mat_1.add(mat_no)
            d_idx = (catg + ["D"]).index("D")
            if (catg + ["D"])[d_idx + 1:]:
                bad_mat_2.add(mat_no)
    print("Rule 2 defaulters\n", bad_mat_1)
    print("Rule 3 defaulters\n", bad_mat_2)


def rule_1_4():
    bad_mat_1 = set()