Files
jupyter/体测单位/通用技术中国医药.ipynb
T
2025-09-22 12:39:11 +08:00

8.3 KiB

人员基本信息导入

In [1]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/通用技术中国医药人员信息.xlsx',data_only=True)
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, 5).value
    dict1['unit'] = sheet.cell(n, 4).value    
    dict1['birth'] = str(sheet.cell(n, 3).value).replace('/','-').split(' ')[0]
    dict1['phone'] = 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(len(person),'ok')
33 ok

导入手工数据

In [5]:
import openpyxl
import json
import time
from datetime import date

wb = openpyxl.load_workbook('data/通用技术中国医药手工数据.xlsx',data_only=True)
sheet = wb.active
# sheets = wb.sheetnames

filename = 'data/通用技术中国医药人员.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

dict2 = {}

for n in range(2, sheet.max_row+1):
    code = str(sheet.cell(n, 1).value)
    rq = date.fromisoformat('2025-09-18')
    birth = date.fromisoformat(dict1[code]['birth'].replace('/','-'))
    dict2[code] = dict1[code]
    days = (rq-birth).days
    dict2[code]['age'] = int(days/365)
    dict2[code]['month'] = int(days/365*12)
    dict2[code]['rq'] = '2025-09-18'
    if sheet.cell(n,4).value:
        dict2[code].setdefault('reaction',{})
        dict2[code]['reaction']['成绩'] = sheet.cell(n, 4).value
    if sheet.cell(n,5).value:
        dict2[code].setdefault('grip',{})
        dict2[code]['grip']['成绩'] = sheet.cell(n, 5).value
    if sheet.cell(n,7).value:
        dict2[code].setdefault('lung',{})
        dict2[code]['lung']['成绩'] = sheet.cell(n, 7).value
    if sheet.cell(n,6).value:
        dict2[code].setdefault('balance',{})
        dict2[code]['balance']['成绩'] = sheet.cell(n, 6).value
    if sheet.cell(n,3).value:
        dict2[code].setdefault('bmi',{})
        dict2[code]['bmi']['成绩'] = sheet.cell(n, 3).value


filename = 'data/result_通用技术中国医药.json'
with open(filename,'w') as fl:
    json.dump(dict2, fl, ensure_ascii=False) 
print(len(dict2))
33

生成测试得分

In [ ]:

导入问卷信息(新)

In [7]:
import json
import csv
import openpyxl
import time
from datetime import date



dict1 = {}

filename = 'data/result_通用技术中国医药.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
filename = 'data/通用技术中国医药人员.json'
with open(filename,'r') as fl:
    dict3 = json.load(fl)

phone =  {}
for k,v in dict3.items():
    if 'phone' in v.keys():
        phone[int(v['phone'])] = k

list1 = []
filename = 'data/survey_records_20250922.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:
     if int(item[3]) in phone.keys():        
        tcm = []
        code = phone[int(item[3])]
        
        for i in range(0,60):
            tcm.append(0)
        
       
        content = json.loads(item[4])
        if code not in dict1.keys():
            dict1[code] = dict3[code]
            rq = date.fromisoformat(item[5].replace('/','-').split(' ')[0])
            dict1[code]['rq'] = str(date.fromisoformat(item[5].replace('/','-').split(' ')[0]))
            #dict1[code]['rq'] = item[5].replace('/','-').split(' ')[0]
        else:
            rq=date.fromisoformat('2025-09-18')
            dict1[code]['rq'] = '2025-09-18'
        for k, v in content.items():
           
            if 'tcm' in k:
                i = int(k[3:])
                tcm[i-1] = int(v)           
        
        if 'tcm' in item[4]:            
            dict1[code]['tcm'] = tcm
       
        birth = date.fromisoformat(dict3[code]['birth'].replace('/','-'))
        
        days =  (rq-birth).days          
        dict1[code]['age'] = int(days/365)
        dict1[code]['month'] = int(days/365*12)
        #print(phone[item[2]])
        nn+=1
filename = 'data/result_通用技术中国医药-1.json'

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False)
In [ ]: