python: excel假期时间提取统计

# encoding: utf-8
# 版权所有 2023 涂聚文有限公司
# 许可信息查看:
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 311
# Datetime  : 2023/9/3 7:04
# User      : geovindu
# Product   : PyCharm
# Project   : LukfookLeaveCalculation
# File      : EmpLoyeeHolidaysGet.py
# explain   : 学习import sys
import os
import Common.Utils
import Model.Holidayclass EmpLoyeeHolidaysGet(object):"""抽取需要的数据"""def getYear(self,strsource):""":param strsource::return:"""refloat = 0if (strsource != None):if ("年" in strsource):refloat=Common.Utils.Utils.getYear(strsource)return refloatdef getMonth(self, strsource):""":param strsource::return:"""refloat = 0if (strsource != None):if ("月" in strsource):refloat = Common.Utils.Utils.getMonth(strsource)return refloatdef getDay(self, strsource):""":param strsource::return:"""refloat = 0if (strsource != None):if ("日" in strsource):refloat = Common.Utils.Utils.getDay(strsource)return refloatdef getHolidays(self,strsource):"""獲得假期限列表:param strsource::return:"""hday=[]if (strsource != None):if("星期" not in strsource):if("nan" not in strsource):spstr = strsource.split(' ')  # 有两个,有换行符,两个假期,一定要这换行符  NaNif (len(spstr) > 1):for i in range(len(spstr)):sk = spstr[i]#print("for sk", sk)hd = Model.Holiday.Holiday()hd=EmpLoyeeHolidaysGet.checkHoliday(self,sk)hday.append(hd)elif (len(spstr) == 1):sk = spstr[0]#print("sk",sk)hd = Model.Holiday.Holiday()hd = EmpLoyeeHolidaysGet.checkHoliday(self,sk)hday.append(hd)else:hday = []else:hday = []return hdaydef checkHoliday(self,strsource):"""检测是什么假期:param strsource::return:"""hd=Model.Holiday.Holiday()#print("chek")if ("例休" in strsource):#print("cehck例休")hd.HolidayId=1hd.HolidayName="例休"hd.WorkTime=Common.Utils.Utils.getRegularHoliday(strsource)if ("特假" in strsource):hd.HolidayId=2hd.HolidayName="特假"hd.workTime=Common.Utils.Utils.getSpecialLeave(strsource)if ("補休" in strsource):hd.HolidayId=3hd.HolidayName="補休"hd.workTime = Common.Utils.Utils.getDeferredHoliday(strsource)if ("加班" in strsource):hd.HolidayId=4hd.HolidayName="加班"hd.workTime = Common.Utils.Utils.getOvertime(strsource)if ("事假" in strsource):hd.HolidayId=5hd.HolidayName="事假"hd.workTime = Common.Utils.Utils.getPersonalLeave(strsource)if ("年假" in strsource):hd.HolidayId = 6hd.HolidayName = "年假"hd.workTime = Common.Utils.Utils.getAnnualLeave(strsource)if ("病假" in strsource):hd.HolidayId = 7hd.HolidayName = "病假"hd.workTime = Common.Utils.Utils.getSickLeave(strsource)if ("育兒假" in strsource):hd.HolidayId = 8hd.HolidayName = "育兒假"hd.workTime = Common.Utils.Utils.getChildcareLeave(strsource)if ("遲到" in strsource):hd.HolidayId = 9hd.HolidayName = "遲到"hd.workTime = Common.Utils.Utils.getLateTime(strsource)return  hddef getEmplee(self,Empleelist,id:int):"""從員工列表中找到對應ID員工的信息:param Empleelist::param id::return:"""ee=[]for em in Empleelist:if(em.EmployeeId==id):ee.append(em.EmployeeNo)ee.append(em.EmployeeDep)ee.append(em.EmployeeName)return eedef getHoliday(self,holidays):"""返回假期:param holidays::return:"""getname=""if(len(holidays)>0):for hd in holidays:if(hd.HolidayId==1):getname=getname+hd.HolidayName+str(hd.WorkTime)+"天 "elif(hd.HolidayId==9):getname = getname + hd.HolidayName + str(hd.WorkTime) + "分钟 "else:getname = getname + hd.HolidayName + str(hd.WorkTime) + "小时 "return getnamedef getHolidayAnnualLeave(self,holidays):"""返回年假数:param holidays::return:"""getsum=0if(len(holidays)>0):for hd in holidays:if(hd.HolidayId==6):getsum=getsum+hd.WorkTime#print("sum:",getsum,hd.HolidayName)return getsumdef getHolidayOvertime(self,holidays):"""返回加班数:param holidays::return:"""getsum=0if(len(holidays)>0):for hd in holidays:if(hd.HolidayId==4):getsum=getsum+hd.WorkTime#print("sum:",getsum,hd.HolidayName)return getsumdef getHolidayDeferred(self,holidays):"""返回補休数:param holidays::return:"""getsum=0if(len(holidays)>0):for hd in holidays:if(hd.HolidayId==3):getsum=getsum+hd.WorkTime#print("sum:",getsum,hd.HolidayName)return getsumdef getEmpleeIdAnnualLeave(self, id:int,listEmp:list):"""年假ID:param self::param listEmp::return:"""annual=0#print(listEmp)for sd in listEmp:#print(sd[0],sd[1])if(sd[0]==id):#print(sd[1])annual=annual+sd[1]return annualdef getEmpleeIdOvertime(self, id:int,listEmp:list):"""加班时间ID:param self::param listEmp::return:"""annual=0#print(listEmp)for sd in listEmp:#print(sd[0],sd[1])if(sd[0]==id):#print(sd[1])annual=annual+sd[1]return annualdef getEmpleeIdeferred(self, id:int,listEmp:list):"""调休时间ID:param self::param listEmp::return:"""annual=0#print(listEmp)for sd in listEmp:#print(sd[0],sd[1])if(sd[0]==id):#print(sd[1])annual=annual+sd[1]return annual
# This is a sample Python script.
# encoding: utf-8
# 版权所有 2023 涂聚文有限公司
# 许可信息查看:
# 描述:
# Author    : geovindu,Geovin Du 涂聚文.
# IDE       : PyCharm 2023.1 python 311
# Datetime  : 2023/9/2 20:20
# User      : geovindu
# Product   : PyCharm
# Project   : LukfookLeaveCalculation
# File      : main.py
# explain   : 学习
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.import xlrd
import xlwt
import xlwings as xw
import xlsxwriterimport openpyxl as openws
import pandas as pd
import numpy as np
import pandasql
import os
import sys
import Common.Utils
import BLL.EmpLoyeeHolidaysGet
import Model.Employee
import Model.HolidayList
from openpyxl import load_workbookdef print_hi(name):# Use a breakpoint in the code line below to debug your script.print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.# Press the green button in the gutter to run the script.
if __name__ == '__main__':print_hi('PyCharm')unstr=Common.Utils.Utils()strtest="年假2小時 事假0.5小時"  # 换行符#strtest-strtest.replace('_x000D_', ' ', regex=True)#strtest = "NaN"spstr = strtest.split(" ")thbll = BLL.EmpLoyeeHolidaysGet.EmpLoyeeHolidaysGet()tt=thbll.getHolidays(spstr[0])print("tt",tt[0].WorkTime,spstr)dataframe1 = pd.read_excel('2023年7月.xlsx')#print(dataframe1)#for idx, data in dataframe1.iterrows():#print("[{}]: {}".format(idx, data))# 第1列为日期,其他列是员工对应的列的考勤print("*************")print(dataframe1.index)print("*************")print(dataframe1.shape) #行列datarowcol=dataframe1.shapeprint("行:",datarowcol[0],",列:",datarowcol[1])excelRows=datarowcol[0]excelColumns=datarowcol[1]print("*********列标题****")print(dataframe1.columns) #第一行标题   pandas.core.indexes.base.Indextitls=dataframe1.columns.to_list()print(titls)print("标题:",titls[1])year=thbll.getYear(titls[1])print("*************",year)dmps = []# 姓名,工号,序号,部门 0行至3行为员工资料  第一行为标题,不算行的内容 可以切片方式GET数据#序号idlist =[]dataId = dataframe1.loc[0:0]for idx, datadd in dataId.iterrows():print("[{}]: {}".format(idx, datadd))idlist=datadd.to_list()for idd in range(1,len(idlist)):#employvee=Model.Employee.employee()#employvee.EmployeeId=idd#dmps.append(employvee)print(idd)print("*******序号******")#工号nolist=[]dataNo = dataframe1.loc[1:1]for idx, dataoo in dataNo.iterrows():print("[{}]: {}".format(idx, dataoo))nolist=dataoo.to_list()print("*******工号******")#部门deplist=[]dataDep = dataframe1.loc[2:2]for idx, datapp in dataDep.iterrows():print("[{}]: {}".format(idx, datapp))deplist=datapp.to_list()print("*******部门******")#姓名namelist=[]dataName = dataframe1.loc[3:3]for idx, datann in dataName.iterrows():print("[{}]: {}".format(idx, datann))namelist=datann.to_list()print("*******姓名******")for i in range(1,len(namelist)):employvee = Model.Employee.employee()employvee.EmployeeId=idlist[i]employvee.EmployeeNo=nolist[i]employvee.EmployeeName=namelist[i]employvee.EmployeeDep=deplist[i]dmps.append(employvee)for ob in dmps:print(ob.EmployeeId,ob.EmployeeNo,ob.EmployeeName,ob.EmployeeDep)#data1 = dataframe1.loc[0:3]#print(type(data1))#print(data1)#for idx, data in data1.iterrows():#print("[{}]: {}".format(idx, data))#print("*************")AnnualLeave=0Overtime=0DeferredHoliday=0SpecialLeave=0PersonalLeave=0SickLeave=0ChildcareLeave=0LateTime=0RegularHoliday=0# 内容mon=0day=0getdate=[]getHolidays=[]readrows=(excelRows-1)-3  #索此值从零开始,所以总数减一,再减三行统计的data4 = dataframe1.loc[4:readrows]  #第四行开始内空getrow=1emplist=[]for idx, datavalue in data4.iterrows():#strnum=Common.Utils.Utils.getAnnualLeave(data)employs = Model.Employee.employee()print("[{}]: {}".format(idx, datavalue))slist=datavalue.tolist()hbll=BLL.EmpLoyeeHolidaysGet.EmpLoyeeHolidaysGet() #病假4小時_x000D_事假0.5小時 未处理#print(slist) #这是读取第1列的日期数据for i in range(0, 1):strvalue = str(slist[i])print("get value:", strvalue.replace('nan', ''), type(strvalue))mon=hbll.getMonth(strvalue)day=hbll.getDay(strvalue)print("*******时间************",mon,day)getdate.append(str(year)+'-'+str(mon)+'-'+str(day))print(slist)hid=1for i in range(1,len(slist)):getdd = Model.HolidayList.HolidayList()getdd.HolidayDate = str(year) + '-' + str(mon) + '-' + str(day)#strvalue=str(slist[i]).replace(r'\s+|\\n', ' ', regex=True)  _x000D_#isnan=np.isnan(slist[i])#if(isnan):strvalue = str(slist[i]).replace('_x000D_', ' ')  # 规换单元格的换行符,否则处理不了正确数据#strvalue = str(slist[i]).replace('nan', ' ')#print("get value:",strvalue.replace('nan',''),type(strvalue))strnums = hbll.getHolidays(strvalue)  # float strprint("hid:",hid)getdd.HolidayEmpId = hidif(len(strnums)>0):for sn in range(len(strnums)):print("str:",strnums[sn].HolidayId,strnums[sn].HolidayName,strnums[sn].WorkTime)if strnums[sn].HolidayId==6:AnnualLeave=AnnualLeave+strnums[sn].WorkTimeif strnums[sn].HolidayId == 4:Overtime=Overtime+strnums[sn].WorkTimeif strnums[sn].HolidayId == 3:DeferredHoliday = DeferredHoliday + strnums[sn].WorkTimeif strnums[sn].HolidayId == 2:SpecialLeave=SpecialLeave+strnums[sn].WorkTimeif strnums[sn].HolidayId == 5:PersonalLeave=PersonalLeave+strnums[sn].WorkTimeif strnums[sn].HolidayId == 7:SickLeave=SickLeave+strnums[sn].WorkTimeif strnums[sn].HolidayId == 8:ChildcareLeave=ChildcareLeave+strnums[sn].WorkTimeif strnums[sn].HolidayId == 9:LateTime=LateTime+strnums[sn].WorkTimeif strnums[sn].HolidayId == 1:RegularHoliday=RegularHoliday+strnums[sn].WorkTimegetdd.Holdays = strnumselse:print("0")getdd.Holdays =[]hid+=1getHolidays.append((getdd))employs.EmployeeHolidays=getHolidaysemploys.EmployeeActiveDate=getdategetrow+=1# getHolidays.append(strnums)print("类型:", type(datavalue))emplist.append((employs))flist=[]getIdAnnualLeave=[]fdata=('ID','工号','部门','姓名','日期','假期')flist.append(fdata)print("date:",getdate,len(getdate))print(len(getHolidays))#for dddd in emplist:#print(dddd.EmployeeId,len(dddd.EmployeeHolidays))  #emplist[0].EmployeeHolidays:for sd in emplist[0].EmployeeHolidays:fdata=(sd.HolidayEmpId,thbll.getEmplee(dmps,sd.HolidayEmpId)[0],thbll.getEmplee(dmps,sd.HolidayEmpId)[1],thbll.getEmplee(dmps,sd.HolidayEmpId)[2],sd.HolidayDate,thbll.getHoliday(sd.Holdays))flist.append(fdata)#ananuaint=thbll.getEmpleeIdAnnualLeave(sd.HolidayEmpId,emplist[0].EmployeeHolidays)#getIdAnnualLeave.append(ananuaint)print(sd.HolidayEmpId,thbll.getEmplee(dmps,sd.HolidayEmpId)[0],thbll.getEmplee(dmps,sd.HolidayEmpId)[1],thbll.getEmplee(dmps,sd.HolidayEmpId)[2],sd.HolidayDate,thbll.getHoliday(sd.Holdays))print("**************")print(getIdAnnualLeave)print("*************",year,"年",mon,"月","考勤合计*************")#,day,"日"print("年假合计:",AnnualLeave,"小时,加班合计:",Overtime,"小时,补休合计:",DeferredHoliday,"小时,特假合计:",SpecialLeave,"小时")print("事假合计",PersonalLeave,"小时,病假合计:",SickLeave,"小时,迟到合计:",LateTime,"分钟,育儿假合计:",ChildcareLeave,"小时")print("例休:",RegularHoliday,"天")print("*****************************************************************")#年假for sd in emplist[0].EmployeeHolidays:ananuaint=[sd.HolidayEmpId,thbll.getHolidayAnnualLeave(sd.Holdays)]getIdAnnualLeave.append(ananuaint)print(getIdAnnualLeave)dd=thbll.getEmpleeIdAnnualLeave(1,getIdAnnualLeave)print("年假 id=1 sum:",dd)#加班getIDOvertimm=[]for sd in emplist[0].EmployeeHolidays:overtimeint=[sd.HolidayEmpId,thbll.getHolidayOvertime(sd.Holdays)]getIDOvertimm.append(overtimeint)print(getIDOvertimm)dov=thbll.getEmpleeIdOvertime(1,getIDOvertimm)print("加班 id=1 sum:",dov)#补休getIdDeferred=[]for sd in emplist[0].EmployeeHolidays:defint=[sd.HolidayEmpId,thbll.getHolidayDeferred(sd.Holdays)]getIdDeferred.append(defint)print(getIdDeferred)doef=thbll.getEmpleeIdeferred(1,getIdDeferred)print("补休 id=1 sum:",doef)''''''taum= []tva=("名称","合计")taum.append(tva)tva=("年假", str(AnnualLeave) + "小时")taum.append(tva)tva=("加班",str(Overtime)+"小时")taum.append(tva)tva=("补休",str(DeferredHoliday)+"小时")taum.append(tva)tva=("特假",str(SpecialLeave)+"小时")taum.append(tva)tva=("事假",str(PersonalLeave)+"小时")taum.append(tva)tva=("病假",str(SickLeave)+"小时")taum.append(tva)tva=("迟到",str(LateTime)+"分钟")taum.append(tva)tva=("育儿假",str(ChildcareLeave)+"小时")taum.append(tva)tva=("例休",str(RegularHoliday)+"天")taum.append(tva)sheetname1 = str(year) + "年" + str(mon) + "月假期"writer = pd.ExcelWriter(sheetname1+"方案.xlsx")  # 这里是创建了可写入不同sheet的文件text1 = pd.DataFrame(flist,columns=['ID','工号','部门','姓名','日期','假期'])text1.to_excel(writer, sheet_name=sheetname1,header=0, index=False)  # sheet命名为sheetname2=str(year)+"年"+str(mon)+"月合计"text2 = pd.DataFrame(taum) #,columns=['名称','合计']text2.to_excel(writer, sheet_name=sheetname2, header=0, index=False)  # sheet命名为text3=dataframe1;sheetname3=str(year) + "年" + str(mon) + "月明細"text3.to_excel(writer,sheet_name=sheetname3, header=0, index=False)#writer.sheets.update()writer.close()dataframe2 = openws.load_workbook("2023年7月.xlsx")# Define variable to read sheetsheet = dataframe2.activesetrow=datarowcol[0] #总共行setcol=datarowcol[1] #总共列#每个人的合计for idd in range(1, len(idlist)):sheet.cell(row=setrow-1, column=1+idd).value = str(thbll.getEmpleeIdAnnualLeave(idd,getIdAnnualLeave)) + "小时"sheet.cell(row=setrow - 0, column=1+idd).value = str(thbll.getEmpleeIdOvertime(idd,getIDOvertimm))+"小时"sheet.cell(row=setrow +1, column=1+idd).value = str(thbll.getEmpleeIdeferred(idd,getIdDeferred))+"小时"#合部汇总sheet.cell(row=setrow+2, column=1).value = "年假汇总"sheet.cell(row=setrow +3, column=1).value = "加班汇总"sheet.cell(row=setrow +4, column=1).value = "补休汇总"sheet.cell(row=setrow+2, column=2).value = str(AnnualLeave) + "小时"sheet.cell(row=setrow +3, column=2).value = str(Overtime)+"小时"sheet.cell(row=setrow +4, column=2).value = str(DeferredHoliday)+"小时"dataframe2.save(r'demo.xlsx')# Iterate the loop to read the cell values#for row in range(0, dataframe2.max_row):#for col in dataframe2.iter_cols(1, dataframe2.max_column):#print(col[row].value)# a single cell#v1 = xw.range("A1:A7").value#v2 = xw.range("F5").value#print("Result:", v1)# https://www.geeksforgeeks.org/how-to-add-one-row-in-an-existing-pandas-dataframe/ 新添加一行
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/109051.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Vulkan入门——编译Shaderc

编译 Vulkan-Samples时,遇到了如下shaderc编译报错。 ninja: error: /Users/xiaxl/Library/Android/sdk/ndk/21.1.6352462/sources/third_party/shaderc/libs/c_static/armeabi-v7a/libshaderc.a, needed by ../../../../build/intermediates/cmake/debug/obj/arme…

【CVPR2021】MVDNet论文阅读分析与总结

Challenge: 现有的目标检测器主要融合激光雷达和相机,通常提供丰富和冗余的视觉信息 利用最先进的成像雷达,其分辨率比RadarNet和LiRaNet中使用的分辨率要细得多,提出了一种有效的深度后期融合方法来结合雷达和激光雷达信号。 MV…

还没用熟 TypeScript 社区已经开始抛弃了

根据 rich-harris-talks-sveltekit-and-whats-next-for-svelte 这篇文章的报道, Svelte 计划要把代码从 TS 换到 JS 了。 The team is switching the underlying code from TypeScript to JavaScript. That and the update will then allow the team to incorporate…

SpingMyc项目如何搭建

目录 一、创建项目 二、环境搭建 (1)引入相关依赖 (2)在web.xml中配置前端控制器DispatcherServlet (3)编写SpringMVC核心配置文件springmvc.xml 三、测试是否成功 (1)编写控…

WebGL 正确处理对象前后的关系——隐藏面消除(深度测试)/ 深度冲突

目录 前言 验证WebGL处理对象前后关系的规则——后绘制的图形覆盖先绘制的图形 隐藏面消除(深度测试) 开启隐藏面消除功能,需要遵循以下两步: 1.开启隐藏面消除功能。 gl.enable()函数规范 2.在绘制…

Linux常用命令字典篇

Linux命令 1. 翻页查看文件 less [-N] 文件名:可以向后翻页,也可以向前翻页,-N表示显示行号 more 文件名:仅可以向后翻页 2. 端口占用信息查看 netstat -tunlp | grep 端口号:查看端口号对应的信息 lsof i: 端口号…

sqlserver查询表中所有字段信息

精简 SELECT 字段名 a.name,主键 case when exists(SELECT 1 FROM sysobjects where xtypePK and parent_obja.id and name in (SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id a.id AND colida.colid))) then √ else …

zabbix 钉钉微信企微告警(动作操作消息内容模板)

一、环境配置 1、配置zabbix服务端 2、配置监控主机&监控项&监控模板 zabbix配置安装_this page is used to test the proper operation of _疯飙的蜗牛的博客-CSDN博客 二、触发器 触发器的本质就是一个条件判断,对于不同的监控数据来说,我…

k8s集群中部署服务之部署描述文件准备

微服务部署描述文件Deploy.yaml 一、各微服务创建部署描述文件 1.1 mall-auth-server --- apiVersion: apps/v1 kind: Deployment metadata:name: mall-auth-servernamespace: sangomalllabels:app: mall-auth-server spec:replicas: 1selector:matchLabels:app: mall-auth-s…

算法通过村第七关-树(递归/二叉树遍历)白银笔记|递归实战

文章目录 前言1. 深入理解前中后序遍历从小到大递推分情况讨论,明确结束条件组合出完整的方法:从大到小 画图推演 总结 前言 提示:没有客观公正的记忆这回事,所有的记忆都是偏见,都是为自己的存活而重组过的经验。--国…

springboot 自动装配原理

一.原理解释 Spring Boot的自动配置是Spring框架的一个重要特性,它旨在简化应用程序的开发和部署过程。自动配置通过基于类路径中的依赖关系和配置文件内容来预先配置Spring应用程序的各种组件和功能。这样,我们可以在无需显式配置大量参数的情况下&…

慢查询SQL如何优化

一.什么是慢SQL? 慢SQL指的是Mysql中执行比较慢的SQL,排查慢SQL最常用的方法是通过慢查询日志来查找慢SQL。Mysql的慢查询日志是Mysql提供的一种日志记录,它用来记录Mysql中响应时间超过long_query_time值的sql,long_query_time的默认时间为10s. 二.查看慢SQL是否…