def fixEmployeeId(self): if len(self.__employees) > 0: max = 0 for employee in self.__employees: if max <= employee.getId(): max = employee.getId() + 1 Employee.setEmployeeId(max)
def test_aggregate(self): employees = [] employees.append(Employee(1, "Arun", "swe", 1000)) employees.append(Employee(2, "Chung", "swe", 100000)) empAgg = Aggregator().aggregate(employees) self.assertEqual(empAgg.aggregateType, "AVG_SALARY") self.assertEqual(empAgg.aggregateValue, 50500)
def deleteEmployee(request): q = Employee.gql("WHERE id = :1", int(request.POST['id'])) for result in q: result.delete() return redirect('/admin/employee')
def addRecord(request): bhour = int(request.POST['bhour'].split(':')[0]) ehour = int(request.POST['ehour'].split(':')[0]) bminutes = int(request.POST['bhour'].split(':')[1]) eminutes = int(request.POST['ehour'].split(':')[1]) subtotal = float((ehour-bhour) + float(eminutes-bminutes)/60) time_format = "%Y-%m-%d" hourly_pay = Employee.gql("WHERE mail = :1", users.get_current_user()).get().hourly_pay working = WorkingHours() result = WorkingHours.gql('ORDER BY id DESC').get(); working.id = result.id + 1 if result else 1 working.worker = users.get_current_user() working.working_date = datetime.date.fromtimestamp(time.mktime(time.strptime(request.POST['date'], time_format))) working.working_bhour = request.POST['bhour'] working.working_ehour = request.POST['ehour'] working.working_area = request.POST['area'] working.working_content = request.POST['content'] working.subtotal = subtotal working.pay = int(subtotal * hourly_pay) working.put() return redirect('/employee/')
def showMonthRecord(request, em_mail, year, month): # user = users.get_current_user() user = users.User(em_mail) time_format = "%Y-%m-%d" bday = year + "-" + month + "-" + '1' endday = year +"-" + unicode(int(month) + 1) + "-" + '1' sdate = datetime.date.fromtimestamp(time.mktime(time.strptime(bday, time_format))) sdate2 = datetime.date.fromtimestamp(time.mktime(time.strptime(endday, time_format))) em_data = Employee.gql("WHERE mail = :1", user) working_hours = WorkingHours.gql("WHERE worker = :1 AND working_date >= :2 AND working_date < :3", user, sdate, sdate2) total_hour = 0 total_pay = 0 for work in working_hours: total_hour += work.subtotal total_pay += work.pay if user: template_values = {'userName': users.get_current_user().nickname().split('@')[0], 'logout': users.create_logout_url('/'), 'em_data': em_data, 'working_hours': working_hours, 'total_hour': total_hour, 'total_pay': total_pay, 'select_year': year, 'select_month': month, 'em_mail': user.email() } return render_to_response('admin/employee/browse_employee.html', template_values)
def btnAddActionPerformed(self): customerId = self.__txtCustomerId.get() itemId = self.__txtItemId.get() number = self.__txtNumber.get() employeeId = self.__txtEmployeeId.get() if len(customerId) > 0 and len(itemId) > 0 and len(number) > 0 and len( employeeId) > 0: try: customer = Customer(customerId, "", "", "") item = Item(itemId, "", "", "") employee = Employee(employeeId, "", "", "", "") if self.__customers.__contains__(customer) \ and self.__items.__contains__(item) and\ self.__employees.__contains__(employee): cIndex = self.__customers.index(customer) iIndex = self.__items.index(item) eIndex = self.__employees.index(employee) transaction = Transaction("", self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) transaction.fixId() self.__parent.addTransactionCallBack(transaction) messagebox.showinfo("Success", "A new transaction has been added") self.showDefaultText() else: messagebox.showerror("Error", "This information does not exist!") except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def printWorkingHours(request, em_mail, year, month): # user = users.get_current_user() user = users.User(em_mail) em_data = Employee.gql("WHERE mail = :1", user).fetch(1) time_format = "%Y-%m-%d" try: bday = year + '-' + month + '-1' endday = year + '-' + unicode(int(month) + 1) + "-1" sdate = datetime.date.fromtimestamp(time.mktime(time.strptime(bday, time_format))) sdate2 = datetime.date.fromtimestamp(time.mktime(time.strptime(endday, time_format))) working_hours = WorkingHours.gql("WHERE worker = :1 AND working_date >= :2 AND working_date < :3", user, sdate, sdate2) template_values = {'working_hours': working_hours, 'em_data':em_data} return render_to_response('table.html', template_values) except: return HttpResponse("請先選擇月份,初始畫面是所有的工讀紀錄。") #application = webapp.WSGIApplication([('/admin/employee', MainPage), # ('/employee/add_record', Add_Record), # ('/employee/delete_record', Delete_Record), # ('/employee/update_record', Update_Record), # ('/employee/add_employee', Add_Employee), # ('/employee/delete_employee/(.*)', Delete_Employee), # ('/employee/update_employee/(.*)', Update_Employee), # ('/employee/edit_employee/(.*)', Edit_Employee), # ('/employee/show_workinghours/(.*)', Show_WorkingHours), # ('/employee/', Personal_Record), # ('/employee/print_workinghours/',Print_WorkingHours), # ('/employee/show_monthrecord/', Show_Month_Record)], debug=True) #
def personalRecord(request): user = users.get_current_user() em_data = Employee.gql("WHERE mail = :1", user) if not em_data.count(1): return HttpResponse('系統找不到您的的資料。') working_hours = WorkingHours.gql("WHERE worker = :1", user) total_pay = 0 total_hour = 0 for work in working_hours: total_pay += work.pay total_hour += work.subtotal if user: template_values = { 'userName': users.get_current_user().nickname().split('@')[0], 'logout': users.create_logout_url('/'), 'em_data': em_data, 'working_hours': working_hours, 'total_pay': total_pay, 'total_hour': total_hour, 'em_mail': user.email() } return render_to_response('employee/employee.html', template_values)
def editEmployee(request): q = Employee.gql("WHERE id = :1", int(request.POST['id'])) results = q.fetch(10) template_values = {} if users.get_current_user(): template_values['userName'] = users.get_current_user().nickname().split('@')[0] template_values['logout'] = users.create_logout_url('/') template_values['employee'] = results return render_to_response('admin/employee/update_employee.html', template_values)
def addEmployee(request): result = Employee.gql('ORDER BY id DESC').get() employee = Employee() employee.id = (result.id + 1) if result else 0 employee.name = request.POST['name'] employee.mail = users.User(request.POST['mail']) employee.hourly_pay = int(request.POST['hourly_pay']) employee.put() #self.response.out.write(self.request.get('mail')) return redirect('/admin/employee')
def readEmployeeTable(self): self.__employees = [] sql = "SELECT * FROM employees" self.__cursor.execute(sql) records = self.__cursor.fetchall() for row in records: employee = Employee(str(row[0]), row[1], row[2], row[3], str(row[4])) self.__employees.append(employee) return self.__employees
def searchEmployeeByPhoneNumber(self, phoneNumber): self.__employees = [] sql = "SELECT * FROM employees WHERE phoneNumber LIKE %s" val = ("%" + phoneNumber + "%", ) self.__cursor.execute(sql, val) records = self.__cursor.fetchall() for row in records: employee = Employee(str(row[0]), row[1], row[2], row[3], str(row[4])) self.__employees.append(employee) return self.__employees
def searchEmployeeBySalary(self, salary): self.__employees = [] sql = "SELECT * FROM employees WHERE salary LIKE %s" val = ("%" + salary + "%", ) self.__cursor.execute(sql, val) records = self.__cursor.fetchall() for row in records: employee = Employee(str(row[0]), row[1], row[2], row[3], str(row[4])) self.__employees.append(employee) return self.__employees
def searchEmployeeById(self, employeeId): self.__employees = [] sql = "SELECT * FROM employees WHERE id = %s" val = (employeeId, ) self.__cursor.execute(sql, val) records = self.__cursor.fetchall() for row in records: employee = Employee(str(row[0]), row[1], row[2], row[3], str(row[4])) self.__employees.append(employee) return self.__employees
def updateEmployee(request): q = Employee.gql("WHERE id = :1", int(request.POST['id'])) results = q.fetch(10) for data in results: data.name = request.POST['new_name'] # data.mail = users.User(self.request.get('new_mail')+'@gmail.com') data.hourly_pay = int(request.POST['new_pay']) db.put(results) return redirect('/admin/employee')
def employees(): search = SearchForm() login = LoginForm() employees = Employee.query.all() form = AddEmployeeForm() if request.method == 'GET': return render_template('AddEmployee.html', title='Add Employee', form=form, login=login, searchform=search, employees=employees) elif request.method == 'POST': if form.validate(): Employee.addEmployee(form) return redirect(url_for('employees')) return render_template('AddEmployee.html', title='Add Employee', form=form, login=login, searchform=search, employees=employees)
def btnEditActionPerformed(self): fullName = self.__txtFullName.get() address = self.__txtAddress.get() phoneNumber = self.__txtPhoneNumber.get() salary = self.__txtSalary.get() if len(fullName) > 0 and len(address) > 0 and len(phoneNumber) > 0: try: employee = Employee(str(self.__employee.getId()), fullName, address, phoneNumber, salary) self.__parent.editEmployeeCallBack(employee) self.__editEmployeeWindow.destroy() messagebox.showinfo("Success", "Employee information has been edited") except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
def extract(self, dbFactory): cnx = dbFactory.getConnection() cursor = cnx.cursor() query = ("SELECT id, name, dept, salary from employee") cursor.execute(query) employees = [] for (id, name, dept, salary) in cursor: emp = Employee(id, name, dept, salary) employees.append(emp) cursor.close() return employees
def add_employee_process(): employee = Employee( request.form["first_name"], request.form["surname"], request.form["email"], request.form["phone_number"], request.form["hire_date"], request.form["job_id"], request.form["salary"], request.form["commission"], request.form["manager_id"], request.form["department_no"], ) result = insert_new_employee(employee) return search_results(request.form["email"])
def edit_employee_process(): employee = Employee( request.form["first_name"], request.form["surname"], request.form["email"], request.form["phone_number"], request.form["hire_date"], request.form["job_id"], request.form["salary"], request.form["commission"], request.form["manager_id"], request.form["department_no"], ) update_employee(employee, request.args.get("id")) return search_results(request.args.get("id"))
def readTransactionTable(self): self.__transactions = [] sql = "SELECT * FROM transactions" self.__cursor.execute(sql) records = self.__cursor.fetchall() for row in records: id = str(row[0]) customerId = str(row[1]) itemId = str(row[3]) number = str(row[5]) employeeId = str(row[7]) cIndex = self.__customers.index(Customer(customerId, "", "", "")) iIndex = self.__items.index(Item(itemId, "", "", "")) eIndex = self.__employees.\ index(Employee(employeeId, "", "", "", "")) transaction = Transaction(id, self.__customers[cIndex], self.__items[iIndex], number, self.__employees[eIndex]) self.__transactions.append(transaction) return self.__transactions
def printWorkingHours(request, year, month): user = users.get_current_user() #user = users.User(mail) em_data = Employee.gql("WHERE mail = :1", user).fetch(1) time_format = "%Y-%m-%d" try: bday = year + '-' + month + '-1' endday = year + '-' + unicode(int(month) + 1) + "-1" sdate = datetime.date.fromtimestamp(time.mktime(time.strptime(bday, time_format))) sdate2 = datetime.date.fromtimestamp(time.mktime(time.strptime(endday, time_format))) working_hours = WorkingHours.gql("WHERE worker = :1 AND working_date >= :2 AND working_date < :3", user, sdate, sdate2) template_values = {'working_hours': working_hours, 'em_data':em_data} return render_to_response('table.html', template_values) except: return HttpResponse("請先選擇月份,初始畫面是所有的工讀紀錄。")
def employeeList(request): employee = Employee.all() year = datetime.date.today().year month = datetime.date.today().month nextMonth = (month + 1) if month < 12 else 1 time_format = "%Y-%m-%d" bday = str(year) + "-" + str(month) + "-1" endday = str(year) + "-" + str(nextMonth) + "-1" sdate = datetime.date.fromtimestamp(time.mktime(time.strptime(bday, time_format))) endate = datetime.datetime.fromtimestamp(time.mktime(time.strptime(endday, time_format))) working_hours = WorkingHours.gql("WHERE working_date >= :1 AND working_date < :2" \ , sdate, endate) seq1 = ()#key值陣列 seq2 = []#時數 for em in employee: # print em.mail seq1 += em.id,#設key id seq2.append(0)#放初值 d = dict(zip(seq1,seq2)) for work in working_hours: for i in employee: if work.worker == i.mail: d[int(i.id)] += work.subtotal # d.values is work subtotal personal_data = zip(d.values(),employee) template_values = {} if users.get_current_user(): template_values['userName'] = users.get_current_user().nickname().split('@')[0] template_values['logout'] = users.create_logout_url('/') template_values['personal_data'] = personal_data return render_to_response('admin/employee/admin_employee.html', template_values)
def showWorkingHours(request, worker_mail): pattern = '([\w.]+)@([\w.]+)' regu = re.compile(pattern, re.IGNORECASE) if not regu.search(worker_mail): return redirect('/admin/employee') now = datetime.datetime.now() nowy=[] for i in range(5): nowy.append(now.year-i) mon=[1,2,3,4,5,6,7,8,9,10,11,12] # user = users.User(worker_mail+'@gmail.com') user = users.User(worker_mail) em_query = Employee.gql("WHERE mail = :1", user) em_data = em_query.fetch(1) working_hours = WorkingHours.gql("WHERE worker = :1", user) total_hour = 0 total_pay = 0 for work in working_hours: total_hour += work.subtotal total_pay += work.pay template_values = {} if users.get_current_user(): template_values['userName'] = users.get_current_user().nickname().split('@')[0] template_values['logout'] = users.create_logout_url('/') template_values['em_data'] = em_data template_values['working_hours'] = working_hours template_values['total_hour'] = total_hour template_values['total_pay'] = total_pay template_values['nowy'] = nowy template_values['mon'] = mon try: em_mail = str(em_data.__getitem__(0).mail) template_values['em_mail'] = worker_mail#em_mail return render_to_response('admin/employee/browse_employee.html', template_values) except: return HttpResponse('找不到此人的資料。')
def btnAddActionPerformed(self): fullName = self.__txtFullName.get() address = self.__txtAddress.get() phoneNumber = self.__txtPhoneNumber.get() salary = self.__txtSalary.get() if len(fullName) > 0 and len(address) > 0 and len(phoneNumber) > 0: try: employee = Person(fullName, address, phoneNumber) if self.__employees.__contains__(employee): messagebox.showerror( "Error", "Employee information already exists!") else: employee = Employee("", fullName, address, phoneNumber, salary) employee.fixId() self.__parent.addEmployeeCallBack(employee) messagebox.showinfo("Success", "A new customer has been added") self.showDefaultText() except Exception: messagebox.showerror("Error", "Invalid information format!") else: messagebox.showerror("Error", "Input fields cannot be left blank!")
from model.Employee import Employee print(Employee.count()) e1 = Employee("Anil", 200) e1.print() print(Employee.count()) e2 = Employee("Osho", 540) e2.print() print(Employee.count()) e3 = Employee.create_employee("Steve", 7800) e3.print() print(Employee.count())
from pyspark.sql import SparkSession from pyspark.sql.functions import broadcast from model.Role import Role from model.Employee import Employee if __name__ == '__main__': # Create the SparkSession spark = SparkSession \ .builder \ .appName("DSL examples") \ .master('local[*]') \ .getOrCreate() spark.sparkContext.setLogLevel('ERROR') emp_df = spark.createDataFrame([ Employee(1, "Sidhartha", "Ray"), Employee(2, "Pratik", "Solanki"), Employee(3, "Ashok", "Pradhan"), Employee(4, "Rohit", "Bhangur"), Employee(5, "Kranti", "Meshram"), Employee(7, "Ravi", "Kiran") ]) emp_df.createOrReplaceTempView("emp") role_df = spark.createDataFrame([ Role(1, "Architect"), Role(2, "Programmer"), Role(3, "Analyst"), Role(4, "Programmer"), Role(5, "Architect"), Role(6, "CEO")
try: print('Start sending messages ...') time_start = int(round(time.time() * 1000)) # produce(topic, [value], [key], [partition], [on_delivery], [timestamp], [headers]) ''' / ** 示範: 如何將資料包成物件並轉換成JSON字串送入Kafka ** // 由於一般應用場景的資料都是包括了很多的資料欄位及不同的資料型別。通常都會使用一個類別物件來做為資料傳遞的容器。 // 因此如何把一個Data Transfer Object (DTO)序列化送進Kafka是相當關鍵的步驟 ''' for i in range(msgCount): fakeNumber = str(i) # 讓我們產生假的Employee資料 employee = Employee(id_='emp_id_' + fakeNumber, first_name='fn_' + fakeNumber, last_name='ln_' + fakeNumber, dept_id='dept_id_' + str(i % 10), hire_date=epoch_now_mills(), wage=float(i), sex=True) # 轉換成JSON字串 employeeJson = json.dumps(employee.__dict__) # 送出訊息 producer.produce(topicName, key=str(i), value=employeeJson, callback=delivery_callback) producer.poll(0) # 呼叫poll來讓client程式去檢查內部的Buffer, 並觸發callback if i % 10000 == 0: print('Send {} messages'.format(i)) time_spend = int(round(time.time() * 1000)) - time_start print('Send : ' + str(msgCount) + ' messages to Kafka')