11 KiB
11 KiB
In [20]:
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, 4).value
dict1['unit'] = ''
dict1['birth'] = sheet.cell(n,3).value
dict1['phone'] = 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')ok
In [21]:
import json
import datetime
import csv
from datetime import date
import my_module as My
filename = 'data/延庆区残联.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/marks_20251023.csv'
re_ta = My.get_result(filename,dict1)
filename = 'data/result_延庆区残联.json'
with open(filename,'w') as fl:
json.dump(re_ta, fl, ensure_ascii=False)
print(len(re_ta))15
In [22]:
import openpyxl
import json
wb = openpyxl.load_workbook('data/延庆区残联.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
filename = 'data/result_延庆区残联.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
for n in range(2, sheet.max_row+1):
code = str(sheet.cell(n, 1).value)
dict1[code].setdefault('bmi',{})
dict1[code]['bmi']['成绩'] = sheet.cell(n,5).value
filename = 'data/result_延庆区残联.json'
with open(filename, 'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print('ok')ok
In [23]:
import json
import time
import my_module as My
#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 'bmi' in v.keys():
#bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]
bmi_data = v['bmi']['成绩']
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'] = My.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])}
#print(k,v['name'])
dict2[k][item_en]['score'] = My.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!') ok!
In [24]:
import json
import csv
import openpyxl
import time
from datetime import date
dict1 = {}
list1 = []
filename = 'data/sql_20251023.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:
dict2 = {}
name = item[1]
phone = str(item[2])[2:]
birth = str(item[4])
content = json.loads(item[0])
tcm = []
for i in range(0,60):
tcm.append(0)
for k, v in content.items():
if 'tcm' not in k:
dict2[k] = v
else:
i = int(k[3:])
tcm[i-1] = int(v)
code = phone
dict1.setdefault(code,{})
dict1[code]['name'] = dict2['name']
if dict2['gender'] == 'm':
dict1[code]['sex'] = '男'
else:
dict1[code]['sex'] = '女'
dict1[code]['birth'] = str(item[4])
dict1[code]['tcm'] = tcm
filename = 'data/survey_延庆区残联.json'
with open(filename,'w') as fl:
json.dump(dict1, fl, ensure_ascii=False)
print(len(dict1),'ok')209 ok
In [25]:
import json
import openpyxl
filename = 'data/survey_延庆区残联.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/result_延庆区残联.json'
with open(filename,'r') as fl:
dict2 = json.load(fl)
for k, v in dict2.items():
phone = str(v['phone'])
if phone in dict1.keys():
dict2[k]['tcm'] = dict1[phone]['tcm']
filename = f'data/result_延庆区残联.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') ok!
In [ ]: