HonorHours/main.py

61 lines
1.4 KiB
Python

import pandas as pd
import time, datetime
from math import floor
# Read & Process ID table
identities_path = r'./identities.xls'
identities = pd.read_excel(identities_path, sheet_name= "Sheet1")
id_dict = {}
index = 0
for name in identities["姓名"]:
id_dict[name] = identities["身份证号码"][index]
index += 1
# Read & Calculate Honor Hours
duty_path = r'./duty.xlsx'
duty = pd.read_excel(duty_path, sheet_name= "Sheet1")
hours_dict = {}
index = 0
time_fmt = "%H:%M"
for members in duty["人员"]:
time = duty["时间"][index].split('-')
time_end = datetime.datetime.strptime(time[1], time_fmt)
time_start = datetime.datetime.strptime(time[0], time_fmt)
hours = (time_end - time_start).seconds / 3600
members = members.split('')
for member in members:
if member not in hours_dict.keys():
hours_dict[member] = hours
else:
hours_dict[member] += hours
index += 1
for member in hours_dict.keys():
hour = hours_dict[member]
hour *= 2
if hour % 1 != 0:
hour = floor(hour)
hour /= 2
hours_dict[member] = hour
# Generate Honor Hour table
hour_path = r'./hour.xlsx'
id_list = []
for member in hours_dict.keys():
id_list.append(id_dict[member])
df = pd.DataFrame({"姓名": hours_dict.keys(), "身份证号码": id_list, "荣誉时数值": hours_dict.values()})
df = df.set_index("姓名")
df.to_excel(hour_path)
# TODO: Write to Document