refactor: 优化日期解析逻辑并改进日志记录
- 将日期解析逻辑从pandas的read_excel中分离出来,改为单独遍历处理 - 使用logging.error替代print输出错误信息 - 在关键处理步骤添加print日志输出以便调试 - 清理了需求文档中的已完成任务标记和格式问题
This commit is contained in:
parent
13c8619cb2
commit
0193264256
18
main.py
18
main.py
@ -21,9 +21,18 @@ def custom_date_parser(x):
|
||||
except:
|
||||
return x
|
||||
|
||||
BaseData = pd.read_excel("原数据.xlsx", sheet_name="入职信息", parse_dates=["出生年月","任职年月","入职时间", "二档起始", "五档起始", "日期2"],date_parser=custom_date_parser)
|
||||
Promote = pd.read_excel("原数据.xlsx", sheet_name="职务变动", parse_dates=["任职时间","工资执行时间"],date_parser=custom_date_parser)
|
||||
BaseData = pd.read_excel("原数据.xlsx", sheet_name="入职信息")
|
||||
Promote = pd.read_excel("原数据.xlsx", sheet_name="职务变动") #
|
||||
Level_Limit = pd.read_excel("原数据.xlsx", sheet_name="职位规则",usecols="A:B", skiprows=2, names=["limit","role"])
|
||||
|
||||
for index, row in BaseData.iterrows():
|
||||
for col in ["出生年月","任职年月","参加工作时间","入职时间", "二档起始", "五档起始", "日期2"]:
|
||||
BaseData.at[index, col] = custom_date_parser(row[col])
|
||||
|
||||
for index, row in Promote.iterrows():
|
||||
for col in ["任职时间","工资执行时间"]:
|
||||
Promote.at[index, col] = custom_date_parser(row[col])
|
||||
|
||||
Rule_Role = []
|
||||
col = 2
|
||||
while True: # 职位规则
|
||||
@ -85,7 +94,7 @@ def role_limit(role:str):
|
||||
tmp = Level_Limit[Level_Limit["role"] == role].iloc[0]
|
||||
return tmp["limit"]
|
||||
except:
|
||||
print(f"[Error] 职位{role}不存在职级上限规则")
|
||||
logging.error(f"职位{role}不存在职级上限规则")
|
||||
return -1
|
||||
|
||||
max_promote = 0
|
||||
@ -149,6 +158,7 @@ BaseData["Latest_Prom"] = None
|
||||
for index, row in BaseData.iterrows():
|
||||
try:
|
||||
logging.info(f"台账:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}")
|
||||
print(f"台账:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}")
|
||||
BaseData.at[index, "Latest_Role"] = row["初始职务"]
|
||||
BaseData.at[index, "Latest_Prom"] = row["入职时间"].strftime("%Y.%m")
|
||||
wb = load_workbook("个人台账.xlsx")
|
||||
@ -189,6 +199,7 @@ for index, row in BaseData.iterrows():
|
||||
if row["入职时间"] < rule["start"]:
|
||||
History_pd.loc[len(History_pd)] = [rule["start"], "", "", "", "", "", "工资调标"]
|
||||
History_pd = History_pd.sort_values(by="时间").reset_index(drop=True)
|
||||
|
||||
for index, hrow in History_pd.iterrows(): # 数据计算
|
||||
# 调整职务职级
|
||||
if index > 0 and hrow["职务"] == "":
|
||||
@ -223,6 +234,7 @@ ws = wb.active
|
||||
for index, row in BaseData.iterrows(): # 汇总
|
||||
try:
|
||||
logging.info(f"汇总:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}")
|
||||
print(f"汇总:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}")
|
||||
for col in range(1,16):
|
||||
ws.cell(row=3+index, column=col)._style = ws.cell(row=3, column=col)._style
|
||||
ws.cell(row=6+index, column=1, value=index+1)
|
||||
|
13
规则需求.md
13
规则需求.md
@ -12,18 +12,15 @@
|
||||
- [ ] feat: 职位名称变化
|
||||
新增名称变化规则,起始、终止时间内自动替换
|
||||
- [ ] fix: 原数据模版(带校验数据值填写规范提示)
|
||||
- [x] 兼容 2003-11-20格式 [completion:: 2025-05-27]
|
||||
- [x] 兼容 yyyy-mm-dd格式 [completion:: 2025-05-27]
|
||||
- [ ] 有一行数据样例,展示数据格式,实际不生成。
|
||||
需要特定格式的:
|
||||
- [ ] 任职年月
|
||||
- [ ] 入职时间
|
||||
- [ ] 二档起始
|
||||
- [ ] 五档起始
|
||||
需要特定格式的
|
||||
- [ ] 带输入格式检测(修正、提示)
|
||||
- [x] doc: 打包成exe教程 [completion:: 2025-05-27]
|
||||
- [x] feat: 【赠送】输出log到文件 [completion:: 2025-05-27]
|
||||
- [ ] fix: 工龄列改为学龄,不参与任何计算。
|
||||
汇总工龄 = 当年年份-参加工作时间年份+工龄调增-工龄调减+1
|
||||
- [ ] feat:【赠送】新增fall-back逻辑
|
||||
- [ ] 工龄=入职时间到现在时间
|
||||
- [ ] 职务2 优先计算结果
|
||||
- [x] 职务2 优先计算结果 [completion:: 2025-05-27]
|
||||
- [ ] feat:合并部门和职务列
|
||||
- [ ] fix:检查日期输出格式(全部放在输出位置更改,除了时间2)
|
Loading…
x
Reference in New Issue
Block a user