29 KiB
29 KiB
In [ ]:
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, 3).value
dict1['birth'] = str(sheet.cell(n,4).value).split(' ')[0]
if sheet.cell(n,5).value is not None:
dict1['门牌号e'] = 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')In [ ]:
import json
import datetime
import csv
from datetime import date
filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k,v in dict1.items():
item[k] = v
item['1']['en'] = 'lung'
item['2']['en'] = 'grip'
item['3']['en'] = 'flexion'
item['4']['en'] = 'jump'
item['5']['en'] = 'pushup'
item['6']['en'] = 'balance'
item['7']['en'] = 'reaction'
item['8']['en'] = 'step'
item['9']['en'] = 'situp'
item['10']['en'] = 'height'
item['11']['en'] = 'weight'
re_ta = {}
dict1 = {}
list1 = []
filename = 'data/积家人员信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/places_result_20231103.csv'
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)
#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']
#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']
for result in list1:
user = str(result[2])
rq = date.fromisoformat(result[6].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 dict1[user]['sex'] == '男':
l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']
else:
l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']
birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))
#nian = int(birth[0].strip())
#yue = int(birth[1].strip())
#ri = int(birth[2].strip())
#print(k,nian,yue,ri)
item_name = item[m_item]['en']
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[8]
re_ta[user].setdefault(item_name,{})
score = int(result[4])/item[m_item]['divisor']
re_ta[user][item_name]['成绩'] = f'{score} {item[m_item]["unit"]}'
print(len(re_ta))
filename = 'data/result_积家.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))In [ ]:
import json
import openpyxl
items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
#title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/result_积家.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/积家人员信息.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
list1 = []
for k, v in dict1.items():
list2 = []
list2.append(str(k).rjust(5,'0'))
list2.append(v['name'])
list2.append(v['rq'])
list2.append(v['sex'])
list1.append(list2)
filename = 'data/积家参加测试人员信息.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import time
filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
dict3 = json.load(fl)
for k,v in dict3.items():
item[k] = v
item['1']['en'] = 'lung'
item['2']['en'] = 'grip'
item['3']['en'] = 'flexion'
item['4']['en'] = 'jump'
item['5']['en'] = 'pushup'
item['6']['en'] = 'balance'
item['7']['en'] = 'reaction'
item['8']['en'] = 'step'
item['9']['en'] = 'situp'
item['10']['en'] = 'height'
item['11']['en'] = 'weight'
filename = 'data/体质检测标准 (1).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
def cal_score(data1):
#data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46}
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)
filename = 'data/体质检测标准_BMI.json'
with open(filename,'r') as fl:
dict4 = json.load(fl)
def cal_bmi(data1):
# data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}
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]
#print(bz)
result = data1['result']
#print(data1['code'],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
#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 'height' in v.keys() and 'weight' in v.keys():
bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]
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'] = 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])}
dict2[k][item_en]['score'] = 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!') In [ ]:
In [ ]:
import openpyxl
import json
filename = 'data/积家人员信息.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
wb = openpyxl.load_workbook('data/积家问卷.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}
dict3 = {}
sheet = wb.active
data1 =list(sheet.values)
list_bh = data1[0][1:]
del data1[0]
for i in range(1,len(list_bh)+1):
list2 = []
for item in data1:
list2.append(item[i])
dict1[list_bh[i-1]] = list2
print(dict1)
filename = 'data/result_积家.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k,v in dict1.items():
if str(k) in dict2.keys():
if v[0] is not None:
psy_yangmiao_old = v[:30]
dict2[str(k)]['psy'] = psy_yangmiao_old
#dict2[str(k)]['psy_yangmiao_old'] = psy_yangmiao_old
if v[30] is not None:
tcm = v[30:90]
dict2[str(k)]['tcm'] = tcm
#print(tcm,len(tcm))
if v[90] is not None:
spine = v[90:116]
xx22 = spine[21]
xx23 = spine[22]
spine[21] = xx23
spine[22] = xx22
dict2[str(k)]['spine'] = spine
#dict2[str(k)]['psy'] = psy_yangmiao_old
#dict2[str(k)]['tcm'] = tcm
#dict2[str(k)]['spine'] = spine
filename = 'data/result_积家1.json'
with open(filename,'w') as fl:
json.dump(dict2, fl, ensure_ascii=False)
print('ok') In [ ]:
In [ ]:
import json
import openpyxl
filename = 'data/世纪花园人员信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
for k, v in dict1.items():
id = str(k).rjust(5,"0")
name = v['name']
list1.append([id,name,v['sex'],v['sex'],v['birth'],v['phone'],v['unit']])
filename = 'data/世纪花园人员信息.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list1:
sheet.append(row)
wb.save(filename)In [ ]:
import json
import datetime
import csv
list1 = []
filename = 'data/Survey_20240801.csv'
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)
#print(list1)
list3 = []
for item in list1:
phone = item[2]
content = json.loads(item[5])
name = content['name']
sex = content['gender']
birth = content['birth']
unit = content['unit']
list2 = [phone,name,sex,birth,unit]
list3.append(list2)
filename = 'data/世纪花园人员信息1.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list3:
sheet.append(row)
wb.save(filename)
In [17]:
import json
import datetime
import csv
list1 = []
filename = 'data/Survey_20240801.csv'
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)
#print(list1)
list3 = []
dict1 = {}
bh = 1
for item in list1:
phone = item[2]
content = json.loads(item[5])
name = content['name']
sex = content['Gender']
age = content['Age']
del content['name']
del content['Gender']
del content['Age']
for k, v in content.items():
if 'O' in k:
psy =[]
for i in range(1,31):
m_key = 'q'+str(i)+'O'
psy.append(content[m_key])
elif 'M' in k:
psy =[]
for i in range(1,48):
m_key = 'q'+str(i)+'M'
psy.append(content[m_key])
elif 'qv' in k:
spine =[]
for i in range(1,27):
m_key = 'qv'+str(i)
if m_key in content.keys():
spine.append(content[m_key])
else:
spine.append(0)
else:
tcm = []
for i in range(1,61):
m_key = 'q'+str(i)
if m_key in content.keys():
tcm.append(content[m_key])
else:
tcm.append(0)
dict1.setdefault(bh,{})
#print(spine)
dict1[bh]['name'] = name
dict1[bh]['sex'] = sex
dict1[bh]['age'] = age
dict1[bh]['phone'] = phone
dict1[bh]['psy'] = psy
dict1[bh]['tcm'] = tcm
dict1[bh]['spine'] = spine
bh += 1
#list3.append(list2)
filename = 'data/积家基础数据240811.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1))38
In [20]:
filename = 'data/积家基础数据240811.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k,v in dict1.items():
if v['phone'] =='18801062497':
del v['phone']
print(k)
filename = 'data/积家基础数据2408.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1))3 5 6 8 10 11 13 14 15 19 20 21 22 23 24 25 26 27 30 38 38
In [ ]:
import openpyxl
import json
filename = 'data/世纪花园人员信息.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
list2 = []
for k, v in dict1.items():
list2.append(v['phone'])
print(list2)
filename = 'data/Survey_20231027.csv'
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)
phone = str(line[2])
if phone in list2:
print(phone)
In [ ]:
import openpyxl
import json
import chardet
filename = 'data/积家人员信息.json'
with open(filename,'r',encoding='utf8') as fl:
dict3 = json.load(fl)
wb = openpyxl.load_workbook('data/积家问卷.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}
zy = [2,7,9,11,12,21,24]
no_xinli = [286]
sheet = wb.active
data1 =list(sheet.values)
list_bh = data1[0][1:]
#print(list_bh)
del data1[0]
for i in range(1,len(list_bh)+1):
list2 = []
for item in data1:
list2.append(item[i])
dict1[list_bh[i-1]] = list2
#print(dict1)
s = ''
for k,v in dict1.items():
if str(k) in dict3.keys():
if dict3[str(k)]['sex'] =='男':
sex = "m"
else:
sex = "f"
dict2 = {}
list_mx = []
list_mx.append(f'"Gender":"{sex}"')
list_mx.append(f'"Age":"O"')
dict2['surveyId'] = "merge1"
dict2['name'] = dict3[str(k)]['name']
dict2['code'] = str(k)
name = dict3[str(k)]['name']
if k not in no_xinli:
for i in range(0,30):
list_mx.append(f'"q{i+1}O":{v[i]}')
for i in range(1,61):
if i not in zy:
list_mx.append(f'"q{i}":{v[29+i]}')
for i in range(1,27):
list_mx.append(f'"qv{i}":{v[89+i]}')
ss = ','.join(list_mx)
ss ='{'+ss+'}'
dict2['data'] = ss
sj = '2023-11-10 12:00:00'
s= s+f'(\'ptv_0533_jj\',\'{name}\',\'{int(k)}\',\'{ss}\',\'{sj}\'),'
#print(dict2)
print(s)
print (chardet.detect(str.encode(s)))In [ ]:
In [ ]:
import json
filename = 'data/积家data(1).json'
with open(filename,'r',encoding='utf8') as fl:
list1 = json.load(fl)
i = 1
for item in list1:
if item['phone'] !='':
print(item['name'],item['phone'])In [23]:
import openpyxl
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
filename = 'data/积家data(1).json'
with open(filename,'r',encoding='utf8') as fl:
list1 = json.load(fl)
dict2 = {}
for item in list1:
code = str(int(item['id']))
dict2.setdefault(code,{})
dict2[code]= {'name':item['name'],'sex':item['gender'],'birth':item['birth'],'phone':item['phone']}
#print(dict2)
place_id = 698465
fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')
i = 1
list2 = []
for fn in fls:
list3 = []
fi_name =Path(fn).stem.split('-')[0]
code = str(int(fi_name))
if code in dict2.keys():
list3 = [code,dict2[code]['name'],dict2[code]['sex'],dict2[code]['phone']]
list2.append(list3)
filename = 'data/积家村报告明细.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list2:
sheet.append(row)
wb.save(filename) In [24]:
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, 3).value
if sheet.cell(n,4).value is not None:
dict1['phone'] = sheet.cell(n,4).value
person[code] = dict1
filename = 'data/积家村报告明细.json'
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')ok
In [ ]: