16 KiB
16 KiB
In [8]:
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 = int(sheet.cell(n, 2).value)
person.setdefault(str(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[str(code)] = dict1
filename = 'data/沧州炼化人员.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person),'ok')1295 ok
In [ ]:
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(str(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[str(code)] = dict1
filename = 'data/沧州炼化人员.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person),'ok')In [6]:
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 [ ]:
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')In [12]:
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_20251117-1.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))1225
In [13]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/沧州俯卧撑手工成绩.xlsx')
sheet = wb.active
filename = 'data/result_沧州炼化.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for n in range(2, sheet.max_row+1):
code = str(sheet.cell(n, 1).value)
item = 'pushup'
mark = str(sheet.cell(n, 2).value)
rq = str(sheet.cell(n, 3).value)
if code in dict2.keys():
dict2[code]['rq'] = rq
dict2[code].setdefault(item,{})
dict2[code][item]['成绩'] = mark
else:
print(code)
filename = 'data/result_沧州炼化-1.json'
with open(filename,'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print(len(re_ta)) 122 123 1225
In [ ]:
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 [7]:
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 [14]:
import json
filename = 'data/result_沧州炼化-1.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 1552999 赵崇胜 储运部 13722775060 2 1553836 王成柱 炼油一部 13111760190 1 1553839 徐振柱 炼油一部 17772650508 1
In [15]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_沧州炼化-1.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]['unit'])
list2.append(dict2[k]['birth'])
if 'phone' in v.keys():
list2.append(dict2[k]['phone'])
else:
list2.append('')
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/沧州炼化体测情况表(2025年)-1.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]: