Files
jupyter/体测单位/延庆区残联.ipynb
2025-11-03 17:56:11 +08:00

11 KiB

体测人员导入

In [20]:
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):
    code = int(sheet.cell(n, 1).value)
    person.setdefault(code, {})
    dict1 = {}
    dict1['name'] = sheet.cell(n, 2).value
    dict1['sex'] = sheet.cell(n, 4).value
    dict1['unit'] = ''
    dict1['birth'] = sheet.cell(n,3).value
    dict1['phone'] = sheet.cell(n,6).value
    person[code] = dict1
filename = 'data/延庆区残联.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
print('ok')
ok

获取人员测试成绩

In [21]:
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_20251023.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))
15

导入手工数据

In [22]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/延庆区残联.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
filename = 'data/result_延庆区残联.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

for n in range(2, sheet.max_row+1):
    code = str(sheet.cell(n, 1).value)
    dict1[code].setdefault('bmi',{})
    dict1[code]['bmi']['成绩'] = sheet.cell(n,5).value
filename = 'data/result_延庆区残联.json'
with open(filename, 'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False)
print('ok')
ok

生成测试得分

In [23]:
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 [24]:
import json
import csv
import openpyxl
import time
from datetime import date


dict1 = {}
list1 = []
filename = 'data/sql_20251023.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)

nn = 0
for item in list1:
    dict2 = {}
    name = item[1]
    phone = str(item[2])[2:]
    birth = str(item[4])
    content = json.loads(item[0])
    tcm = []
    for i in range(0,60):
        tcm.append(0)
    for k, v in content.items():           
        if 'tcm' not in k:
            dict2[k] = v
        else:
            i = int(k[3:])
            tcm[i-1] = int(v)
    
    code = phone
    dict1.setdefault(code,{})
    dict1[code]['name'] = dict2['name']
    if dict2['gender'] == 'm':
        dict1[code]['sex'] = '男'
    else:
        dict1[code]['sex'] = '女'
    dict1[code]['birth'] = str(item[4])
    
    
    dict1[code]['tcm'] = tcm
filename = 'data/survey_延庆区残联.json'

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1),'ok')
209 ok

导入问卷信息

In [25]:
import json
import openpyxl


filename = 'data/survey_延庆区残联.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

filename = 'data/result_延庆区残联.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)

for k, v in dict2.items():
    phone = str(v['phone'])
    if phone in dict1.keys():
        dict2[k]['tcm'] = dict1[phone]['tcm']
filename = f'data/result_延庆区残联.json'
with open(filename,'w') as fl:
    json.dump(dict2,fl , ensure_ascii=False) 
print('ok!')        
ok!
In [ ]: