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()
示例#2
0
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 add_person(a_list, obj_to_create, title):
    """
    Add object representation of person from list.

    Args:
        a_list (list of :obj:): list of object representation of person
        obj_to_create (class): class of person that will be created
        title (string): title of performed task

    Examples:
        obj_to_create can be Mentor or Student class depending on place of function call
    """

    person = get_user_details()
    idx = tools.gen_idx(obj_to_create.__name__.lower())
    a_list.append(obj_to_create(idx, *person))
    codecooler_view.print_result('Succesfully added new person.')
    sleep(1.5)
示例#4
0
def change_password(idx):
    """
    Allow user to change his password

    Args:
        idx (string): unique id of user
    """

    user = find_user_by_id(idx)
    passes = codecooler_view.get_inputs("Please provide data",
                                        ["Old password", "New password"])

    if passes[0] == user.password:
        user.password = passes[1]
        codecooler_view.print_result("Password changed succesfully!\n")

    else:
        codecooler_view.print_error_message('Wrong old password provided.')

    sleep(1.5)
    codecooler_view.clear_window()
示例#5
0
def login():
    """
    Contain logic of user login to program. Create list of all users and check if user login and password are correct.
    """

    found = False
    data_loader.load_data_from_files()
    mergedlist = Student.student_list + Mentor.mentor_list + OfficeManager.office_managers_list + Manager.manager_list

    while not found:
        passes = codecooler_view.get_inputs(
            "Please provide your login and password", ["Login", "Password"])
        idx, password = passes[0], passes[1]

        for ccooler in mergedlist:
            if idx == ccooler.idx and password == ccooler.password:
                codecooler_view.clear_window()
                start_controller(ccooler)
                found = True
                break

        if not found:
            codecooler_view.print_result("Wrong login or password!\n")
示例#6
0
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)
def start_controller(students):
    """
    Contain main logic for AssignmentController.
    Ask user about assigemnt details and add it to assigments list

    Args:
        students (list of :obj: `Student`): list of all students

    Raises:
        ValueError: if deadline date is wrong
    """

    "is_empty = True"
    questions = ["Title", "Description"]
    deadline_questions = ["Deadline day", "Deadline month", "Deadline year"]

    assgn_details = codecooler_view.get_inputs("Add assignment", questions)
    deadline_details = codecooler_view.get_inputs("Provide deadline",
                                                  deadline_questions)
    is_empty = is_empty_input(assgn_details)
    check_adding_assignment_possibility = is_possible_to_add_assignment(
        assgn_details[0])

    if not is_empty and check_adding_assignment_possibility:
        try:
            deadline = set_deadline(*deadline_details)
            Assignment.assignments.append(Assignment(*assgn_details, deadline))
            codecooler_view.print_result('Succesfuly added assignment.')
            _create_student_assigments(students, assgn_details[0])
        except ValueError:
            codecooler_view.print_result("Provided deadline is impossible!")

    else:
        codecooler_view.print_error_message(
            'Please provide title, description. Or Try another title.')

    sleep(2)