Files
jupyter/体测单位/沧州炼化.ipynb
T
2025-11-14 13:50:06 +08:00

12 KiB

体测人员导入

In [25]:
import openpyxl
import json
from datetime import date

wb = openpyxl.load_workbook('data/沧州炼化人员.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}

for n in range(2, sheet.max_row+1):
    code = sheet.cell(n, 2).value
    person.setdefault(code, {})
    dict1 = {}
    dict1['name'] = sheet.cell(n, 4).value
    dict1['sex'] = sheet.cell(n, 5).value
    dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0] 
    dict1['unit'] = sheet.cell(n, 3).value
    if sheet.cell(n, 7).value is not None:
        dict1['phone'] = str(sheet.cell(n, 7).value)
    person[code] = dict1
filename = 'data/沧州炼化人员.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print(len(person),'ok')
1301 ok
In [9]:
import openpyxl
import json
from datetime import date

wb = openpyxl.load_workbook('data/沧州炼化人员.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
list1 = []
list2 = []
for n in range(2, sheet.max_row+1):
    code = sheet.cell(n, 2).value
    if code not in list1:
        list1.append(code)
    else:
        list2.append(code)
list3 = []
for n in range(2, sheet.max_row+1):
    code = sheet.cell(n, 2).value
    if code in list2:
        list4 = [code,sheet.cell(n, 4).value,sheet.cell(n, 3).value]
        list3.append(list4)
print(list3)
filename = 'data/沧州炼化编号重复人员.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active

for row in list3:
    sheet.append(row)
    
wb.save(filename)
[['1553904', '孙建国', '物资采购中心'], ['1553904', '张巍', '应急救援中心']]

生成读卡系统文件

In [19]:
import json

filename = 'data/沧州炼化人员.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
    dict2 = {}
    #if dict1['sex'] =='男':
    #    sex = 1
    
    dict2 = {'id':k,'name':v['name'],'gender':v['sex'],'birth':v['birth'],'unit':v['unit']}
    list1.append(dict2)
json_data = json.dumps(list1,ensure_ascii=False, indent=4)  

# 将 json 数据写入文件
with open("data/card_沧州炼化人员.json", "w",encoding = 'utf-8') as file:
    file.write(json_data)   
print(len(list1),'ok')
1297 ok

获取人员测试成绩

In [29]:
import json
import datetime
import csv
from datetime import date
import my_module1 as My

filename = 'data/沧州炼化人员.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
filename = 'data/marks_20251114.csv'
re_ta = My.get_result(filename,dict1)


filename = 'data/result_沧州炼化.json'
with open(filename,'w') as fl:
    json.dump(re_ta, fl, ensure_ascii=False) 
print(len(re_ta))
1175

统计各部门测试情况

In [30]:
import json

filename = 'data/result_沧州炼化.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

filename = 'data/沧州炼化人员.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)

dict3 = {}
for k, v in dict2.items():
    unit = v['unit']
    #sub_unit = v['sub_unit']
    dict3.setdefault(unit,{})
    dict3[unit].setdefault('人数',0)
    dict3[unit].setdefault('体测人数',0)
    #dict3[unit].setdefault(sub_unit,0)
    #dict3[unit][sub_unit] = dict3[unit][sub_unit] + 1
    dict3[unit]['人数'] = dict3[unit]['人数'] + 1

title =['单位','体测人数']
list1 = []
for k,v in dict1.items():    
    unit = v['unit']
    #sub_unit = v['sub_unit']
    #dict3[unit][sub_unit] = dict3[unit][sub_unit] - 1
    dict3[unit].setdefault('体测人数',0)
    dict3[unit]['体测人数'] = dict3[unit]['体测人数'] + 1
for k, v in dict3.items():
    list2 = [k,v['人数'],v['体测人数']]
    list1.append(list2)

filename = 'data/沧州炼化部门测试情况(截至20251114).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename)

统计未体测人员明细表

In [31]:
import json
import openpyxl

filename = 'data/result_沧州炼化.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

filename = 'data/沧州炼化人员.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)

list1 = []

i = 1
for k, v in dict2.items():    
    if k not in dict1.keys():
        list2 = [i,k,v['name'],v['unit']]
        i+=1
        list1.append(list2)
#print(list1)
filename = f'data/沧州炼化未测试人员名单(截至20251114).xlsx'
title = ['序号','员工编号','姓名','部门']
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)    
wb.save(filename)

统计体测人员项目数

In [34]:
import json

filename = 'data/result_沧州炼化.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step','situp']
for k,v in dict1.items():
    list1 = []
    for item in v.keys():
        if item in xm:
            list1.append(item)
    if len(list1) <3:
        print(k,v['name'],v['unit'],v['phone'],len(list1))
1553238 齐金永 公用工程部 13231725301 2
1553763 王鑫 应急救援中心 15632778668 2
1552999 赵崇胜 储运部 13722775060 2
01553836 王成柱 炼油一部 13111760190 1
01553839 徐振柱 炼油一部 17772650508 1
In [ ]: