def render_class(class_id, error=None): # format class tables names tables = database(class_id) #query database classrow = select_all_from_row(tables['classes'], 'id', class_id) schoolrow = select_school_by_id(session['user_id']) subjectrow = select_all_from_table(tables['subjects']) classlistrow = select_all_from_table(tables['classlist']) # render class veiw if error: flash(error, 'failure') return render_template("classView.html", schoolInfo=schoolrow, classData=classrow, subjectData=subjectrow, class_list=classlistrow, error=error)
def add_student(student_id, class_id): tables = database(class_id) student_grade = select_all_from_row(tables['grade'], 'id', student_id) all_std = select_all_from_table(tables['grade']) subjects = select_all_from_table(tables['subjects']) totals = select_all_from_row(tables['mastersheet'], 'id', student_id) class_details = select_all_from_row(tables['classes'], 'id', class_id) #for each subject in grades student_total = 0 new_total = 0 pass_mark = grade(0)["pass_mark"] for subject in subjects: student_total = student_total + int(totals[0][str(subject["id"])]) the_grade = student_grade[0][str(subject["id"])][0] #form the column string for no_of_column the_column = "no_of_" + str(the_grade).lower() current = int(subject[the_column]) #subract 1 from that no_of_column in subjects new_total = int(subject["total_score"]) + int(totals[0][str( subject["id"])]) new_average = new_total / len(all_std) #subtract students total from subjects total previous = select_all_from_row(tables['grades'], 'id', student_id) new_no = int(previous[0][the_column]) + 1 update_table(tables['subjects'],['total_score', 'class_average', the_column],\ [new_total, new_average, (current + 1) ], 'id', subject['id']) update_table(tables['grade'], the_column, new_no, 'id', student_id) assign_subject_position(class_id, subject["id"]) if len(subjects) > 0: student_average = student_total / len(subjects) update_table(tables['mastersheet'], ['average', 'total_score'], [student_average, student_total], 'id', student_id) if pass_mark > student_average: update_table(tables['classes'], 'no_of_failures', (class_details[0]['no_of_failures'] + 1), 'id', class_id) else: update_table(tables['classes'], 'no_of_passes', (class_details[0]['no_of_passes'] + 1), 'id', class_id) assign_student_position(class_id)
def render_portfolio(error=None): tables = database(0) rows = select_school_by_id(session['user_id']) classrows = select_all_from_table(tables['classes']) if error: flash(error, 'failure') return render_template("portfolio.html", schoolInfo=rows, clas=classrows, error=error)
def remove_student(student_id, class_id): tables = database(class_id) student_grade = select_all_from_row(tables['grade'], 'id', student_id) subjects = select_all_from_table(tables['subjects']) students = select_all_from_table(tables['classlist']) totals = select_all_from_row(tables['mastersheet'], 'id', student_id) #class_details = select_all_from_row(tables['settings'],'id', class_id) delete_from_id(tables['mastersheet'], student_id) #for each subject in grades for subject in subjects: #get students grade in this subject the_grade = student_grade[0][str(subject["id"])] #form the column string for no_of_column the_column = "no_of_" + str(the_grade[0].lower()) current = int(subject[the_column]) #subract 1 from that no_of_column in subjects new_total = int(subject["total_score"]) - int(totals[0][str( subject["id"])]) #subtract students total from subjects total update_table(tables['subjects'], 'total_score', new_total, 'id', subject['id']) no_of_students = len(students) - 1 if no_of_students == 0: new_average = 0 else: new_average = new_total / no_of_students update_table(tables['subjects'], ['class_average', the_column],\ [new_average, current-1], 'id', subject['id'] ) assign_subject_position(class_id, subject["id"]) #student_average = totals[0]["average"] #pass_mark = grade(0)["pass_mark"] delete_from_id(tables['ca'], student_id) delete_from_id(tables['grade'], student_id) delete_from_id(tables['test'], student_id) delete_from_id(tables['exam'], student_id) delete_from_id(tables['subject_position'], student_id) delete_from_id(tables['classlist'], student_id) assign_student_position(class_id)
def assign_subject_position(class_id, subject_id): tables = database(class_id) subject = str(subject_id) subject_position = select_all_from_table(tables['mastersheet']) for student in subject_position: student[subject] = float(student[subject]) subject_pos = sorted(subject_position, key=itemgetter(subject), reverse=True) j = 0 i = 0 previous = 101 for person in subject_pos: if previous == float(person[subject]): update_table(tables['subject_position'], subject, ith_position(j), 'id', person['id']) else: j = i + 1 update_table(tables['subject_position'], subject, ith_position(j), 'id', person['id']) i = i + 1 previous = float(person[subject])
def assign_student_position(class_id): tables = database(class_id) student_position = select_all_from_table(tables['mastersheet']) for student in student_position: student["average"] = float(student["average"]) student_position = sorted(student_position, key=itemgetter('average'), reverse=True) j = 0 i = 0 previous = None for person in student_position: if previous == float(person["average"]): update_table(tables['mastersheet'], 'position', ith_position(j), 'id', person['id']) else: j = i + 1 update_table(tables['mastersheet'], 'position', ith_position(j), 'id', person['id']) i = i + 1 previous = float(person["average"])
def new_term(school_session, term): tables = database(0) selected_term = term selected_session = school_session former_term_settings = select_all_from_table(tables['settings']) #new_session = selected_session+"_"+selected_term insert_into_table(tables['terms'], ['session', 'term'], [session, term]) class_term_data = "settings" + "_" + str(selected_term) + "_" + str( selected_session) + "_" + str(session["user_id"]) copy_table(class_term_data, tables['settings']) for clas in former_term_settings: former = database(clas["id"]) #class_subjects = select_all_from_row(former["subjects"],'id', clas["id"]) # format class tables names classsql = str(clas["id"])+"_"+str(selected_term)+"_"+\ str(selected_session)+"_"+str(former["school_id"]) classlist = "classlist" + "_" + classsql ca = "catable" + "_" + classsql test = "testtable" + "_" + classsql exam = "examtable" + "_" + classsql subjects = "subjects" + "_" + classsql mastersheet = "mastersheet" + "_" + classsql subject_position = "subject_position" + "_" + classsql grade = "grade" + "_" + classsql # create classlist copy_table(classlist, former['classlist']) #create tables create_subjects_table(subjects) # create catable create_ca_table(ca, classlist) # create grade create_grades_table(grade, classlist) # create testtable create_test_table(test, classlist) # create examtable create_exam_table(exam, classlist) # create mastersheet create_mastersheet_table(exam, classlist) # create subject_position create_subject_position_table(subject_position, classlist) #copy classlist tables = database(clas["id"]) current_classlist = select_all_from_table(classlist) pins = generate_pins(10, 30) #change pins for classlist i = 0 for student in current_classlist: update_table(classlist, 'pin', pins[i], 'id', student['id']) update_table(ca, 'id', student['id']) update_table(test, 'id', student['id']) update_table(exam, 'id', student['id']) update_table(grade, 'id', student['id']) update_table(subject_position, 'id', student['id']) update_table(mastersheet, 'id', student['id']) i = i + 1 #update term om school update_table('school', 'current_term', selected_term, 'id', session['user_id'])