Files
jupyter/体测单位/燕山石化.ipynb
T
2023-04-17 13:55:48 +00:00

11 KiB

导入人员信息

In [17]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/燕山石化人员情况表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}

for n in range(2, sheet.max_row+1):
    if sheet.cell(n,1).value is not None:
        code = int(sheet.cell(n, 1).value)
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 2).value        
        dict1['sex'] = sheet.cell(n, 3).value
        birth = str(sheet.cell(n, 6).value).split()[0]
        dict1['birth'] = birth
        if sheet.cell(n,5).value is not None:
            dict1['phone'] = sheet.cell(n, 5).value
        if sheet.cell(n,7).value is not None:
            dict1['id_num'] = sheet.cell(n, 7).value
        if sheet.cell(n,8).value is not None:
            dict1['SAP'] = sheet.cell(n, 8).value
        if sheet.cell(n,9).value is not None:
            dict1['工作单位'] = sheet.cell(n, 9).value
        if sheet.cell(n,10).value is not None:
            dict1['车间'] = sheet.cell(n, 10).value
        else:
            dict1['车间'] =''
        if sheet.cell(n,11).value is not None:
            dict1['班组'] = sheet.cell(n, 11).value
        else:
            dict1['班组'] =''
        if sheet.cell(n,12).value is not None:
            dict1['工作性质'] = sheet.cell(n, 11).value
        person[code] = dict1
filename = 'data/燕山石化人员名单.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print('ok')
ok

每日成绩导入

In [23]:
import json
import time
import csv

filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
for k,v in dict1.items():
    item[k] = v
re_ta = {}
dict1 = {}
list1 = []
filename = 'data/燕山石化人员名单.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20230417.csv'
with open(filename,'r',newline='') as csv_file:
    fl = csv.reader(csv_file,delimiter=',')
    header = next(fl)    
    for line in fl:
        #line = re.sub('[\r\n\f ]{1,}', '', line)
        list1.append(line)
#print(list1)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():
        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        re_ta[user]['sex'] = dict1[user]['sex'] 
        re_ta[user]['部门'] = dict1[user]['工作单位']
        item_name = item[m_item]['name']
        re_ta[user].setdefault(item_name,{})  
        score = int(result[4])/item[m_item]['divisor']    
        re_ta[user][item_name]['成绩'] = f'{score} {item[m_item]["unit"]}'
print(len(re_ta))
filename = 'data/result_燕山石化(20230417).json'
with open(filename,'w') as fl:
    json.dump(re_ta, fl) 
print('ok')
343
ok

每日成绩导出

In [24]:
import json
import openpyxl

items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位','车间','班组','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_燕山石化(20230417).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 = []
for k, v in dict1.items():
    list2 = []
    list2.append(str(k).rjust(5,'0'))
    list2.append(v['name'])    
    list2.append(dict2[k]['sex'])
    list2.append(dict2[k]['工作单位'])    
    list2.append(dict2[k]['车间'])
    list2.append(dict2[k]['班组'])
    for item in items:
        if item in v.keys():
            list2.append(v[item]['成绩'])            
        elif item =='name':
            list2.append(v[item])
        else:
            list2.append('') 
    list1.append(list2)
filename = 'data/燕山石化体测情况表(20230417).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename)

统计部门测试人数

In [25]:
import json
import openpyxl

filename = 'data/result_燕山石化(20230417).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
    unit = v['部门']
    dict2.setdefault(unit,0)
    dict2[unit] = dict2[unit] + 1
print(dict2)
title =['单位','体测人数']
list1 = [] 
for k, v in dict2.items():
    list2 = []
    list2 = [k,v]
    list1.append(list2)
filename = 'data/燕山石化部门测试人数情况表(20230417).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename)
{'行政事务中心(离退中心)工会': 83, '机关工会': 80, '消防中心工会': 44, '生产运行保障中心': 85, '教育培训中心工会': 19, '烯烃厂工会': 2, '物装中心工会': 29, '有机化工厂工会': 1}

每日未测试人员情况表

In [26]:
import json
import openpyxl


title = ['编号','姓名','性别','单位','车间','班组']
filename = 'data/result_燕山石化(20230417).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 = []
for k, v in dict2.items():
    list2 = []
    if k not in dict1.keys():
        list2.append(str(k).rjust(5,'0'))
        list2.append(v['name'])    
        list2.append(dict2[k]['sex'])
        list2.append(dict2[k]['工作单位'])    
        list2.append(dict2[k]['车间'])
        list2.append(dict2[k]['班组'])
        list1.append(list2)
filename = 'data/燕山石化未体测人员名单(20230417).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename)        
In [ ]: