Files
jupyter/体测单位/国图.ipynb
T
2025-05-28 15:21:57 +08:00

9.1 KiB

体测人员导入

In [18]:
import openpyxl
import json
from datetime import date
from pathlib import Path

wb = openpyxl.load_workbook('data/国图测试名单.xlsx')
sheet = wb.active
sheets = wb.sheetnames

filename = 'data/国图人员.json'
path = Path(filename)
if path.exists():
    with open(filename,'r') as fl:
        person = json.load(fl) 
else:
    person = {}
    
for n in range(2, sheet.max_row+1):
    code = int(sheet.cell(n, 1).value)
    if code not in person.keys():
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 2).value
        dict1['sex'] = sheet.cell(n, 4).value
        dict1['birth'] = str(sheet.cell(n, 3).value).replace('/','-').split(' ')[0] 
        if sheet.cell(n,6).value is not None:
            dict1['phone'] = str(sheet.cell(n,6).value) 
        #dict1['phone'] = str(sheet.cell(n, 5).value)
        person[code] = dict1
filename = 'data/国图人员.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print('ok')
ok

获取人员测试成绩

In [19]:
import json
import datetime
import csv
from datetime import date
import my_module as My

filename = 'data/国图人员.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
filename = 'data/marks_20250424.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))
4

生成测试得分

In [20]:
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_国图人员.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_国图人员.json'
with open(filename,'w') as fl:
    json.dump(dict2,fl , ensure_ascii=False) 
print('ok!')        
ok!

生成报告

In [21]:
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(5,"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]
    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 or 'surveys' in mydata.keys():
    #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)
        #x.close()
print(i)
4
In [ ]: