69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
import sys,os
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
|
|
|
|
import json
|
|
import time
|
|
|
|
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 |