def list_employees(): view.clear_console() employee = hr.read() view.print_table(employee, hr.HEADERS, title="All employees") view.wait_for_reaction() view.clear_console() display_menu()
def test_fetch_record_by_id(self): table = data_manager.get_table_from_file(self.data_file) record_id_to_found = "jH34Ju#&" expected_record = [ "jH34Ju#&", "Barbara Streisand", "*****@*****.**", "1955-11-21", "4125" ] actual_record = hr.read(table, record_id_to_found) self.assertListEqual(actual_record, expected_record)
def get_oldest_and_youngest(): view.clear_console() employees = hr.read() employees.sort(key=lambda employee: employee[2]) oldest_employee = employees[0][1] youngest_employee = employees[len(employees) - 1][1] oldest_and_youngest = oldest_employee, youngest_employee oldest_and_youngest_label = "Oldest and youngest employees is : " view.print_general_results(oldest_and_youngest, oldest_and_youngest_label) view.wait_for_reaction() return oldest_employee, youngest_employee
def count_employees_per_department(): view.clear_console() employees = hr.read() sep = " " employees.sort(key=lambda emplo: emplo[3]) dict_of_emplo_in_departament = {} for employee in employees: name_of_departament = employee[3] if name_of_departament not in dict_of_emplo_in_departament: dict_of_emplo_in_departament[name_of_departament] = 1 elif name_of_departament in dict_of_emplo_in_departament: dict_of_emplo_in_departament[name_of_departament] += 1 dict_of_emplo_in_departament_label = "Employee numbers by department" view.print_general_results(dict_of_emplo_in_departament, dict_of_emplo_in_departament_label) view.wait_for_reaction()
def delete_employee(): view.clear_console() view.print_message("Delete employee: ") employees = hr.read() view.print_table(employees, hr.HEADERS, title="All Employees") delete_label = "Provide employee id to remove: " employee_index = view.get_input_number(delete_label, max_value=len(employees)) employees.pop(int(employee_index) - 1) hr.create(employees) view.print_message("Employee was removed correctly.") view.wait_for_reaction()
def count_employees_with_clearance(): view.clear_console() employees = hr.read() sep = " " employees.sort(key=lambda employee: employee[4]) list_of_employees_with_lowest_clearance = [] for worker in employees: int_worker_clearance = int(worker[4]) if int_worker_clearance > 0: worker_str = sep.join(worker) list_of_employees_with_lowest_clearance.append(worker_str) list_of_employees_with_lowest_clearance.sort(key=lambda emplo: emplo[4]) employees_with_lowest_clearance_label = "number of employees with clearances is :" view.print_general_results(len(list_of_employees_with_lowest_clearance), employees_with_lowest_clearance_label) view.wait_for_reaction()
def get_average_age(): view.clear_console() current_year = int(datetime.now().year) all_together = 0 number_of_employee = 0 employees = hr.read() for employee in employees: date_list = employee[2].split("-") year = int(date_list[0]) all_together += year number_of_employee += 1 average = current_year - all_together // number_of_employee average_label = "the average age of the employees is" view.print_general_results(average, average_label) view.wait_for_reaction() return average
def update_employee(): view.clear_console() view.print_message("update employee:\n") employees = hr.read() view.print_table(employees, hr.HEADERS, title="All Employees") update_label = "Provide employees id to update: " employee_index = view.get_input_number(update_label, max_value=len(employees)) - 1 employee_to_update = employees.pop(int(employee_index)) updated_employee = get_updated_employee_data(employee_to_update, hr.HEADERS) employees.insert(int(employee_index), updated_employee) hr.create(employees) view.print_message("Customer was updated correctly.") view.wait_for_reaction()