87 KiB
87 KiB
In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/北海石化监测花名册2022 .xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
code = int(sheet.cell(n, 4).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 6).value
xb = str(sheet.cell(n, 7).value)
if xb == '1':
sex = '男'
elif xb =='2':
sex = '女'
dict1['sex'] = sex
dict1['unit'] = sheet.cell(n, 3).value
dict1['birth'] = str(sheet.cell(n,8).value).split(' ')[0]
person[code] = dict1
filename = 'data/北海炼化人员_2022.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
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
#SQL语句为:
# SELECT a.item_id,a.performance,a.score,a.date AS DATE1,a.avatar_id,b.unit,b.name FROM places_result AS a,_zgshhgxs AS b WHERE a.place_id=135 AND a.avatar_id=b.id AND a.avatar_id < 4999
re_ta = {}
dict1 = {}
list1 = []
#print("\n运动项目信息:")
filename = 'data/138_2210.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[4])
m_item = str(result[0])
re_ta.setdefault(user,{})
re_ta[user]['name'] = str(result[6])
re_ta[user]['unit'] = str(result[5])
item_name = item[m_item]['name']
re_ta[user].setdefault(item_name,{})
score = int(result[1])/item[m_item]['divisor']
re_ta[user][item_name]['成绩'] = f'{score} {item[m_item]["unit"]}'
re_ta[user][item_name]['得分'] =result[2]
filename = 'data/result_北海炼化2022.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl)
print('ok')In [ ]:
import json
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位/部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_北海炼化2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
list2.append(str(k).rjust(8,'0'))
list2.append(v['name'])
list2.append(dict2[k]['sex'])
list2.append(dict2[k]['unit'])
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/北海炼化体测情况表(截至20221101).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import openpyxl
import os
import glob
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
m_path = '../file/221103'
fls = glob.glob(f'../file/221103/*.pdf')
list1 = []
for fn in fls:
list2 = []
code = os.path.basename(fn).split('.')[0]
list2 = [code.rjust(5,"0"),dict1[code]['name'],dict1[code]['unit']]
list1.append(list2)
title = ['编号','姓名','部门']
filename = 'data/北海体测报告情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import openpyxl
title = ['部门','部门人数','已测人数','未测人数']
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/result_北海炼化2022.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
dict3 = {}
for k, v in dict1.items():
dict3.setdefault(v['unit'],{})
dict3[v['unit']].setdefault('人数',0)
dict3[v['unit']].setdefault('已测人数',0)
dict3[v['unit']]['人数'] = dict3[v['unit']]['人数']+1
for k, v in dict2.items():
if len(v.keys())>5:
dict3[v['unit']]['已测人数'] = dict3[v['unit']]['已测人数'] + 1
list1 = []
for k, v in dict3.items():
list2 = []
list2 = [k,v['人数'],v['已测人数'],v['人数']-v['已测人数']]
list1.append(list2)
filename = 'data/北海炼化体测人数统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
print('ok!')In [ ]:
import json
import openpyxl
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/all_result.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
dict3 = {}
dict3 = dict2['北海炼化']
for k, v in dict1.items():
name = v['name']
birth = v['birth']
for k1, v1 in dict3.items():
if v1['name'] == name and v1['birth'] == birth:
dict1[k]['old_code'] = int(k1)
dict1[k]['record'] = v1['record']
filename = 'data/北海炼化人员_2022.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import openpyxl
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k,v in dict1.items():
if 'old_code' in v.keys():
list1.append(v['old_code'])
filename = 'data/all_result.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
dict3 = {}
dict3 = dict2['北海炼化']
for k, v in dict3.items():
if int(k) not in list1:
print(k,v['name'],v['birth'])In [ ]:
import json
import openpyxl
filename = 'data/北海炼化人员_2022.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = dict1.keys()
items = ['台阶指数']
title = ['编号','姓名','部门','22年台阶指数','21年台阶指数']
filename = 'data/result_北海炼化2022.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list4 = []
for k, v in dict2.items():
if k in list1:
list2 = [k,v['name'],v['unit']]
list3 = []
for item in items:
# 获取2022年成绩
if item in v.keys():
list2.append(v[item]['成绩'].split()[0])
else:
list2.append('')
# 获取2021年成绩
if 'record' in dict1[k].keys() and item in dict1[k]['record'].keys():
list3.append(dict1[k]['record'][item]['成绩'])
else:
list3.append('')
for cj in list3:
if cj != '':
list2.append(cj.split()[0])
list4.append(list2)
filename = 'data/b北海炼化成绩对照221026.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list4:
sheet.append(row)
wb.save(filename) In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/中国石化北海炼化有限责任公司2022年健康体检团体报告统计表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
code = sheet.cell(n, 2).value
dict1.setdefault(code, {})
dict1[code]['name'] = sheet.cell(n, 3).value
dict1[code]['sex'] = sheet.cell(n, 4).value
dict1[code]['age'] = sheet.cell(n, 5).value
dict1[code].setdefault('bz',[])
dict1[code]['bz'].append(sheet.cell(n, 6).value)
filename = 'data/北海炼化2022年健康体检团体报告.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')
list1 = []
for k, v in dict1.items():
list2 = []
mbz = set(v['bz'])
list2.append(k)
list2.append(v['name'])
list2.append(v['sex'])
list2.append(v['age'])
list2.append(','.join(mbz))
list1.append(list2)
title = ['体检编号','姓名','性别','年龄','体检症状']
filename = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告汇总统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import openpyxl
import json
list2 = []
file_name = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告.txt'
with open(file_name,'r',encoding='utf-8') as fl:
for l in fl:
list1 = []
list1 = l.strip('\n').split()
del list1[0]
list2.append(list1)
print(list2)
title = ['体检编号','姓名','性别','年龄','体检症状']
filename = 'data/中国石化北海炼化有限责任公司2022年健康体检团体报告统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list2:
sheet.append(row)
wb.save(filename)
In [ ]:
import openpyxl
import json
import itertools
import operator
filename = 'data/北海炼化2022年健康体检团体报告.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
bz = set()
for k, v in dict1.items():
for i in v['bz']:
bz.add(i)
print(len(bz))
dict2 = {}
dict3 = {}
i = 1
for n in [2,3,4]:
iter1 = itertools.combinations(bz, n)
list1 = list(iter1)
print(len(list1))
list2 = []
for item in list1:
for k, v in dict1.items():
list3 = []
if set(item).issubset(v['bz']):
dict3[i] =item
list3 = [k,i]
list2.append(list3)
i = i+1
dict2[n] = list2
dict2['bingzheng'] = dict3
filename = 'data/北海炼化2022年健康体检病症组合.json'
with open(filename,'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok')In [ ]:
import openpyxl
import json
import itertools
import operator
filename = 'data/北海炼化2022年健康体检病症组合.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
bz = dict1['bingzheng']
bz1 = dict1['2']
list1 = []
for k, v in bz.items():
list2 = []
i = 1
bzs = len(v)
for v1 in dict1[str(bzs)]:
if v1[1] == int(k):
i+=1
list2 =[bzs,','.join(v),i]
list1.append(list2)
filename = 'data/中国石化北海炼化有限责任公司2022年病症统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path
import openpyxl
fi_path = 'data/北海炼化/'
fls = glob.glob(f'{fi_path}/*.xlsx')
i = 1
person = {}
for fl in fls:
wb = openpyxl.load_workbook(fl)
sheet = wb.active
# sheets = wb.sheetnames
for n in range(3,sheet.max_row+1):
if sheet.cell(n,1).value is not None:
code = str(i)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n,3 ).value
dict1['婚姻'] = sheet.cell(n, 5).value
dict1['phone'] = str(sheet.cell(n,6).value)
dict1['id'] = sheet.cell(n,7 ).value
dict1['总工龄'] = sheet.cell(n, 8).value
dict1['损害工龄'] = sheet.cell(n, 9).value
dict1['既往病史'] = sheet.cell(n,10 ).value
dict1['有毒因素'] = sheet.cell(n, 11).value
dict1['unit'] = sheet.cell(n, 12).value
dict1['工种'] = sheet.cell(n, 13).value
dict1['防护措施'] = sheet.cell(n,15 ).value
person[code] = dict1
i+=1
filename = 'data/北海炼化2023.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
id= []
phone = []
for k, v in dict1.items():
if v['phone'] not in phone:
phone.append(v['phone'] )
else:
print(v['name'] ,v['phone'])
if v['id'] not in id:
id.append(v['id'] )
else:
print(v['id'] ,v['id'] )
In [ ]:
import json
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
id= '440906199104060046'
for k, v in dict1.items():
if v['id'] == id:
print(id,v['name'])In [ ]:
import json
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
phone= ['13807799565','18877976757','13927509537']
for k, v in dict1.items():
if v['phone'] in phone:
print(v['phone'],v['name'])In [ ]:
import json
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k, v in dict1.items():
id = str(v['id'])
#print(id)
birth = id[6:10] + '-' +id[10:12] + '-' +id[12:14]
dict1[k]['birth'] = birth
filename = 'data/北海炼化2023.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
import openpyxl
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
person = json.load(fl)
i = len(person)+1
fl = 'data/北海炼化机关名单表(2023年汇总156人).xlsx'
wb = openpyxl.load_workbook(fl)
sheet = wb.active
# sheets = wb.sheetnames
for n in range(3,sheet.max_row+1):
if sheet.cell(n,1).value is not None:
code = str(i)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n,3 ).value
dict1['phone'] = sheet.cell(n,6).value
dict1['id'] = sheet.cell(n,5 ).value
dict1['婚姻'] = sheet.cell(n, 11).value
dict1['unit'] = sheet.cell(n, 8).value
person[code] = dict1
i+=1
filename = 'data/北海炼化2023.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')
In [ ]:
import json
import openpyxl
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
person = json.load(fl)
i = len(person)+1
fl = 'data/北海炼化上岗体检人员名单 (2023年).xlsx'
wb = openpyxl.load_workbook(fl)
sheet = wb.active
# sheets = wb.sheetnames
for n in range(5,sheet.max_row+1):
if sheet.cell(n,1).value is not None:
code = str(i)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n,3 ).value
dict1['phone'] = str(sheet.cell(n,7).value)
dict1['id'] = sheet.cell(n,6 ).value
dict1['有毒因素'] = sheet.cell(n, 11).value
dict1['unit'] = '新上岗'
dict1['工种'] = sheet.cell(n, 8).value
dict1['防护措施'] = sheet.cell(n,13 ).value
person[code] = dict1
i+=1
filename = 'data/北海炼化2023.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')
In [ ]:
import json
import openpyxl
filename = 'data/北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
list2 = [str(k).rjust(4,'0'),v['name'],v['sex'],v['unit'],v['birth'],v['phone']]
list1.append(list2)
filename = 'data/北海炼化人员信息(2023年).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/北海炼化人员信息(2023年) (更新).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
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
dict1['unit'] = sheet.cell(n, 4).value
dict1['birth'] = sheet.cell(n,5).value
if sheet.cell(n,6).value is not None:
dict1['phone'] = str(sheet.cell(n,6).value)
person[code] = dict1
filename = 'data/北海炼化2023年.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
filename = 'data/北海炼化2023年.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/data_北海炼化.json", "w",encoding = 'utf-8') as file:
file.write(json_data)
print('ok')In [ ]:
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/北海炼化2023年.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/places_result_20231122.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]['unit'] = dict1[user]['unit']
re_ta[user]['phone'] = dict1[user]['phone']
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"]}'
re_ta[user]['rq'] = str(result[6])
rq = date.fromisoformat(str(result[6]))
birth = date.fromisoformat(dict1[user]['birth'])
days = (rq-birth).days
re_ta[user]['age'] = int(days/365)
re_ta[user]['month'] = int(days/365*12)
print(len(re_ta))
filename = 'data/result_北海炼化2023.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))In [ ]:
import json
import openpyxl
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.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)
filename = f'data/北海炼化未测试人员名单(截至20231111).xlsx'
title = ['序号','员工编号','姓名','部门']
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
phone = {}
for k,v in dict3.items():
if 'phone' in v.keys():
phone[v['phone']] = k
list1 = []
filename = 'data/Survey_20231127.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
list1.append(line)
#print(list1)
dict2 = {}
psy =[]
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
psy[44] = []
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
for item in list1:
if item[2] in phone.keys():
psy =[]
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
psy[44] = []
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
content = json.loads(item[5])
if phone[item[2]] not in dict1.keys():
dict1[phone[item[2]]] = dict3[phone[item[2]]]
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
#dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
for k, v in content.items():
if 'psy' in k:
i = int(k[3:])
psy[i-1] = int(v)
if 'tcm' in k:
i = int(k[3:])
tcm[i-1] = int(v)
if 'spine' in k:
i = int(k[5:])
spine[i-1] = int(v)
if 'psy' in item[5]:
#for i in range(5,26):
# new_valve = 5-psy[i]
# psy[i] = new_valve
for i in range(26,40):
new_valve = 1+psy[i]
psy[i] = new_valve
dict1[phone[item[2]]]['psy'] = psy
if 'tcm' in item[5]:
dict1[phone[item[2]]]['tcm'] = tcm
if 'spine' in item[5]:
dict1[phone[item[2]]]['spine'] = spine
birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))
days = (rq-birth).days
dict1[phone[item[2]]]['age'] = int(days/365)
dict1[phone[item[2]]]['month'] = int(days/365*12)
filename = 'data/result_北海炼化2023.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False) In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
phone = {}
for k,v in dict3.items():
if 'phone' in v.keys():
phone[v['phone']] = k
list1 = []
filename = 'data/Survey_20231114.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
list1.append(line)
#print(list1)
dict2 = {}
psy = []
tcm = []
spine = []
for i in range(0,44):
psy.append(0)
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
print(len(spine))In [ ]:
import json
import csv
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k,v in dict1.items():
i = 0
list2 = []
for item in items:
if item in v.keys():
i+=1
print(k)
list2 = [k,v['name'],v['sex'],v['age'],v['unit'],v['phone'],i]
if 'psy' in v.keys():
list2.append(1)
else:
list2.append(0)
if 'tcm' in v.keys():
list2.append(1)
else:
list2.append(0)
if 'spine' in v.keys():
list2.append(1)
else:
list2.append(0)
list1.append(list2)
filename = 'data/北海炼化员工测试项目情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
phone = {}
for k,v in dict3.items():
if 'phone' in v.keys():
phone[v['phone']] = k
list1 = []
filename = 'data/Survey_20231119.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
list1.append(line)
for item in list1:
if item[2] not in phone.keys():
print(item[2])
In [ ]:
import json
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.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(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/北海炼化部门测试情况.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import datetime
import csv
from datetime import date
filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k,v in dict1.items():
item[k] = v
item['1']['en'] = 'lung'
item['2']['en'] = 'grip'
item['3']['en'] = 'flexion'
item['4']['en'] = 'jump'
item['5']['en'] = 'pushup'
item['6']['en'] = 'balance'
item['7']['en'] = 'reaction'
item['8']['en'] = 'step'
item['9']['en'] = 'situp'
item['10']['en'] = 'height'
item['11']['en'] = 'weight'
re_ta = {}
dict1 = {}
list1 = []
filename = 'data/北海炼化2023年.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/places_result_20231122.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)
#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']
#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']
for result in list1:
user = str(result[2])
rq = date.fromisoformat(result[6].replace('/','-'))
if user in dict1.keys():
l_xm = []
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]['phone'] = dict1[user]['phone']
if dict1[user]['sex'] == '男':
l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']
else:
l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']
re_ta[user]['unit'] = dict1[user]['unit']
birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))
#nian = int(birth[0].strip())
#yue = int(birth[1].strip())
#ri = int(birth[2].strip())
#print(k,nian,yue,ri)
item_name = item[m_item]['en']
if item_name in l_xm:
days = (rq-birth).days
re_ta[user]['age'] = int(days/365)
re_ta[user]['month'] = int(days/365*12)
re_ta[user]['rq'] = result[6]
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_北海炼化2023.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))In [ ]:
import json
import time
filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
dict3 = json.load(fl)
for k,v in dict3.items():
item[k] = v
item['1']['en'] = 'lung'
item['2']['en'] = 'grip'
item['3']['en'] = 'flexion'
item['4']['en'] = 'jump'
item['5']['en'] = 'pushup'
item['6']['en'] = 'balance'
item['7']['en'] = 'reaction'
item['8']['en'] = 'step'
item['9']['en'] = 'situp'
item['10']['en'] = 'height'
item['11']['en'] = 'weight'
filename = 'data/体质检测标准 (1).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
def cal_score(data1):
#data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46}
person = dict1['person']
criteria = dict1['criteria']
if data1['age'] >59:
data1['age'] = 59
if data1['age'] <20:
data1['age'] = 20
info = data1['sex']+str(data1['age'])
bz = person[info]
mx = criteria[bz][data1['item']]
result = data1['result']
if data1['item'] == 'reaction':
for bz1 in mx:
if result > bz1:
#print(bz1)
score = mx.index(bz1,0)
break
else:
score = 5
else:
for bz1 in mx:
if result < bz1:
#print(bz1)
score = mx.index(bz1,0)
break
else:
score = 5
return(score)
filename = 'data/体质检测标准_BMI.json'
with open(filename,'r') as fl:
dict4 = json.load(fl)
def cal_bmi(data1):
# data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}
person = dict4['person']
criteria = dict4['criteria']
if data1['age'] > 59:
data1['age'] = 59
if data1['age'] <20:
data1['age'] = 20
info = data1['sex']+str(data1['age'])
bz = person[info]
#print(bz)
result = data1['result']
#print(data1['code'],result)
height = int(float(result.split(',')[0]))
weight = float(result.split(',')[1])
if str(height) not in criteria[bz]:
score = 1
else:
mx = criteria[bz][str(height)]
if weight < mx[0]:
score = 1
elif weight < mx[1]:
score = 3
elif weight < mx[2]:
score = 5
elif weight <= mx[3]:
score = 3
elif weight > mx[3]:
score = 1
return score
#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
#print(k)
if v['sex'] == '男':
sex = 'M'
else:
sex = 'F'
if 'height' in v.keys() and 'weight' in v.keys():
bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]
data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}
dict2[k]['bmi'] = {}
dict2[k]['bmi']['成绩'] = bmi_data
dict2[k]['bmi']['score'] = cal_bmi(data1)
for item_en in list_item:
if item_en in v.keys():
data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}
#print(k,v['name'])
dict2[k][item_en]['score'] = cal_score(data1)
#print(k,v[item_en]['成绩'],cal_score(data1))
filename = f'data/result_北海炼化2023.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') In [ ]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
bmi = ['height','weight']
title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])
list2 = []
list2.append(str(k).rjust(5,'0'))
list2.append(dict1[k]['name'])
list2.append(dict1[k]['sex'])
list2.append(dict1[k]['unit'])
#list2.append(dict1[k]['phone'])
i = 0
if 'bmi' in dict1[k].keys():
list2.append(dict1[k]['height']['成绩'])
list2.append(dict1[k]['weight']['成绩'])
list2.append(dict1[k]['bmi']['score'])
i+=1
else:
list2.append('')
list2.append('')
list2.append('')
for item in items:
if item in dict1[k].keys():
list2.append(dict1[k][item]['成绩'])
list2.append(dict1[k][item]['score'])
i+=1
elif item =='name':
list2.append(dict1[k][item])
else:
list2.append('')
list2.append('')
if i>2:
list1.append(list2)
filename = 'data/北海炼化体测情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
print('ok') In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化2023年.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
phone = set()
phone1 = set()
for k,v in dict3.items():
phone.add(v['phone'])
for k,v in dict1.items():
phone1.add(v['phone'])
list1 = []
filename = 'data/Survey_20231122.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
list1.append(line)
for item in list1:
if item[2] in phone and item[2] not in phone1:
print(item[2])
In [ ]:
import json
import csv
import glob
from pathlib import Path
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
fi_path = '/home/songyi/pdf-typescript/北海炼化2023_1'
fls = glob.glob(f'{fi_path}/*.pdf')
list1 = []
for fl in fls:
fn = Path(fl).stem.split('-')[0]
list1.append(int(fn))
print(len(dict1))
for k ,v in dict1.items():
if int(k) not in list1:
print(k,v['name'])In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path
fi_path = '/home/songyi/pdf-typescript/134'
new_path = 'file/134'
old = []
dict2 = {}
filename = 'data/天津石化人员名单2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
fls = glob.glob(f'{fi_path}/*.pdf')
for fn in fls:
fi_name =Path(fn).stem.split('-')[0]
code = int(fi_name)
unit_path = Path(new_path,dict1[str(code)]['unit'])
unit_path.mkdir(parents = True, exist_ok = True)
n_name = Path(unit_path,Path(fn).stem+'.pdf')
if not os.path.exists(n_name):
shutil.copyfile(fn,n_name)
#print(n_name)In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2023.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
wb = openpyxl.load_workbook('data/北海炼化新名单.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
list1 = []
for n in range(5, sheet.max_row+1):
if sheet.cell(n,2).value is not None:
list1.append(sheet.cell(n,2).value)
print(len(list1))
i = 1
for k, v in dict1.items():
name = v['name']
if name not in list1:
print(i,name)
i+=1In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/北海体检报告数据整理2024.xlsx')
#sheet = wb.active
# sheets = wb.sheetnames
sheet = wb['Sheet3']
dict1 = {}
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
code = sheet.cell(n, 2).value
dict1.setdefault(code, {})
dict1[code]['name'] = sheet.cell(n, 3).value
dict1[code]['sex'] = sheet.cell(n, 4).value
dict1[code]['age'] = sheet.cell(n, 5).value
dict1[code].setdefault('bz',[])
dict1[code]['bz'].append(sheet.cell(n, 7).value)
filename = 'data/北海炼化2023年健康体检团体报告.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')
list1 = []
for k, v in dict1.items():
list2 = []
mbz = set(v['bz'])
list2.append(k)
list2.append(v['name'])
list2.append(v['sex'])
list2.append(v['age'])
list2.append(','.join(mbz))
list1.append(list2)
title = ['体检编号','姓名','性别','年龄','体检症状']
filename = 'data/中国石化北海炼化有限责任公司2023年职业体检团体报告汇总统计表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/北海体检报告数据整理2024.xlsx')
#sheet = wb.active
# sheets = wb.sheetnames
sheet = wb['原始']
xm = set()
list1 = []
for n in range(2, sheet.max_row+1):
if sheet.cell(n,2).value is None:
break
else:
xm.add(sheet.cell(n, 6).value)
for i, item in enumerate(xm):
list1.append([i+1,item])
filename = 'data/中国石化北海炼化有限责任公司2023年体检指标统计表1.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
title = ['序号','项目名称']
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename) In [ ]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/北海人员202410.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(3, sheet.max_row+1):
if sheet.cell(n, 1).value is not None:
#print(sheet.cell(n, 1).value)
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
dict1['unit'] = sheet.cell(n, 6).value
dict1['phone'] = sheet.cell(n, 5).value
dict1['birth'] = sheet.cell(n,4).value
person[code] = dict1
filename = 'data/北海炼化人员2024.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [ ]:
import json
filename = 'data/北海炼化人员2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
dict2 = {}
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_北海炼化人员2024.json", "w",encoding = 'utf-8') as file:
file.write(json_data)
print('ok')In [35]:
import json
import datetime
import csv
from datetime import date
re_ta = {}
list1 = []
filename = 'data/北海炼化人员2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/marks_20241201.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)
for result in list1:
user = str(result[2])
rq = date.fromisoformat(result[5].replace('/','-'))
if user in dict1.keys():
l_xm = []
m_item = str(result[3])
re_ta.setdefault(user,{})
re_ta[user]['name'] = dict1[user]['name']
re_ta[user]['sex'] = dict1[user]['sex']
if 'phone' in dict1[user].keys():
re_ta[user]['phone'] = dict1[user]['phone']
if dict1[user]['sex'] == '男':
l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step']
else:
l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp']
re_ta[user]['unit'] = dict1[user]['unit']
birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))
item_name = result[3]
if item_name in l_xm:
days = (rq-birth).days
re_ta[user]['age'] = int(days/365)
re_ta[user]['month'] = int(days/365*12)
re_ta[user]['rq'] = result[5]
re_ta[user].setdefault(item_name,{})
score = result[4]
re_ta[user][item_name]['成绩'] = score
filename = 'data/result_北海炼化2024.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))739
In [36]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化人员2024.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]['unit'])
if 'bmi' in v.keys():
height = v['bmi']['成绩'].split(',')[0]
weight = v['bmi']['成绩'].split(',')[1]
list2.append(height)
list2.append(weight)
else:
list2.append('')
list2.append('')
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/北海炼化体测情况表2024.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [37]:
import json
import time
import my_module as My
#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
#print(k)
if v['sex'] == '男':
sex = 'M'
else:
sex = 'F'
if 'bmi' in v.keys():
#bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]
bmi_data = v['bmi']['成绩']
data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}
dict2[k]['bmi'] = {}
dict2[k]['bmi']['成绩'] = bmi_data
dict2[k]['bmi']['score'] = My.cal_bmi(data1)
for item_en in list_item:
if item_en in v.keys():
data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}
#print(k,v['name'])
dict2[k][item_en]['score'] = My.cal_score(data1)
#print(k,v[item_en]['成绩'],cal_score(data1))
filename = f'data/result_北海炼化2024.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') ok!
In [43]:
import json
import csv
import openpyxl
import time
from datetime import date
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化人员2024.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
phone = {}
for k,v in dict3.items():
if 'phone' in v.keys():
phone[v['phone']] = k
list1 = []
filename = 'data/Survey_20241206.csv'
with open(filename,'r',newline='') as csv_file:
fl = csv.reader(csv_file,delimiter=',')
header = next(fl)
for line in fl:
list1.append(line)
#print(list1)
dict2 = {}
psy =[]
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
psy[44] = []
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
for item in list1:
if item[2] in phone.keys():
psy =[]
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
psy[44] = []
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
content = json.loads(item[5])
if phone[item[2]] not in dict1.keys():
dict1[phone[item[2]]] = dict3[phone[item[2]]]
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
#dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
for k, v in content.items():
if 'psy' in k:
i = int(k[3:])
psy[i-1] = int(v)
if 'tcm' in k:
i = int(k[3:])
tcm[i-1] = int(v)
if 'spine' in k:
i = int(k[5:])
spine[i-1] = int(v)
if 'psy' in item[5]:
#for i in range(5,26):
# new_valve = 5-psy[i]
# psy[i] = new_valve
for i in range(26,40):
new_valve = 1+psy[i]
psy[i] = new_valve
dict1[phone[item[2]]]['psy'] = psy
if 'tcm' in item[5]:
dict1[phone[item[2]]]['tcm'] = tcm
if 'spine' in item[5]:
dict1[phone[item[2]]]['spine'] = spine
birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))
days = (rq-birth).days
dict1[phone[item[2]]]['age'] = int(days/365)
dict1[phone[item[2]]]['month'] = int(days/365*12)
filename = 'data/result_北海炼化2024.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False) In [47]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
bmi = ['height','weight']
title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])
list2 = []
list2.append(str(k).rjust(5,'0'))
list2.append(dict1[k]['name'])
list2.append(dict1[k]['sex'])
list2.append(dict1[k]['unit'])
i = 0
if 'bmi' in dict1[k].keys():
list2.append(dict1[k]['bmi']['成绩'].split(',')[0])
list2.append(dict1[k]['bmi']['成绩'].split(',')[1])
list2.append(dict1[k]['bmi']['score'])
i+=1
else:
list2.append('')
list2.append('')
list2.append('')
for item in items:
if item in dict1[k].keys():
list2.append(dict1[k][item]['成绩'])
list2.append(dict1[k][item]['score'])
i+=1
elif item =='name':
list2.append(dict1[k][item])
else:
list2.append('')
list2.append('')
if i>2:
list1.append(list2)
filename = 'data/北海炼化体测情况明细表(2024年).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)
print('ok') ok
In [ ]:
import json
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化人员2024.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(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/北海炼化部门测试情况2024.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import openpyxl
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/北海炼化人员2024.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)
filename = f'data/北海炼化未测试人员名单.xlsx'
title = ['序号','员工编号','姓名','部门']
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [39]:
import json
import openpyxl
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
#items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
items = {}
items['lung'] = '肺活量'
items['grip'] ='握力'
items['flexion'] ='坐位体前屈'
items['jump'] ='纵跳'
items['pushup'] ='俯卧撑'
items['balance'] ='单脚站立'
items['reaction'] ='选择反应时'
items['step'] ='台阶指数'
items['situp'] ='一分钟仰卧起坐'
items['bmi'] ='BMI'
list1 = []
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i=1
list2 = []
dict2 = {}
for k, v in dict1.items():
list1 = []
mydata = {}
id = str(k).rjust(5,"0")
mydata['unit'] = v['unit']
mydata['name'] = v['name']
mydata['sex'] = v['sex']
mydata['month'] = v['month']
age = int(v['month']/12)
if age <20:
mydata['age'] = 20
else:
mydata['age'] = int(v['month']/12)
mydata['fits'] = {}
score = 0
for item in list_item:
if item in v.keys():
if item in ['lung','pushup','step','situp']:
mark = v[item]['成绩'].split()[0].split('.')[0]
else:
mark = v[item]['成绩'].split()[0]
mydata['fits'][items[item]] = {'mark':mark,'score':v[item]['score']}
score = score + v[item]['score']
mydata['score'] = round(score/len(mydata['fits']),2)
if len(mydata['fits']) >2:
dict2[str(k)] = mydata
filename = f'data/data_北海炼化2024.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print(len(dict2))
print('ok!')738 ok!
In [58]:
import json
import openpyxl
filename = 'data/result_北海炼化2024.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list2 = []
for k,v in dict1.items():
#list2 = []
list2.append([k,v['name'],v['sex'],v['age'],v['unit']])
filename = 'data/北海人员基本情况2024.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list2:
sheet.append(row)
wb.save(filename)
print(len(dict1))
print('ok') 757 ok
In [ ]: