160 lines
5.3 KiB
Python
160 lines
5.3 KiB
Python
import sys,os
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
|
|
import json
|
|
import time
|
|
from datetime import date
|
|
import csv
|
|
|
|
filename = 'data/体质检测标准 (1).json'
|
|
with open(filename,'r') as fl:
|
|
dict1 = json.load(fl)
|
|
filename = 'data/体质检测标准_BMI.json'
|
|
with open(filename,'r') as fl:
|
|
dict4 = json.load(fl)
|
|
|
|
def cal_score(data1):
|
|
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)
|
|
|
|
def cal_bmi(data1):
|
|
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]
|
|
result = data1['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
|
|
|
|
def get_wenjuan(list1,phone,dict1,dict3):
|
|
|
|
nn = 0
|
|
for item in list1:
|
|
if item[2] in phone.keys():
|
|
psy =[]
|
|
tcm = []
|
|
spine = []
|
|
for i in range(0,30):
|
|
psy.append(0)
|
|
for i in range(0,60):
|
|
tcm.append(0)
|
|
for i in range(0,26):
|
|
spine.append(0)
|
|
|
|
content = json.loads(item[5])
|
|
if phone[item[2]] not in dict1.keys():
|
|
dict1[phone[item[2]]] = dict3[phone[item[2]]]
|
|
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
|
|
dict1[phone[item[2]]]['rq'] = item[6].replace('/','-').split(' ')[0]
|
|
else:
|
|
rq = dict1[phone[item[2]]]['rq'].replace('/','-').split(' ')[0]
|
|
for k, v in content.items():
|
|
if 'psyOld' in k:
|
|
i = int(k[6:])
|
|
psy[i-1] = int(v)
|
|
if 'tcm' in k:
|
|
i = int(k[3:])
|
|
tcm[i-1] = int(v)
|
|
if 'spine' in k:
|
|
i = int(k[5:])
|
|
spine[i-1] = int(v)
|
|
if 'psyOld' in item[5]:
|
|
dict1[phone[item[2]]]['psy_yangmiao_old'] = psy
|
|
if 'tcm' in item[5]:
|
|
|
|
dict1[phone[item[2]]]['tcm'] = tcm
|
|
if 'spine' in item[5]:
|
|
for ii in range(25,23,-1):
|
|
spine[ii] = spine[ii-1]
|
|
spine[22] = 0
|
|
dict1[phone[item[2]]]['spine'] = spine
|
|
birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))
|
|
rq = date.fromisoformat(dict1[phone[item[2]]]['rq'].replace('/','-'))
|
|
days = (rq-birth).days
|
|
dict1[phone[item[2]]]['age'] = int(days/365)
|
|
dict1[phone[item[2]]]['month'] = int(days/365*12)
|
|
nn+=1
|
|
data1 = [dict1,nn]
|
|
return(data1)
|
|
|
|
def get_result(filename,dict1):
|
|
re_ta = {}
|
|
list1 = []
|
|
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)
|
|
|
|
for result in list1:
|
|
user = str(result[2])
|
|
rq = date.fromisoformat(result[5].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 'phone' in dict1[user].keys():
|
|
re_ta[user]['phone'] = dict1[user]['phone']
|
|
if dict1[user]['sex'] == '男':
|
|
l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step']
|
|
else:
|
|
l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp']
|
|
#re_ta[user]['unit'] = dict1[user]['unit']
|
|
birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))
|
|
item_name = result[3]
|
|
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[5]
|
|
re_ta[user].setdefault(item_name,{})
|
|
score = result[4]
|
|
re_ta[user][item_name]['成绩'] = score
|
|
return(re_ta) |