def ui_login(self): program_is_running = True print("====== Employee Login ======\n") username = input("Username: "******"-Password input is hidden-") password = getpass.getpass() # built-in Python module print("") # creates current_employee class using username and password # login() method checks if it's a valid employee and returns # true if employee found in data file and given password matches. # Next method checks for employee # admin status and sets it according to data file. current_employee = Employee(username, password) if self.__employee_services.login(current_employee, password): current_employee.manager = current_employee.is_manager() # Must pass current_employee class to main menu to # carry employee data to method and rest of program while program_is_running == True: self.main_menu(current_employee) else: print("Invalid username or password\n") self.ui_login()
def getEmployeesSatisfaction(): # Retrieve all the Employees from the Database employees_1 = Employee.getEmployeesSatisfaction(1, mysql) employees_2 = Employee.getEmployeesSatisfaction(2, mysql) employees_3 = Employee.getEmployeesSatisfaction(3, mysql) employees_4 = Employee.getEmployeesSatisfaction(4, mysql) return jsonify({ "A": employees_1, "B": employees_2, "C": employees_3, "D": employees_4, })
def getEmployeesPerformance(): # Retrieve all the Employees from the Database employees_A = Employee.getEmployeesPerformance('A', mysql) employees_B = Employee.getEmployeesPerformance('B', mysql) employees_C = Employee.getEmployeesPerformance('C', mysql) employees_D = Employee.getEmployeesPerformance('D', mysql) print(employees_D) return jsonify({ "A": employees_A, "B": employees_B, "C": employees_C, "D": employees_D })
def getEmployee(self): emp = Employee.getByCredential("sam", "hunt") print emp if emp != None: print emp.username print emp.password print emp.employee_id
def setting(self): # check for request # if post then validate and update if request.method == 'POST': if (request.form['type'] == 'credential'): username = request.form['username'] password = request.form['password'] if len(username) > 2 and len(password) > 2: if (username != current_user.username): exist = Employee.getByUsername(username) if isinstance(exist, Employee): self.view.setFlashMessage("fail", "Username already exists!") return self.view.render_employee_setting(current_user) current_user.username = username current_user.setPassword(password) current_user.update() self.view.setFlashMessage("success", "Successfully updated") else: self.view.setFlashMessage("fail", "Password must be greater than 2!") elif (request.form['type'] == 'visible'): current_user.visible = request.form['visible'] current_user.update() self.view.setFlashMessage("success", "Successfully updated") return self.view.render_employee_setting(current_user)
def get_employee_information_class(self, employee): with open("./data/employee.csv", newline='', encoding='utf-8-sig') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if row['ssn'] == employee: employee_info = Employee(row['occupation'], row['name'], row['ssn'], row['address'], row['home_phone'], row['cell_phone'], row['email'], row['licence'], row['status']) return employee_info
def get_data(self, instance_type): '''Returns a list of all vehicles in database''' csv_folder = self.get_csv_folder( instance_type) #get csv folder path to save instance instance_list = [] with open(f'{csv_folder}', newline='', encoding="utf-8") as csvfile: reader = csv.DictReader(csvfile) for row in reader: instance_attribute_list = [] for value in row: instance_attribute_list.append(row[f"{value}"]) if instance_type == "contract": contract = Contract(*instance_attribute_list) if contract.state == "DELETED": continue else: instance_list.append(contract) elif instance_type == "customer": customer = Customer(*instance_attribute_list) if customer.state == "DELETED": continue else: instance_list.append(customer) elif instance_type == "destination": destination = Destination(*instance_attribute_list) if destination.state == "DELETED": continue else: instance_list.append(destination) elif instance_type == "employee": employee = Employee(*instance_attribute_list) if employee.state == "DELETED": continue else: instance_list.append(employee) elif instance_type == "vehicle": vehicle = Vehicle(*instance_attribute_list) if vehicle.state == "DELETED": continue else: instance_list.append(vehicle) elif instance_type == "invoice": invoice = Invoice(*instance_attribute_list) if invoice.state == "DELETED": continue else: instance_list.append(invoice) elif instance_type == "rate": rate = Rate(*instance_attribute_list) if rate.state == "DELETED": continue else: instance_list.append(rate) instance_attribute_list.clear() return instance_list
def read(self): rows = Repository().read(self.filename) users = [ Employee(row['role'], row['name'], row['address'], row['postal'], row['ssn'], row['phone'], row['homephone'], row['email'], row['location_id'], row['id']) for row in rows ] return users
def update_employee(self, employee, new_employee): with open("./data/employee.csv", newline='', encoding='utf-8-sig') as csvfile: fieldnames = [ 'occupation', 'id', 'name', 'ssn', 'address', 'home_phone', 'cell_phone', 'email', 'licence', 'status' ] reader = csv.DictReader(csvfile) with open("./data/tempfile.csv", "w+", encoding='utf-8-sig') as tempfile: writer = csv.DictWriter(tempfile, fieldnames=fieldnames) writer.writeheader() for row in reader: if row['ssn'] == employee: updated_employee = Employee( row['occupation'], row['name'], row['ssn'], row['address'], row['home_phone'], row['cell_phone'], row['email'], row['licence'], row['status']) if new_employee[0] != "": updated_employee.occupation = new_employee[0] if new_employee[1] != "": updated_employee.address = new_employee[1] if new_employee[2] != "": updated_employee.home_phone = new_employee[2] if new_employee[3] != "": updated_employee.cell_phone = new_employee[3] if new_employee[4] != "": updated_employee.email = new_employee[4] if new_employee[5] != "": updated_employee.licence = new_employee[5] row = ({ 'occupation': updated_employee.occupation, 'name': updated_employee.name, 'ssn': updated_employee.ssn, 'address': updated_employee.address, 'home_phone': updated_employee.home_phone, 'cell_phone': updated_employee.cell_phone, 'email': updated_employee.email, 'licence': updated_employee.licence, 'status': updated_employee.emp_status }) writer.writerow(row) csvfile.close() tempfile.close() with open("./data/tempfile.csv", encoding='utf-8-sig') as tempfile: reader2 = csv.DictReader(tempfile) with open("./data/employee.csv", "w+", encoding='utf-8-sig') as csvfile: writer2 = csv.DictWriter(csvfile, fieldnames=fieldnames) writer2.writeheader() for row in reader2: writer2.writerow(row) tempfile.close() csvfile.close()
def init_meeting_scheduler(num_employees, num_meeting_rooms): for i in range(1, num_employees + 1): Scheduler.employees.append(Employee(i)) for i in range(1, num_meeting_rooms + 1): Scheduler.meetingRooms.append(MeetingRoom(i)) for i in range(1, 10000): Scheduler.meetingIds.add(i)
def get_employee(self): employee_lst = [] if employee_lst == []: with open("./data/employee.csv", newline='', encoding='utf-8-sig') as csvfile: reader = csv.DictReader(csvfile) for row in reader: new_employee = Employee(row['occupation'], row['name'], row['ssn'], row['address'], row['home_phone'], row['cell_phone'], row['email'], row['licence'], row['status']) employee_lst.append(new_employee) return employee_lst
def deleteEmployee(employee_id): result = Employee.deleteEmployee(employee_id, mysql) if result is True: return jsonify({ "result": True, "msg": "Successfully Deleted Employee!" }) return jsonify({"result": False, "msg": "Failed to Delete Employee!"})
def unassignEmployee(employee_id): result = Employee.unassignEmployee(employee_id, mysql) if result is True: return jsonify({ "result": True, "msg": "Successfully Assigned Employee!" }) return jsonify({"result": False, "msg": "Failed to Assign Employee!"})
def getEmployee(employee_id): employee = Employee.getEmployee(employee_id, mysql) if (employee == None): return jsonify({"employee": None, "msg": "Employee Not Found!"}) return jsonify({ "employee": employee, "msg": "Employee Found Successfully!" })
def get_pilots_by_model(self, pilots_model): models_and_pilots = [] if models_and_pilots == []: with open("./data/employee.csv", newline='', encoding='utf-8-sig') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if row['licence'] == pilots_model: the_models_and_pilots = Employee(row['occupation'], row['name'], row['ssn'], row['address'], row['home_phone'], row['cell_phone'], row['email'], row['licence'], row['status']) models_and_pilots.append(the_models_and_pilots) return models_and_pilots
def get_flight_attendants(self): flight_attendants = [] if flight_attendants == []: with open("./data/employee.csv", newline='', encoding='utf-8-sig') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if row['occupation'] == 'FA' or row['occupation'] == 'FSM': the_flight_attendants = Employee(row['occupation'], row['name'], row['ssn'], row['address'], row['home_phone'], row['cell_phone'], row['email'], row['licence'], row['status']) flight_attendants.append(the_flight_attendants) return flight_attendants
def __create_employee(self): '''Takes no input. Prints on the screen and asks for input to create an employee in the database. If all input is there and correctly typed it is saved to the employee.csv data file''' print(header_string("CREATE EMPLOYEE", 50)) occupation_str = self.__llapi.choose_occupation() if occupation_str: print(please_fill_info()) print("Occupation: ", occupation_str) name_str = get_string("Name") SO_str = input("Social Security Number: ") while not (self.__llapi.is_ssn_valid(SO_str)): print("Please insert a valid 10-digit social security number.") SO_str = input("Social Security Number: ") if self.__llapi.check_if_ssn_unique(SO_str): address_str = get_address() home_phone_str = self.__llapi.get_phone("Home") cell_phone_str = self.__llapi.get_phone("Cell") email_str = get_email() if occupation_str in ["C", "P"]: print("") print('List of airplane models') airplanes = self.__llapi.get_airplanes() print_airplane_models(airplanes) airplane_license_str = self.__llapi.get_airplane_model() else: airplane_license_str = "N/A" print("") if is_correct(): new_employee = Employee(occupation_str, name_str, SO_str, address_str, home_phone_str, cell_phone_str, email_str, airplane_license_str) if self.__llapi.add_employee(new_employee): print(header_string("SUCCESS!", 50)) press_enter() else: print( "Oh-oh something went wrong! Please fill in all information" ) try_again() self.__create_employee() else: self.__create_employee() else: print("The SSN already exists!") press_enter()
def updateEmployee(employee_id): employee = Employee( request.json['name'], request.json['age'], request.json['department'], request.json['phone'], request.json['email'], request.json['address'], request.json['distFromHome'], request.json['education'], request.json['gender'], request.json['jobSatisfaction'], request.json['maritalStatus'], request.json['children'], request.json['salary'], request.json['numCompaniesWorked'], request.json['overtime'], request.json['performanceRating'], request.json['standardHours'], request.json['trainingHours'], request.json['workLifeBalance'], request.json['yearsAtCompany'], request.json['yearsInCurrentRole'], request.json['yearsSinceLastPromo'], request.json['yearsWithCurrSupervisor'], request.json['absenteeism'], request.json['recruitmentDate']) result = Employee.updateEmployee(employee_id, employee, mysql) if result is True: return jsonify({ "result": True, "msg": "Successfully Updated Employee!" }) return jsonify({"result": False, "msg": "Failed to Update Employee!"})
def load_user(id): print("loading user") if (session.get('user_type')): if (session['user_type'] == 'Employee'): emp = Employee.getById(int(id)) if isinstance(emp, Employee) == False: return None elif (session['user_type'] == 'Admin'): emp = Administrator.getById(int(id)) if isinstance(emp, Administrator) == False: return None emp.is_authenticated = True print(emp) return emp return None
def login(self): if request.method == 'POST': print('This standard output', file=sys.stdout) username = request.form['username'] password = request.form['password'] print('got data', file=sys.stdout) print(username + " " + password) registered_user = Employee.getByCredential(username, password) if registered_user is None: flash('Username or Password is invalid', 'error') print('F**k', file=sys.stdout) return redirect('/') print('Got this shit', file=sys.stdout) session['user_type'] = "Employee" login_user(registered_user) print("logged IN") print(current_user) flash('Logged in successfully') return redirect('/calendar') return PageController().index()
def getEmployeesManager(): # Retrieve all the Employees from the Database return jsonify({"employees": Employee.getEmployeesManager(mysql)})
def search(query): # Retrieve all the Employees from the Database return jsonify({"employees": Employee.searchEmployees(query, mysql)})
def create(self): counter = 0 role = "" name = "" email = "" ssn = "" phone = "" homephone = "" address = "" postal = "" location_id = "" location_id_page = 1 role_page = 1 while True: location = self.logic.get_location_by_id(location_id) if location is None: location = "" self.printer.header("Create employee") print( f"Role:\t\t\t\t{role}\nName:\t\t\t\t{name}\nEmail:\t\t\t\t{email}\nSocial security number:\t\t{ssn}\nMobile phone:\t\t\t{phone}\nHome phone:\t\t\t{homephone}\nAddress:\t\t\t{address}\nPostal code:\t\t\t{postal}\nLocation:\t\t\t{location}\n" ) self.printer.new_line() self.printer.print_fail("Press q to go back") self.printer.new_line() self.notification() next_input = True data = None try: if counter == 0: data = self.input.get_option("role", [ "Admin", "Delivery", "Booking", "Mechanic", "Financial" ], current_page=role_page, warning_msg=self.warning_msg) if data[0]: role = data[1] else: next_input = False self.warning_msg = data[1] role_page = data[2] elif counter == 1: data = self.input.get_input("name", ["required"], warning_msg=self.warning_msg) if data[0]: name = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 2: data = self.input.get_input("email", ["required", "email"], warning_msg=self.warning_msg) if data[0]: email = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 3: data = self.input.get_input("social security number", ["required", "ssn"], warning_msg=self.warning_msg) if data[0]: ssn = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 4: data = self.input.get_input("mobile phone", ["required", "phone"], warning_msg=self.warning_msg) if data[0]: phone = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 5: data = self.input.get_input("home phone", ["required", "phone"], warning_msg=self.warning_msg) if data[0]: homephone = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 6: data = self.input.get_input("address", ["required"], warning_msg=self.warning_msg) if data[0]: address = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 7: data = self.input.get_input("postal code", ["required"], warning_msg=self.warning_msg) if data[0]: postal = data[1] else: next_input = False self.warning_msg = data[1] elif counter == 8: locations = self.logic.get_all_locations() available_locations = [[location.id, location] for location in locations] location_input = self.input.get_option( "location", available_locations, current_page=location_id_page, warning_msg=self.warning_msg) if location_input[0] == True: location_id = location_input[1] else: next_input = False self.warning_msg = location_input[1] location_id_page = location_input[2] elif counter > 8: new_employee = Employee(role, name, address, postal, ssn, phone, homephone, email, location_id) confirmation = input( "Are you sure you want to create this employee? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): " ).lower() if confirmation == 'y': self.logic.create_employee(new_employee) return True return False if next_input: counter += 1 except ValueError: break
def getAll(): employees = Employee.query().order(Employee.employeeName).fetch() return employees
def saveNew(request): employee = Employee() employee.employeeName = request.get('employeeName') employee.put() time.sleep(sleepTime)
def getAll(self): emp = Employee.getAll() print emp for e in emp: print e.username
def addEmployee(self): emp = Employee() emp.setCredentials("sam", "hunt") print Employee.add(emp)
def updateEmployee(self): emp = Employee.getByCredential("saam", "hunt") emp.username = "******" Employee.update(emp)
def create_employee(self, a_list): employee = Employee(self.data.new_employee_id, *a_list) return self.data.create_employee(employee)
def addEmployee(): if not request.json or not 'name' in request.json: return jsonify({"result": False, "msg": "Failed to Add Employee!"}) # Get Prediction for the Employee Turnover - Create Dataframe df = pd.DataFrame() print(request.json) df['Age'] = [request.json['age']] df['DistanceFromHome'] = [request.json['distFromHome']] df['Children'] = [request.json['children']] df['Num CompaniesWorked'] = [request.json['numCompaniesWorked']] df['Training '] = [request.json['trainingHours']] df['Years At Company'] = [request.json['yearsAtCompany']] df['Years In Current Role'] = [request.json['yearsInCurrentRole']] df['YearsSinceLastPromotion'] = [request.json['yearsSinceLastPromo']] df['YearsWithCurSupervisor'] = [request.json['yearsWithCurrSupervisor']] df['StandardHours'] = [request.json['standardHours']] if (request.json['department'] == '1'): df['Department_Cutting'] = [1] df['Department_Pressing'] = [0] df['Department_Sewing'] = [0] if (request.json['department'] == '2'): df['Department_Cutting'] = [0] df['Department_Pressing'] = [1] df['Department_Sewing'] = [0] if (request.json['department'] == '3'): df['Department_Cutting'] = [0] df['Department_Pressing'] = [0] df['Department_Sewing'] = [1] if (request.json['gender'] == '1'): df['Gender_Female'] = [1] df['Gender_Male'] = [0] if (request.json['gender'] == '2'): df['Gender_Female'] = [0] df['Gender_Male'] = [1] if (request.json['jobSatisfaction'] == '1'): df['Job_Satisfaction_1'] = [1] df['Job_Satisfaction_2'] = [0] df['Job_Satisfaction_3'] = [0] df['Job_Satisfaction_4'] = [0] if (request.json['jobSatisfaction'] == '2'): df['Job_Satisfaction_1'] = [0] df['Job_Satisfaction_2'] = [1] df['Job_Satisfaction_3'] = [0] df['Job_Satisfaction_4'] = [0] if (request.json['jobSatisfaction'] == '3'): df['Job_Satisfaction_1'] = [0] df['Job_Satisfaction_2'] = [0] df['Job_Satisfaction_3'] = [1] df['Job_Satisfaction_4'] = [0] if (request.json['jobSatisfaction'] == '4'): df['Job_Satisfaction_1'] = [0] df['Job_Satisfaction_2'] = [0] df['Job_Satisfaction_3'] = [0] df['Job_Satisfaction_4'] = [1] if (request.json['maritalStatus'] == '0'): df['Martial_Status_Single'] = [1] df['Martial_Status_Married'] = [0] df['Martial_Status_Divorced'] = [0] if (request.json['maritalStatus'] == '1'): df['Martial_Status_Single'] = [0] df['Martial_Status_Married'] = [1] df['Martial_Status_Divorced'] = [0] if (request.json['maritalStatus'] == '2'): df['Martial_Status_Single'] = [0] df['Martial_Status_Married'] = [0] df['Martial_Status_Divorced'] = [1] if (request.json['salary'] == '0'): df['Salary_Low'] = [1] df['Salary_Average'] = [0] df['Salary_High'] = [0] if (request.json['salary'] == '1'): df['Salary_Low'] = [0] df['Salary_Average'] = [1] df['Salary_High'] = [0] if (request.json['salary'] == '2'): df['Salary_Low'] = [0] df['Salary_Average'] = [0] df['Salary_High'] = [1] if (request.json['overtime'] == '0'): df['OverTime_No'] = [1] df['OverTime_Yes'] = [0] if (request.json['overtime'] == '1'): df['OverTime_No'] = [0] df['OverTime_Yes'] = [1] if (request.json['absenteeism'] == '0'): df['Absenteeism Rate_Low'] = [1] df['Absenteeism Rate_Medium'] = [0] df['Absenteeism Rate_High'] = [0] if (request.json['absenteeism'] == '1'): df['Absenteeism Rate_Low'] = [0] df['Absenteeism Rate_Medium'] = [1] df['Absenteeism Rate_High'] = [0] if (request.json['absenteeism'] == '2'): df['Absenteeism Rate_Low'] = [0] df['Absenteeism Rate_Medium'] = [0] df['Absenteeism Rate_High'] = [1] if (request.json['performanceRating'] == 'A'): df['PerformanceRating_A'] = [1] df['PerformanceRating_B'] = [0] df['PerformanceRating_C'] = [0] df['PerformanceRating_D'] = [0] if (request.json['performanceRating'] == 'B'): df['PerformanceRating_A'] = [0] df['PerformanceRating_B'] = [1] df['PerformanceRating_C'] = [0] df['PerformanceRating_D'] = [0] if (request.json['performanceRating'] == 'C'): df['PerformanceRating_A'] = [0] df['PerformanceRating_B'] = [0] df['PerformanceRating_C'] = [1] df['PerformanceRating_D'] = [0] if (request.json['performanceRating'] == 'D'): df['PerformanceRating_A'] = [0] df['PerformanceRating_B'] = [0] df['PerformanceRating_C'] = [0] df['PerformanceRating_D'] = [1] if (request.json['education'] == '1'): df['Education_1'] = [1] df['Education_2'] = [0] df['Education_3'] = [0] df['Education_4'] = [0] if (request.json['education'] == '2'): df['Education_1'] = [0] df['Education_2'] = [1] df['Education_3'] = [0] df['Education_4'] = [0] if (request.json['education'] == '3'): df['Education_1'] = [0] df['Education_2'] = [0] df['Education_3'] = [1] df['Education_4'] = [0] if (request.json['education'] == '4'): df['Education_1'] = [0] df['Education_2'] = [0] df['Education_3'] = [0] df['Education_4'] = [1] if (request.json['workLifeBalance'] == '1'): df['Work Life Balance_1'] = [1] df['Work Life Balance_2'] = [0] df['Work Life Balance_3'] = [0] df['Work Life Balance_4'] = [0] if (request.json['workLifeBalance'] == '2'): df['Work Life Balance_1'] = [0] df['Work Life Balance_2'] = [1] df['Work Life Balance_3'] = [0] df['Work Life Balance_4'] = [0] if (request.json['workLifeBalance'] == '3'): df['Work Life Balance_1'] = [0] df['Work Life Balance_2'] = [0] df['Work Life Balance_3'] = [1] df['Work Life Balance_4'] = [0] if (request.json['workLifeBalance'] == '4'): df['Work Life Balance_1'] = [0] df['Work Life Balance_2'] = [0] df['Work Life Balance_3'] = [0] df['Work Life Balance_4'] = [1] # Load the XGBoost Model param_dist = { 'objective': 'binary:logistic', 'n_estimators': 180, 'eta': 0.1, 'gamma': 0.05, 'max_depth': 3 } clf = xgb.XGBModel(**param_dist) clf.load_model(TURNOVER_MODEL) # Predict Turnover from the XGBoost Model prediction = clf.predict(df.to_numpy()) print(prediction) # Get Turnover Drivers # explainer = lime.lime_tabular(df.to_numpy(), feature_names=df.columns, class_names=[0,1], kernel_width=3) # Load the SVR Model svr = pickle.load(open(TIMETILLTURNOVER_MODEL, 'rb')) # Predict Time Till Turnover timetillturnover = svr.predict(df.to_numpy())[0] employee = Employee(request.json['name'], request.json['age'], request.json['department'], request.json['phone'], request.json['email'], request.json['address'], request.json['distFromHome'], request.json['education'], request.json['gender'], request.json['jobSatisfaction'], request.json['maritalStatus'], request.json['children'], request.json['salary'], request.json['numCompaniesWorked'], request.json['overtime'], request.json['performanceRating'], request.json['standardHours'], request.json['trainingHours'], request.json['workLifeBalance'], request.json['yearsAtCompany'], request.json['yearsInCurrentRole'], request.json['yearsSinceLastPromo'], request.json['yearsWithCurrSupervisor'], request.json['absenteeism'], request.json['recruitmentDate'], request.json['loggedInId'], turnover=prediction[0], timetillturnover=timetillturnover) result = Employee.addEmployee(employee, mysql) return jsonify({"result": True, "msg": "Successfully Added Employee!"})
def deleteEmployee(self): emp = Employee.getByCredential("sam", "hunt") print emp if emp != None: print emp.username Employee.delete(emp)
def __init__(self, dapi_in): self.__employee_repo = dapi_in self.__employee = Employee() self.__get = Get_DL()