Пример #1
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    title = "Human resources manager"
    options = [
        "Add item", "Remove item", "Update item", "Show the oldest person",
        "Show person closest to average age"
    ]
    exit_message = "Back to main menu"

    title_list = [['Name'], ['Date of birth']]

    data_file = "model/hr/persons.csv"
    table = data_manager.get_table_from_file(data_file)
    terminal_view.print_table(table, title_list)

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(title, options, exit_message)
        if choice == "1":
            record = []
            index = 0
            inputs = terminal_view.get_inputs(title_list, title)
            for i in inputs:
                record.insert(index, i)
                index += 1
            hr.add(table, record)
            data_manager.write_table_to_file(data_file, table)
            terminal_view.print_table(table, title_list)

        elif choice == "2":
            user_input = terminal_view.get_inputs(["Enter ID: "], "")
            hr.remove(table, user_input[0])
            terminal_view.print_table(table, title_list)
        elif choice == "3":
            record = []
            index = 0
            user_input = terminal_view.get_inputs(["Enter ID: "], "")
            inputs = terminal_view.get_inputs(title_list, title)
            for i in inputs:
                record.insert(index, i)
                index += 1
            hr.update(table, user_input[0], record)
            terminal_view.print_table(table, title_list)
        elif choice == "4":
            terminal_view.print_result(hr.get_oldest_person(table),
                                       "Oldest person")
        elif choice == "5":
            terminal_view.print_result(
                hr.get_persons_closest_to_average(table),
                "Person closest to average")
        else:
            terminal_view.print_error_message("You have chosen back to menu.")
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    common.clear()
    title = 'Human Resources menu'
    options = ["Add new record to table",
               "Remove a record with a given id from the table.",
               "Updates specified record in the table.",
               "Who is the oldest person?",
               "Who is the closest to the average age?"]
    exit_message = "Back to main menu"

    title_list = ["ID", "NAME", "BIRTH YEAR"]
    table = hr.data_manager.get_table_from_file('model/hr/persons.csv')
    # terminal_view.print_table(table, title_list)

    choice = None
    while choice != "0":
        terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice(title, options, exit_message)
        if choice == "1":
            record = terminal_view.get_inputs(title_list, 'Please add following informations :', table)
            updated_table = hr.add(table, record)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "2":
            id_ = terminal_view.get_inputs(['Id'], 'Please give ID to remove :', table)
            updated_table = hr.remove(table, id_)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "3":
            id_ = terminal_view.get_inputs(['Id'], 'Please give ID of changed line :', table)
            record = terminal_view.get_inputs(title_list, 'Please add following informations :', table)
            updated_table = hr.update(table, id_, record)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "4":
            result = hr.get_oldest_person(table)
            label = "The oldest person is: "
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice == "5":
            result = hr.get_persons_closest_to_average(table)
            label = "The closest to the average age is person: ?"
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice != 0:
            terminal_view.print_error_message("There is no such choice.")
Пример #3
0
def run():
    """
	Starts this module and displays its menu.
	* User can access default special features from here.
	* User can go back to main menu from here.

	Returns:
		None
	"""
    list_options = [
        'Human resources', 'Show all people', 'Add', 'Remove', 'Update',
        'Get oldest person', 'Get persons closest to average',
        'Exit to main menu'
    ]
    list_labels = [['Name', 'name'], ['Birth year', 'year']]
    data_file = "model/hr/persons.csv"
    crud_module = hr
    while True:
        table = data_manager.get_table_from_file(data_file)
        max_id = len(table)
        user_choice = terminal_view.get_choice(list_options)
        if user_choice in ['1', '2', '3', '4']:
            make_crud(crud_module, list_labels, list_options, max_id, table,
                      user_choice)
        elif user_choice == '5':
            terminal_view.print_result(hr.get_oldest_person(table),
                                       'Get oldest person:')
        elif user_choice == '6':
            terminal_view.print_result(
                hr.get_persons_closest_to_average(table),
                'Get persons closest to average:')
        elif user_choice == '0':
            break
        else:
            terminal_view.print_error_message("There is no such choice.")
Пример #4
0
def run():
    """
Uruchamia ten moduł i wyświetla jego menu.
     * Użytkownik ma tutaj dostęp do domyślnych funkcji specjalnych.
     * Użytkownik może wrócić do głównego menu.

    Zwroty:
        Żaden
    """

    options = [
        "Add new record to table", "Remove a record", "Update a record",
        "Get oldest person in file",
        "Get closest person to average year in file", "Print table"
    ]

    title_list = ["*id", "person", "year"]
    os.system('clear')
    file = "model/hr/persons.csv"
    choice = None
    while choice != "0":
        terminal_view.print_menu("What do you want to do: ", options,
                                 "Back to main menu")
        choice = terminal_view.get_choice(options)
        if choice == "1":
            common.all_add(title_list, file)
        elif choice == "2":
            common.all_remove(title_list, file)
        elif choice == "3":
            common.all_updates(title_list, file)
        elif choice == "4":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = file
            table = common.get_table_from_file(file_name)
            oldest_person = hr.get_oldest_person(table)
            os.system("clear")
            print("The oldest persons in the file: ", oldest_person)
            common.waiting()
            os.system("clear")
        elif choice == "5":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = file
            table = common.get_table_from_file(file_name)
            closest_to_average = hr.get_persons_closest_to_average(table)
            os.system("clear")
            print("Closest person to average year is:", closest_to_average)
            common.waiting()
            os.system("clear")
        elif choice == "6":
            common.all_print_table(title_list, file)

        else:
            if choice != "0":
                terminal_view.print_error_message("There is no such choice.")
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    list_options = [
        "1. Add new record to table",
        "2. Remove a record with a given id from the table",
        "3. Update specified record in the table", "4. Which person is oldest",
        "5. Which person is closest to average"
    ]

    program_works = True

    while program_works:
        table = hr.get_table()
        title_list = ["ID", "NAME", "DATE OF BIRTH"]
        terminal_view.print_table(table, title_list)
        answer = terminal_view.get_choice(list_options)

        if answer == "1":
            record = terminal_view.get_inputs(
                ["ID: ", "Name and surname: ", "Date of birth: "],
                "Please provide your personal information")
            common.add(table, record)
            hr.save_table(table)
        elif answer == "2":
            id_ = terminal_view.get_input("Please enter id number: ")
            common.remove(table, id_)
            hr.save_table(table)
        elif answer == "3":
            id_ = terminal_view.get_input("Please enter id number: ")
            record = terminal_view.get_inputs(
                ["ID: ", "Name and surname: ", "Year of birth: "],
                "Please provide new information")
            common.update(table, id_, record)
            hr.save_table(table)
        elif answer == "4":
            print(hr.get_oldest_person(table))
            # result = hr.get_oldest_person(table)
            # terminal_view.print_result(result, "Oldest person is: ")
        elif answer == "5":
            hr.get_persons_closest_to_average(table)
        elif answer == "0":
            program_works = False
        else:
            terminal_view.print_error_message(
                "There is no such choice. Choose from 1 to 5")
    return
Пример #6
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    table_headers = ['ID', 'Name', 'Birth Year']
    choice = None
    filename = 'model/hr/persons.csv'
    columns_headers = ['Name', 'Birth Year']
    ask_information = "Please provide your personal information"

    common.print_art(0)
    while choice != "0":
        choice = terminal_view.get_submenu_choice([
            'Add', 'Remove', 'Update', 'Get oldest person',
            'People closest to average age'
        ])
        table = common.get_table_from_file(filename)

        if choice[0] == "1":
            common.clear_terminal()
            common.adding(table, table_headers, filename, columns_headers,
                          ask_information)
        elif choice[0] == "2":
            common.clear_terminal()
            common.removing(table, table_headers, id, filename)
        elif choice == "3":
            common.clear_terminal()
            common.updating(table, table_headers, id, filename,
                            columns_headers, ask_information)
        elif choice == "4":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            hr_result = hr.get_oldest_person(table)
            terminal_view.print_result("\nThe oldest people are/ person is",
                                       hr_result)
        elif choice == "5":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            closest_to_average_people = hr.get_persons_closest_to_average(
                table)
            terminal_view.print_result("People closest to average age: ",
                                       closest_to_average_people)

        elif int(choice) >= 6:
            common.clear_terminal()
            terminal_view.print_error_message("There is no such choice.")
Пример #7
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """

    # your code
    menu_hr = [
        "Print hr list", "Add to hr list", "Remove form hr list",
        "Update record in hr list", "Oldest employe", "Average age"
    ]
    title = ["Id", "Name", "Year"]
    title_del = ["Input ID: "]
    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(menu_hr)

        if choice == "1":
            terminal_view.print_table(hr.get_data(), title)

        if choice == "2":
            hr.new_record(
                common.get_user_inp_record(
                    terminal_view.get_inputs(title[1:], "")),
                "model/hr/persons.csv")

        if choice == "3":
            hr.delete_record(
                hr.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                "model/hr/persons.csv")

        if choice == "4":
            hr.update_record(
                hr.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                terminal_view.get_inputs(title[1:], ""),
                "model/hr/persons.csv")

        if choice == "5":
            terminal_view.print_result(
                str(hr.get_oldest_person(hr.get_data())), "Oldest persons: ")
        if choice == "6":
            terminal_view.print_result(
                str(hr.get_persons_closest_to_average(hr.get_data())),
                "Closest to average age: ")
Пример #8
0
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    table = hr.get_hr_table_from_file()
    title_list = ["ID", "Name", "BirthYear"]
    options = [
        "View records", "Add record", "Remove record", "Update record",
        "Which person is the oldest?",
        "Which person is the closet to average age?"
    ]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice_inner_menu(options, "HR manager")
        if choice == "1":
            terminal_view.print_table(table, title_list)
        elif choice == "2":
            record = terminal_view.get_inputs(title_list[1::],
                                              "Please provide new item data")
            table = hr.add(table, record)
        elif choice == "3":
            id_to_delete_table = terminal_view.get_inputs(["ID"],
                                                          "Item to delete")
            id_to_delete = id_to_delete_table[0]
            table = hr.remove(table, id_to_delete)
        elif choice == "4":
            records = terminal_view.get_inputs(title_list, "Edit item")
            record_id = records[0]
            table = hr.update(table, record_id, records)
        elif choice == "5":
            oldest_person = hr.get_oldest_person(table)
            terminal_view.print_result(oldest_person, "The oldest person: ")
        elif choice == "6":
            closest_to_average = hr.get_persons_closest_to_average(table)
            terminal_view.print_result(closest_to_average,
                                       "The closest to average is: ")
        elif choice != "0":
            terminal_view.print_error_message("There is no such choice.")
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    options = ["Add", "Remove", "Update", "Oldest person", "Persons closest to average"]
    common_options = ["Name: ", "Year: "]
    file = "model/hr/persons.csv"
    title_list = ["Id", "Name", "Year"]
    choice = None
    dont_clear = False
    while choice != '0':
        if not dont_clear:
            os.system("clear")
            table = data_manager.get_table_from_file(file)
            terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice_submenu(options)
        dont_clear = False
        if choice == '1':
            common.add(file, common_options)
        elif choice == '2':
            common.remove(file)
        elif choice == '3':
            common.update(file, common_options)
        elif choice == '4':
            terminal_view.print_result(hr.get_oldest_person(table), "Oldest persons:\n")
            dont_clear = True
        elif choice == '5':
            msg = "Persons with age closest to average:\n"
            terminal_view.print_result(hr.get_persons_closest_to_average(table), msg)
            dont_clear = True
        else:
            terminal_view.print_error_message("There is no such choice.")
Пример #10
0
 def test_get_oldest_person(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected = ["Evelin Smile"]
     result = hr.get_oldest_person(table)
     compare_lists(self, expected, result)
 def test_get_oldest_person(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected = ["Barbara Streisand", "Joey Tribbiani", "Evelin Smile"]
     result = hr.get_oldest_person(table)
     compare_lists(self, expected, result)
def run():
    """
    Starts this module and displays its menu.
     * User can access default special features from here.
     * User can go back to main menu from here.

    Returns:
        None
    """
    list_of_humans = hr.get_data_to_list()

    # your code
    options = [
        "Add new record", "Remove a record", "Update record",
        "Search oldest persons", "Search persons closest to average",
        "Print table"
    ]

    title_list = ["ID", "NAME", "YEAR"]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(options, "Back to main menu")
        if choice == "1":

            new_record = terminal_view.get_inputs(["Name: ", "Birthyear: "],
                                                  "Please enter value: ")

            new_record.insert(0, hr.get_random_id(list_of_humans))
            list_of_humans = hr.add(list_of_humans, new_record)
        elif choice == "2":
            id_of_record_to_remove = ask_untill_correct(list_of_humans)
            list_of_humans = hr.remove(
                list_of_humans,
                common.check_id_by_number(list_of_humans,
                                          int(id_of_record_to_remove)))
        elif choice == "3":
            id_of_record_to_update = ask_untill_correct(list_of_humans)
            updated_record = terminal_view.get_inputs(
                ["Name: ", "Birthyear: "], "Please enter value: ")
            list_of_humans = hr.update(
                list_of_humans,
                common.check_id_by_number(list_of_humans,
                                          int(id_of_record_to_update)),
                updated_record)
        elif choice == "4":
            oldest_persons = hr.get_oldest_person(list_of_humans)
            terminal_view.print_result(oldest_persons,
                                       "List of oldest persons")
        elif choice == "5":
            closest_persons_to_avg = hr.get_persons_closest_to_average(
                list_of_humans)
            terminal_view.print_result(
                closest_persons_to_avg,
                "List of persons closest to average year")
        elif choice == "6":
            terminal_view.print_table(list_of_humans, title_list)
        elif choice == "0":
            hr.export_list_to_file(list_of_humans)
        else:
            terminal_view.print_error_message("There is no such choice.")