def handle_main_menu_requests(user_request, idx, name, surname): """ Call function that perform task from menu choosen by user: see list of students, mentors, edit mentors, use talkbox Args: user_request (string): option choosen by user idx (string): uniqe person id name (string): person name surname (strin): person surname """ if user_request == '1': get_mentors_list(lock=True) elif user_request == '2': start_mentor_edit_menu() elif user_request == '3': get_students_list() elif user_request == "4": rank = student_controller.get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() elif user_request == '5': codecooler_controller.change_password(idx) elif user_request == "6": talkbox.start_talkbox(name, surname)
def _calculate_attendnace(students_attendance, given_student_idx): """ Calculate student attendance in percents. Args: students_attendance (list of :obj: `AttendanceModel`): list with detail of attendance for all students student_idx (str): uniqe id number of student Raises: ZeroDivisionError: if student have no records about attendance """ attendance_sum = 0 max_possible_attendance = 0 for student in students_attendance: if student.student_idx == given_student_idx: attendance_sum += float(student.state) max_possible_attendance += 1 try: attendance_procent = round( ((attendance_sum / max_possible_attendance) * 100), 2) except ZeroDivisionError: codecooler_view.print_error_message("This student have no attendance") sleep(1.5) else: codecooler_view.print_result( "Student attendance {}%\n".format(attendance_procent)) codecooler_view.state_locker()
def show_ranking(): """ Call functions to display students ranking by grades """ rank = student_controller.get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() codecooler_view.clear_window()
def get_students_list(): """ Call functions to display students list as formatted table """ titles = ["Idx", "Password", "Name", "Surname", "Email"] students = instances_manager.prepare_data_to_visualize(Student.student_list) codecooler_view.clear_window() codecooler_view.print_table(titles, students) codecooler_view.state_locker()
def get_mentors_list(lock=False): """ Call functions to display formatted table with all Mentor objects details """ titles = ["Idx", "Password", "Name", "Surname", "Email"] mentors = instances_manager.prepare_data_to_visualize(Mentor.mentor_list) codecooler_view.print_table(titles, mentors) if lock: codecooler_view.state_locker()
def show_debt(idx): """ Call functions to display student's debet Args: idx (string): unique user's id """ debt = calculate_debt(idx) codecooler_view.print_result( "If you will leave us now, your debt will be ~{} PLN.\n".format(debt)) codecooler_view.state_locker()
def _check_attendance(students_attendance, students): """ Create `AttendnaceModel` object with given student id, state and current date. Args: students_attendance (list of :obj: `AttendanceModels`): list with detail of attendance for all students students (list of :obj: `StudentModels`):list with detail of all students Examples: `AttendnaceModel` object have state as float representing presance of student during class in current day date. Presence with it's float value is as follow: Present: 1.0, Not present: 0.0 and Late: 0.8 """ current_date = str(date.today()) for student in students: try: _vaildate_correct_date(current_date, student, students_attendance) except ValueError as err: print(err) codecooler_view.state_locker() continue user_choice = None attendance_state = None check_attendance_person = "Check attendance for {} {}".format( student.name, student.surname) while user_choice not in ["0", "1", "2", "3"]: codecooler_view.print_menu(check_attendance_person, ["Present", "Not present", "Late"], "Exit") user_choice = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] attendance_values = {'1': '1.0', '2': '0.0', '3': '0.8'} if user_choice in attendance_values: attendance_state = attendance_values[user_choice] else: codecooler_view.print_error_message('Wrong option!') if attendance_state: student_attendance = AttendanceModel(student.idx, current_date, float(attendance_state)) students_attendance.append(student_attendance)
def start_controller(name, surname, idx): """ Allow mentor perform assign tasks. Call functions to print menu for user and get input of choosen option. Then call proper function to perform given task. Args: name (string): name of user surname (string): surname of user idx (string): unique user's id """ students = Student.get_students_list() option = None while option != "0": codecooler_view.clear_window() codecooler_view.print_menu("Welcome {} {}".format(name, surname), [ "Students list", "Add assignment", "Grade assignment", "Check attendace", "Edit student", "Student ranking", "Change your password", "Enter talkbox" ], "Exit") option = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] codecooler_view.clear_window() if option == "1": get_students_list(present_student_grades=True) elif option == "2": assignment_controller.start_controller(students) elif option == "3": show_assignments() submit_assignment_controller.start_controller("mentor", idx) elif option == "4": attendance_controller.start_controller(students) elif option == "5": start_student_edit_menu() elif option == "6": rank = student_controller.get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() elif option == "7": codecooler_controller.change_password(idx) elif option == "8": talkbox.start_talkbox(name, surname)
def start_controller(name, surname, idx): """ Allow student user perform assign tasks. Call functions to print menu for user and get input of choosen user_choice Args: name (string): name of user surname (string): surname of user idx (string): unique user's id """ user_choice = None while user_choice != "0": codecooler_view.clear_window() codecooler_view.print_menu("Welcome {} {}".format(name, surname), [ "Submit assignment", "View grades", "Students ranking", "Change your password", "Enter talkbox", "Debt calculator" ], "Exit") user_choice = codecooler_view.get_inputs("Please choose a number", ["Number"])[0] codecooler_view.clear_window() if user_choice == "1": submit_assignment_controller.start_controller("student", idx) elif user_choice == "2": view_grades(idx) elif user_choice == "3": rank = get_ranking() codecooler_view.print_table(["Name", "Total points"], rank) codecooler_view.state_locker() codecooler_view.clear_window() elif user_choice == "4": codecooler_controller.change_password(idx) elif user_choice == "5": talkbox.start_talkbox(name, surname) elif user_choice == "6": show_debt(idx)
def view_grades(idx): """ Allow student to see assigments grades Args: idx (string): unique user's id """ students_grades = [] all_grades = Grade.get_grades_list() for grade in all_grades: if idx == grade.idx and grade.grade != 0: students_grades.append([grade.idx, grade.title, str(grade.grade)]) if len(students_grades) > 0: titles = ["Students idx", "Assignment", "Grade"] codecooler_view.print_table(titles, students_grades) codecooler_view.state_locker() else: codecooler_view.print_result("There is no grades!") sleep(1.5)