74 KiB
74 KiB
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 = 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, 5).value
if sheet.cell(n, 6).value is not None:
dict1['gh'] = sheet.cell(n, 6).value
dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]
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('ok')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('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/镇海(合并).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/places_result_20240922.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]['sub_unit'] = dict1[user]['sub_unit']
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_镇海(合并).json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))In [ ]:
import json
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
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 = []
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'])
for item in items:
if item in v.keys():
list2.append(v[item]['成绩'])
elif item =='name':
list2.append(v[item])
else:
list2.append('')
list2.append(dict2[k]['gwxl'])
list2.append(dict2[k]['gzz'])
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 openpyxl
filename = 'data/result_镇海.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/镇海1.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/镇海未测试人员名单(截至20240922).xlsx'
title = ['序号','员工编号','姓名','部门']
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
filename = 'data/镇海.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
print(len(dict1))
dict2 = {}
for k, v in dict1.items():
if 'phone' in v.keys():
dict2.setdefault(k,{})
dict2[k]['name'] = v['name']
dict2[k]['phone'] = v['phone']
list1 = []
for k, v in dict2.items():
i = 0
for k1, v1 in dict1.items():
if v['name']== v1['name'] and v['phone'] == v1['phone'] and k1 != k:
list1.append(max(int(k),int(k1)))
for item in set(list1):
del dict1[str(item)]
print(len(dict1))
filename = 'data/镇海1.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
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/镇海(合并).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/places_result_20240922.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']
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('/','-'))
birth = date.fromisoformat(dict1[user]['birth'])
#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_镇海(合并).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_镇海(合并).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])}
dict2[k][item_en]['score'] = cal_score(data1)
#print(k,v[item_en]['成绩'],cal_score(data1))
filename = f'data/result_镇海(合并).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_镇海(合并).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]['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 requests
import json
import openpyxl
headers = {
"Content-Type": "application/json; charset=UTF-8"
}
filename = 'data/result_镇海(合并).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
file_path ='./镇海石化/'
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i=0
list2 = []
for k, v in dict1.items():
list1 = []
mydata = {}
id = str(k).rjust(4,"0")
mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'
mydata['title'] = '中国石化镇海炼化公司'
mydata['subtitle'] = v['unit']
mydata['id'] = id
mydata['name'] = v['name']
if v['sex'] == '男':
mydata['gender'] = 'male'
else:
mydata['gender'] = 'female'
mydata['month'] = v['month']
mydata['fits'] = {}
survey_list = ['tcm','psy','spine']
for item in survey_list:
if item in v.keys():
mydata.setdefault('surveys',{})
mydata['surveys'][item] = v[item]
#mydata['fits'] = {}
for item in list_item:
if item in v.keys():
mydata.setdefault('fits',{})
if item in ['lung','pushup','step','situp']:
mark = v[item]['成绩'].split()[0].split('.')[0]
else:
mark = v[item]['成绩'].split()[0]
mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}
#if len(mydata['fits']) >2 or len(mydata['surveys']) >0:
if len(mydata['fits']) >2 :
list1.append(mydata)
list2.append([k,v['name']])
i+=1
x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)
#print(id,v['name'],x.text)
#print(mydata)
#x.close()
print(i)In [ ]:
import json
import glob
from pathlib import Path
import openpyxl
filename = 'data/镇海.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
fi_path = '/home/songyi/python/mycrm/flask/pdf/files/345321'
fls = glob.glob(f'{fi_path}/*.pdf')
dict2 = {}
for fn in fls:
fi_name =Path(fn).stem.split('-')[0]
#fi_name =Path(fn).stem
code = int(fi_name)
dict2[str(code)] = dict1[str(code)]
filename = 'data/镇海体测人员.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print(len(dict2))
list1 = []
for k, v in dict2.items():
list2 = []
if 'gh' in v.keys():
gh = v['gh']
else:
gh = ''
if 'phone' in v.keys():
phone = v['phone']
else:
phone = ''
list2 = [k,v['name'],v['sex'],v['birth'],v['unit'],gh,phone]
list1.append(list2)
#print(list1)
filename = 'data/镇海参加测试人员名单.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 glob
from pathlib import Path
import openpyxl
filename = 'data/镇海体测人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
wb = openpyxl.load_workbook('data/镇海炼化参加测试人员名单(分析用).xlsx')
sheet = wb.active
for n in range(2, sheet.max_row+1):
if sheet.cell(n, 12).value is not None:
code = int(sheet.cell(n, 1).value)
if sheet.cell(n, 12).value is not None:
dict1[str(code)]['gwlb'] = sheet.cell(n, 12).value
dict1[str(code)]['gwxl'] = sheet.cell(n, 9).value
dict1[str(code)]['gzz'] = sheet.cell(n, 11).value
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('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 = 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, 5).value
if sheet.cell(n, 6).value is not None:
dict1['gh'] = sheet.cell(n, 6).value
dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]
if sheet.cell(n, 7).value is not None:
dict1['phone'] = str(sheet.cell(n,7).value)
if len(str(sheet.cell(n,7).value))<11:
print(code,sheet.cell(n, 2).value)
person[code] = dict1
filename = 'data/镇海炼化参加测试人员.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person))In [ ]:
import openpyxl
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
mycol = mydb["pdf"]
place_id = 345321
fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')
filename = 'data/镇海炼化参加测试人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for fn in fls:
dict2 = {}
fi_name =Path(fn).stem.split('-')[0]
#fi_name =Path(fn).stem
code = int(fi_name)
dxm = dict1[str(code)]['gh']
dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}
list2.append(dict2)
i +=1
x = mycol.insert_many(list2)
print('ok') In [ ]:
import json
filename = 'data/镇海炼化参加测试人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
list2 = []
set1 = set()
for k, v in dict1.items():
if 'gh' in v.keys():
gh = v['gh']
if gh not in list1:
list1.append(v['gh'])
else:
list2.append(gh)
print(list2)In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path
fi_path = '/home/songyi/pdf-typescript/镇海石化'
new_path = 'file/镇海石化'
old = []
dict2 = {}
filename = 'data/镇海炼化参加测试人员.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)In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path
import openpyxl
fi_path = '/home/songyi/pdf-typescript/镇海石化'
filename = 'data/镇海炼化参加测试人员.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
fls = glob.glob(f'{fi_path}/*.pdf')
list1 = []
title = ['测试编号','姓名','性别','部门']
for fn in fls:
list2 = []
fi_name =Path(fn).stem.split('-')[0]
code = int(fi_name)
sex = dict1[str(code)]['sex']
unit = dict1[str(code)]['unit']
list2 = [fi_name,Path(fn).stem.split('-')[1],sex,unit]
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/result_镇海(合并).json'
with open(filename,'r',encoding = 'utf-8') 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 = []
#fiie_path ='./138/'
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(8,"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_镇海(合并).json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') In [ ]:
import json
import openpyxl
filename = 'data/result_镇海2.json'
with open(filename,'r',encoding = 'utf-8') as fl:
dict1 = json.load(fl)
filename = 'data/镇海体测人员.json'
with open(filename,'r',encoding = 'utf-8') as fl:
dict3 = 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 = []
#fiie_path ='./138/'
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i=1
list2 = []
dict2 = {}
for k, v in dict1.items():
if dict3[k]['gzz'] == '倒班':
list1 = []
mydata = {}
id = str(k).rjust(8,"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_镇海_倒班.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print(len(dict2)) In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
filename = 'data/data_镇海(合并).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
i = 1
m = 0
f = 0
score = 0
t_score = 0
for k,v in dict1.items():
if v['sex'] == '男':
m = m +1
score = score+v['score']
print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')
t_score = t_score + score
score = 0
for k,v in dict1.items():
if v['sex'] == '女':
f = f +1
score = score+v['score']
print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')
t_score = t_score + score
print(f'平均成绩:{round(t_score/(f+m),4)}分,总体:{(f+m)}人')In [ ]:
import json
items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
#filename = 'data/data_长炼医院.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
for k1, v1 in dict2.items():
di = v1[0]
gao = v1[1]
i = 0
m = 0
f = 0
for k,v in dict1.items():
if int(v['score']*100) in range(di,gao+1):
dict1[k]['level'] = k1
i+=1
if v['sex'] == '男':
m = m +1
else:
f = f+1
print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')
print(len(dict1))
with open(filename,'w') as fl:
json.dump(dict1, fl)
print('ok')In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
dict3 = {}
for item in nld:
di = item[0]
gao = item[1]
age = f'{di}-{gao}'
dict3.setdefault(age,{})
i = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
dict3[age].setdefault(v['level'],0)
if v['sex'] == '女':
dict3[age][v['level']] = dict3[age][v['level']]+1
for k, v in dict3.items():
print(k,v)In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
dict3 = {}
for item in nld:
di = item[0]
gao = item[1]
age = f'{di}-{gao}'
dict3.setdefault(age,{})
i = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
dict3[age].setdefault(v['level'],0)
if v['sex'] == '男':
dict3[age][v['level']] = dict3[age][v['level']]+1
for k, v in dict3.items():
print(k,v)In [ ]:
nld = [[16,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
score = score+v['score']
i+=1
if v['sex'] == '男':
m = m +1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:0人,男性:{m}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人,男性:{m}人')In [ ]:
import json
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1) and v['sex'] == '男':
score = score+v['score']
i+=1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1) and v['sex'] == '女':
score = score+v['score']
i+=1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')In [ ]:
with open(filename,'r') as fl:
dict1 = json.load(fl)
items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
for item in items:
score = 0
n = 0
for k, v in dict1.items():
if item in v['fits'].keys():
n = n + 1
score =score + int(v['fits'][item]['score'])
print(item,round(score/n,2),n)In [ ]:
with open(filename,'r') as fl:
dict1 = json.load(fl)
depart = []
for k, v in dict1.items():
if v['unit'] not in depart:
depart.append(v['unit'])
for item in depart:
score = 0
n = 0
for k, v in dict1.items():
if item == v['unit']:
score = score + v['score']
n = n +1
if n>0:
print(item,round(score/n,2),n)
else:
print(item,0,n)In [ ]:
with open(filename,'r') as fl:
dict1 = json.load(fl)
depart = []
for k, v in dict1.items():
if v['unit'] not in depart:
depart.append(v['unit'])
for item in depart:
score = 0
n = 0
for k, v in dict1.items():
if item == v['unit'] and v['sex'] == '男':
score = score + v['score']
n = n +1
if n>0:
print(item,round(score/n,2),n)
else:
print(item,0,n)In [ ]:
import json
items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/data_镇海(合并).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 dict1.items():
unit = v['unit']
dict3.setdefault(unit,{})
for item in items:
dict3[unit].setdefault(item,{})
dict3[unit][item].setdefault('score',0)
dict3[unit][item].setdefault('count',0)
for k1,v1 in v['fits'].items():
if k1 in items:
dict3[unit][k1]['score']+=v1['score']
dict3[unit][k1]['count']+=1
for k, v in dict3.items():
print(k)
for k1, v1 in v.items():
print(k1,v1['score'],v1['count'])In [ ]:
import json
items = ['优秀','良好','合格','不合格']
filename = 'data/data_镇海(合并).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict3 = {}
for k, v in dict1.items():
unit = v['unit']
dict3.setdefault(unit,{})
for item in items:
dict3[unit].setdefault(item,0)
for k, v in dict1.items():
unit = v['unit']
#dict3.setdefault(unit,{})
#for item in items:
#dict3[unit].setdefault(v['level'],0)
dict3[unit][v['level']] +=1
for k, v in dict3.items():
print(k,v['优秀'],v['良好'],v['合格'],v['不合格'])In [ ]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/镇海人员2025.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
code = sheet.cell(n, 5).value
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n, 3).value
dict1['birth'] = str(sheet.cell(n, 6).value).replace('/','-').split(' ')[0]
dict1['unit'] = sheet.cell(n, 7).value
dict1['phone'] = sheet.cell(n, 4).value
person[code] = dict1
filename = 'data/镇海人员2025.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person),'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, 1).value.lower()
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n, 3).value
dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0]
dict1['unit'] = sheet.cell(n, 4).value
if sheet.cell(n,6).value is not None:
dict1['phone'] = sheet.cell(n, 6).value
person[code] = dict1
filename = 'data/镇海人员2025.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person),'ok')In [ ]:
import json
filename = 'data/镇海人员2025.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_镇海2025.json", "w",encoding = 'utf-8') as file:
file.write(json_data)
print(len(list1),'ok')In [ ]:
import json
filename = 'data/镇海人员2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/data_镇海2025.json'
with open(filename,'r') as fl:
list1 = json.load(fl)
for item in list1:
code = item['id'].lower()
if code not in dict1.keys():
print(code,item['name'],item['unit'])
code = code.lower()
dict1.setdefault(code,{})
dict1[code]['name'] = item['name']
dict1[code]['sex'] = item['gender']
dict1[code]['unit'] = item['unit']
dict1[code]['birth'] = item['birth']
filename = 'data/镇海人员2025.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1),'ok')In [ ]:
import json
filename = 'data/镇海人员2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/data_镇海2025.json'
with open(filename,'r') as fl:
list1 = json.load(fl)
for item in list1:
code = item['id'].lower()
dict1[code]['name'] = item['name']
dict1[code]['sex'] = item['gender']
dict1[code]['unit'] = item['unit']
dict1[code]['birth'] = item['birth']
filename = 'data/镇海人员2025-1.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1),'ok')In [55]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/镇海人员信息确认表.xlsx')
sheet = wb.active
person = {}
for n in range(2, sheet.max_row+1):
code = sheet.cell(n, 1).value
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 2).value
dict1['sex'] = sheet.cell(n, 3).value
dict1['birth'] = str(sheet.cell(n, 5).value).replace('/','-').split(' ')[0]
dict1['unit'] = sheet.cell(n, 4).value
if sheet.cell(n, 6).value is not None:
dict1['phone'] = sheet.cell(n, 6).value
person[code] = dict1
filename = 'data/镇海人员2025.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print(len(person),'ok')1564 ok
In [ ]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/镇海项目手工成绩.xlsx')
sheet = wb.active
filename = 'data/result_镇海2025.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 = str(sheet.cell(n, 2).value)
mark = str(sheet.cell(n, 3).value)
dict2[code].setdefault(item,{})
dict2[code][item]['成绩'] = mark
filename = 'data/result_镇海2025-1.json'
with open(filename,'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print(len(re_ta)) In [ ]:
import json
import datetime
import csv
from datetime import date
import my_module1 as My
filename = 'data/镇海人员2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/marks_20251031.csv'
re_ta = My.get_result(filename,dict1)
filename = 'data/result_镇海2025.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))In [60]:
import openpyxl
import json
from datetime import date
filename = 'data/result_镇海2025.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
filename = 'data/镇海人员2025.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
dict1 = {}
for k, v in dict2.items():
code = k.upper()
dict1[code] = v
dict1[code]['unit'] = dict3[code]['unit']
filename = 'data/result_镇海2025-1.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(re_ta))
1564
In [ ]:
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_镇海2025-1.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_镇海2025.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']
title = ['编号','姓名','性别','单位','部门','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_镇海2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/镇海人员2025.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年).xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
filename = 'data/result_镇海2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/镇海人员2025.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/镇海部门测试情况(截至20251031).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_镇海2025.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/镇海人员2025.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/镇海未测试人员名单(截至20251031).xlsx'
title = ['序号','员工编号','姓名','部门']
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import openpyxl
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
place_id = 1
place_code = "20"
fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')
for fn in fls:
dict2 = {}
fi_name =Path(fn).stem.split('-')[0]
#fi_name =Path(fn).stem
code = int(fi_name)
dxm = list1[i]
dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}
list2.append(dict2)
i +=1
x = mycol.insert_many(list2)
print(len(list2),'ok') In [64]:
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
import pymongo
myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]
place_id = 1
place_code = "20"
#fi_path = '/root/data/flask/pdf/files'
#fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')
list2 = []
for fn in fls:
dict2 = {}
fi_name =Path(fn).stem.split('-')[0]
#fi_name =Path(fn).stem
code = fi_name
dict2 = {'place_id':place_id,'code':code,'fn':Path(fn).name}
list2.append(dict2)
i +=1
x = mycol.insert_many(list2)
print(len(list2),'ok') [{'place_id': 1, 'code': '016368', 'fn': '016368-陈兴旺.pdf'}, {'place_id': 1, 'code': '013403', 'fn': '013403-孙震.pdf'}, {'place_id': 1, 'code': '008553', 'fn': '008553-张国栋.pdf'}, {'place_id': 1, 'code': '015775', 'fn': '015775-张永战.pdf'}, {'place_id': 1, 'code': '015867', 'fn': '015867-高再玲.pdf'}, {'place_id': 1, 'code': '015770', 'fn': '015770-许丹萍.pdf'}, {'place_id': 1, 'code': '021574', 'fn': '021574-杨子敬.pdf'}, {'place_id': 1, 'code': '013141', 'fn': '013141-何文丰.pdf'}, {'place_id': 1, 'code': '015635', 'fn': '015635-王宇光.pdf'}, {'place_id': 1, 'code': '016224', 'fn': '016224-方丽华.pdf'}, {'place_id': 1, 'code': '014081', 'fn': '014081-谢希杭.pdf'}, {'place_id': 1, 'code': '019323', 'fn': '019323-赖佳奇.pdf'}, {'place_id': 1, 'code': '020747', 'fn': '020747-贺海鹏.pdf'}, {'place_id': 1, 'code': '014609', 'fn': '014609-靳贤锐.pdf'}, {'place_id': 1, 'code': '016309', 'fn': '016309-张鹏宇.pdf'}, {'place_id': 1, 'code': '015206', 'fn': '015206-王贺永.pdf'}, {'place_id': 1, 'code': '015184', 'fn': '015184-彭志涛.pdf'}, {'place_id': 1, 'code': '018706', 'fn': '018706-陈佳欣.pdf'}, {'place_id': 1, 'code': '021568', 'fn': '021568-张峻哲.pdf'}, {'place_id': 1, 'code': '016402', 'fn': '016402-石晓雨.pdf'}, {'place_id': 1, 'code': '016023', 'fn': '016023-何正楠.pdf'}, {'place_id': 1, 'code': '008319', 'fn': '008319-陈文近.pdf'}, {'place_id': 1, 'code': '014701', 'fn': '014701-陈顺.pdf'}, {'place_id': 1, 'code': '013564', 'fn': '013564-徐凯华.pdf'}, {'place_id': 1, 'code': '015014', 'fn': '015014-赵刚.pdf'}, {'place_id': 1, 'code': '010481', 'fn': '010481-徐旭东.pdf'}, {'place_id': 1, 'code': '016354', 'fn': '016354-张婕.pdf'}]
In [ ]: