30 KiB
30 KiB
In [2]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/北体体质康健.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(1, 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['unit'] = '北体体质康健班'
dict1['birth'] = str(sheet.cell(n, 4).value).replace('/','-').split(' ')[0]
if sheet.cell(n,5).value is not None:
dict1['phone'] = str(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('ok')ok
In [5]:
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_20240918.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 'phone' in dict1[user].keys():
re_ta[user]['phone'] = dict1[user]['phone']
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']
re_ta[user]['unit'] = dict1[user]['unit']
#birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))
birth = date.fromisoformat(dict1[user]['birth'])
#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[6]
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))87 87
In [ ]:
import json
import openpyxl
items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
bmi = ['height','weight']
title = ['编号','姓名','性别','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']
filename = 'data/727410_pdf.json'
with open(filename,'r') as fl:
list2 = json.load(fl)
list1 = []
for xm in list2:
list2 = []
list2.append(xm['id'].rjust(3,'0'))
list2.append(xm['name'])
list2.append(xm['gender'])
i = 0
if 'bmi' in xm['fits'].keys():
m_bmi = xm['fits']['bmi']['mark']
list2.append(m_bmi.split(',')[0])
list2.append(m_bmi.split(',')[1])
list2.append(xm['fits']['bmi']['score'])
i+=1
else:
list2.append('')
list2.append('')
list2.append('')
for item in items:
if item in xm['fits'].keys():
list2.append(xm['fits'][item]['mark'])
list2.append(xm['fits'][item]['score'])
i+=1
#elif item =='name':
# list2.append(dict1[k][item])
else:
list2.append('')
list2.append('')
print(list2)
if i>2:
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)
print('ok') In [24]:
import json
import csv
import openpyxl
import time
from datetime import date
dict1 = {}
filename = 'data/result_北体体质康健.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
list1 = []
filename = 'data/Survey_20240914.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)
#print(list1)
dict2 = {}
for item in list1:
psy = []
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
phone = item[2]
for k1, v1 in dict3.items():
if 'phone' in v1.keys() and phone ==v1['phone']:
dict1[k1] = dict3[k1]
#dict1[k1]['month'] = dict1[k1]['age'] *12
#print(dict1)
for item in list1:
#print(item)
psy = []
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
phone = item[2]
for k1, v1 in dict1.items():
#print((k1,v1))
if phone ==v1['phone']:
content = json.loads(item[5])
#print(content)
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
#dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
for k, v in content.items():
#print('k:',k,'v:',v)
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]:
#for i in range(5,26):
# new_valve = 5-psy[i]
# psy[i] = new_valve
for i in range(26,40):
new_valve = 1+psy[i]
psy[i] = new_valve
psy[44] = []
dict1[k1]['psy'] = psy
if 'tcm' in item[5]:
if tcm[40] ==0:
tcm[40] =1
dict1[k1]['tcm'] = tcm
if 'spine' in item[5]:
for ii in range(25,23,-1):
spine[ii] = spine[ii-1]
spine[22] = 0
dict1[k1]['spine'] = spine
#birth = date.fromisoformat(dict3[k1]['birth'].replace('/','-'))
#days = (rq-birth).days
#dict1[k1]['age'] = int(days/365)
dict1[k1]['rq'] = item[6].replace('/','-').split(' ')[0]
#print(dict1)
filename = 'data/result_北体体质康健1.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False) In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
dict1 = {}
filename = 'data/result_东营老年大学.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
list1 = []
filename = 'data/Survey_20240321.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)
list2 = []
for item in list1:
list3 = []
phone = item[2]
content = json.loads(item[5])
name = content['name']
gender = content['gender']
unit = content['unit']
list2.append([name,phone,gender,unit])
filename = 'data/东营老年大学问卷人员表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
for row in list2:
sheet.append(row)
wb.save(filename)
print('ok') In [ ]:
import json
import csv
import openpyxl
import time
from datetime import date
dict1 = {}
filename = 'data/result_东营老年大学.json'
with open(filename,'r') as fl:
dict3 = json.load(fl)
list1 = []
filename = 'data/Survey_20240321.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)
#print(list1)
dict2 = {}
for item in list1:
psy = []
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
phone = item[2]
for k1, v1 in dict3.items():
if 'phone' in v1.keys() and phone ==v1['phone']:
dict1[k1] = dict3[k1]
#dict1[k1]['month'] = dict1[k1]['age'] *12
#print(dict1)
for item in list1:
#print(item)
psy = []
tcm = []
spine = []
for i in range(0,45):
psy.append(0)
for i in range(0,60):
tcm.append(0)
for i in range(0,26):
spine.append(0)
phone = item[2]
for k1, v1 in dict1.items():
#print((k1,v1))
if 'phone' in v1.keys() and phone ==v1['phone']:
content = json.loads(item[5])
#print(content)
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
#dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
for k, v in content.items():
#print('k:',k,'v:',v)
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]:
#for i in range(5,26):
# new_valve = 5-psy[i]
# psy[i] = new_valve
for i in range(26,40):
new_valve = 1+psy[i]
psy[i] = new_valve
psy[44] = []
dict1[k1]['psy'] = psy
if 'tcm' in item[5]:
if tcm[40] ==0:
tcm[40] =1
dict1[k1]['tcm'] = tcm
if 'spine' in item[5]:
for ii in range(25,23,-1):
spine[ii] = spine[ii-1]
spine[22] = 0
dict1[k1]['spine'] = spine
#birth = date.fromisoformat(dict3[k1]['birth'].replace('/','-'))
#days = (rq-birth).days
#dict1[k1]['age'] = int(days/365)
dict1[k1]['rq'] = item[6].replace('/','-').split(' ')[0]
#print(dict1)
filename = 'data/result_东营老年大学1.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False) In [ ]:
import json
import openpyxl
items = ['bmi','lung','grip','flexion','jump','pushup','situp','balance','reaction','step']
bmi = ['height','weight']
filename = 'data/727410_pdf.json'
with open(filename,'r') as fl:
list2 = json.load(fl)
filename = 'data/result_东营老年大学1.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for xm in list2:
id = xm['id']
if str(id) in dict1.keys():
#print(id,xm['name'])
for item in xm['fits'].keys():
y_score = xm['fits'][item]['score']
if item not in dict1[str(id)].keys() or y_score != dict1[str(id)][item]['score']:
print(id,xm['name'],item,'no')In [ ]:
import openpyxl
import json
from datetime import date
filename = 'data/东营老年大学.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
wb = openpyxl.load_workbook('data/东营老年大学电话.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
person = {}
for n in range(2, sheet.max_row+1):
code = str(sheet.cell(n, 3).value)
phone = sheet.cell(n, 1).value
if code in dict1.keys():
print(phone,code,dict1[code]['phone'])
dict1[code]['phone'] = phone
filename = 'data/东营老年大学.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')In [ ]:
import openpyxl
import json
from datetime import date
filename = 'data/东营老年大学.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
wb = openpyxl.load_workbook('data/6.20日北体花名册.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict2 = {}
for n in range(3, sheet.max_row+1):
phone = int(sheet.cell(n, 3).value)
dict2[phone] = sheet.cell(n, 2).value
i = 1
for k, v in dict1.items():
if 'phone' in v.keys() and v['phone'] in dict2.keys() :
print(i,v['name'],dict2[v['phone']])
i+=1In [ ]:
%reset -f
import openpyxl
import json
from datetime import date
filename = 'data/东营老年大学.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
if 'phone' in v.keys():
dict2[v['phone']] = v['name']
wb = openpyxl.load_workbook('data/6.20日北体花名册.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
for n in range(3, sheet.max_row+1):
phone = int(sheet.cell(n, 3).value)
if phone not in dict2.keys():
print(sheet.cell(n, 2).value)
print(dict2) In [30]:
import json
from datetime import date
filename = 'data/result_北体体质康健1.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/result_北体体质康健2.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
n = 50
for k, v in dict2.items():
dict1[n+int(k)] = v
filename = 'data/result_北体体质康健.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1))170
In [29]:
import openpyxl
import json
from datetime import date
wb = openpyxl.load_workbook('data/北体体质康健.xlsx')
sheet = wb.active
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)
for n in range(1, sheet.max_row+1):
code = str(sheet.cell(n, 1).value)
if code in dict1.keys():
if sheet.cell(n,5).value is not None:
dict1[code]['phone'] = str(sheet.cell(n,5).value)
else:
dict1[code]= dict2[code]
rq = '2024-09-14'
birth = dict2[code]['birth']
days = (rq-birth).days
dict1[code]['age'] = int(days/365)
dict1[code]['month'] = int(days/365*12)
filename = 'data/result_北体体质康健.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')ok
In [33]:
import json
from datetime import date
filename = 'data/result_北体体质康健2.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for k,v in dict1.items():
if 'month' not in v.keys():
rq = date.fromisoformat(v['rq'])
birth = date.fromisoformat(v['birth'])
days = (rq-birth).days
dict1[k]['age'] = int(days/365)
dict1[k]['month'] = int(days/365*12)
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok') ok
In [36]:
import requests
import json
import openpyxl
headers = {
"Content-Type": "application/json; charset=UTF-8"
}
filename = 'data/result_北体体质康健2.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
file_path ='./北体体质康健班/'
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i=0
list2 = []
for k, v in dict1.items():
list1 = []
mydata = {}
id = str(k).rjust(4,"0")
mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'
mydata['title'] = '北体体质康健班'
mydata['subtitle'] = ''
mydata['id'] = id
mydata['name'] = v['name']
if v['sex'] == '男':
mydata['gender'] = 'male'
else:
mydata['gender'] = 'female'
mydata['month'] = v['month']
mydata['fits'] = {}
survey_list = ['tcm','psy','spine']
for item in survey_list:
if item in v.keys():
mydata.setdefault('surveys',{})
mydata['surveys'][item] = v[item]
#mydata['fits'] = {}
for item in list_item:
if item in v.keys():
mydata.setdefault('fits',{})
if item in ['lung','pushup','step','situp']:
mark = v[item]['成绩'].split()[0].split('.')[0]
else:
mark = v[item]['成绩'].split()[0]
mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}
if len(mydata['fits']) >2 :
list1.append(mydata)
list2.append([k,v['name']])
i+=1
x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)
#print(id,v['name'],x.text)
#print(mydata)
#x.close()
print(i)79
In [ ]: