24 KiB
24 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 = str(sheet.cell(n, 4).value)
person.setdefault(code, {})
dict1 = {}
dict1['name'] = sheet.cell(n, 1).value
dict1['unit'] = '农工党延庆支部'
dict1['sex'] = sheet.cell(n, 2).value
nianyue = str(sheet.cell(n,3).value).replace('.','-')+'-01'
dict1['birth'] = nianyue
person[code] = dict1
filename = 'data/农工党延庆支部.json'
print(len(person))
with open(filename, 'w') as fl:
json.dump(person, fl, ensure_ascii=False)
print('ok')In [1]:
import json
import csv
import openpyxl
from datetime import date
filename = 'data/农工党延庆支部.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
filename = 'data/Survey_20231128.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)
dict2 = {}
m_rq = '2023-11-20'
rq= date.fromisoformat(m_rq.replace('/','-'))
for item in list1:
if item[2] in dict1.keys():
dict2[str(item[2])] = dict1[str(item[2])]
rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])
tcm = []
for i in range(0,60):
tcm.append(0)
content = json.loads(item[5])
for k, v in content.items():
i = int(k[1:])
tcm[i-1] = int(v)
dict2[str(item[2])]['tcm'] = tcm
birth = date.fromisoformat(dict1[str(item[2])]['birth'].replace('/','-'))
days = (rq-birth).days
dict2[str(item[2])]['age'] = int(days/365)
dict2[str(item[2])]['month'] = int(days/365*12)
print(len(dict2))
filename = 'data/result_农工党延庆支部问卷.json'
with open(filename,'w') as fl:
json.dump(dict2, fl, ensure_ascii=False) 26
In [3]:
import json
import csv
import openpyxl
filename = 'data/农工党延庆支部.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
filename = 'data/Survey_20231128.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)
phone1 = set()
for result in list1:
phone1.add(result[2])
for k, v in dict1.items():
if k not in phone1:
print(k,v['name'])13501017366 程大庆 13910270600 袁正东 13501017663 李志玖 13901363461 陈学军 13911795921 祁向东 18600419150 鲁兴隆 17316020604 刘凡
In [ ]:
import json
import csv
import openpyxl
filename = 'data/农工党延庆支部.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/Survey_20231121.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)
for item in list1:
if item[2] not in dict1.keys():
print(item[2])In [12]:
import requests
import json
headers = {
"Content-Type": "application/json; charset=UTF-8"
}
filename = 'data/result_农工党延庆支部问卷.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
list1 = []
fiie_path ='./政法委1/'
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i = 27
list2 = []
for k,v in dict1.items():
list1 = []
mydata = {}
id = k.rjust(3,"0")
mydata['path'] = fiie_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']
if 'tcm' in v.keys():
mydata.setdefault('surveys',{})
mydata['surveys']['tcm'] = v['tcm']
mydata['fits'] = {}
#mydata.setdefault('fits',{})
for item in list_item:
if item in dict1[k].keys():
if item in ['lung','pushup','step','situp']:
mark = dict1[k][item]['成绩'].split()[0].split('.')[0]
else:
mark = dict1[k][item]['成绩'].split()[0]
mydata['fits'][item] = {'mark':mark,'score':dict1[k][item]['score']}
#print(mydata)
list1.append(mydata)
#list2.append([k,dict1[k]['name']])
x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)
print(id,dict1[k]['name'],x.text)
x.close()
#print(mydata)
15010721720 吕毅夫 {"errmsg":"ok"}
13911532480 王若云 {"errmsg":"ok"}
15810430182 赵凤龙 {"errmsg":"ok"}
17778112523 蔡丽娟 {"errmsg":"ok"}
15910393682 吴晨晨 {"errmsg":"ok"}
13241607620 韦树鹏 {"errmsg":"ok"}
15201130595 刘均平 {"errmsg":"ok"}
18500858558 张超 {"errmsg":"ok"}
13911692169 郑文凯 {"errmsg":"ok"}
15910799757 王贝 {"errmsg":"ok"}
13911816920 王欣 {"errmsg":"ok"}
13621168106 赵颖 {"errmsg":"ok"}
13683643617 周娟 {"errmsg":"ok"}
15010369810 黄俊平 {"errmsg":"ok"}
13810927023 高丽 {"errmsg":"ok"}
15210546702 杨海燕 {"errmsg":"ok"}
15010601650 于永华 {"errmsg":"ok"}
15910799750 韩骐 {"errmsg":"ok"}
13784086161 霍莉媛 {"errmsg":"ok"}
15810404851 王建斌 {"errmsg":"ok"}
15810830119 奚晓亮 {"errmsg":"ok"}
13651123781 马海涛 {"errmsg":"ok"}
13651357627 高桂所 {"errmsg":"ok"}
13718793001 乔金梅 {"errmsg":"ok"}
In [ ]:
import json
filename = 'data/result_政法委new.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
#items = ['身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
items = {}
items['lung'] = '肺活量'
items['grip'] ='握力'
items['flexion'] ='坐位体前屈'
items['jump'] ='纵跳'
items['pushup'] ='俯卧撑'
items['balance'] ='单脚站立'
items['reaction'] ='选择反应时'
items['step'] ='台阶指数'
items['situp'] ='一分钟仰卧起坐'
items['bmi'] ='BMI'
list1 = []
list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']
i=1
list2 = []
dict2 = {}
for k, v in dict1.items():
list1 = []
mydata = {}
id = str(k).rjust(3,"0")
mydata['unit'] = v['unit']
mydata['name'] = v['name']
mydata['sex'] = v['sex']
mydata['month'] = v['month']
age = int(v['month']/12)
if age <20:
mydata['age'] = 20
else:
mydata['age'] = int(v['month']/12)
mydata['fits'] = {}
score = 0
for item in list_item:
if item in v.keys():
if item in ['lung','pushup','step','situp']:
mark = v[item]['成绩'].split()[0].split('.')[0]
n+=1
else:
mark = v[item]['成绩'].split()[0]
mydata['fits'][items[item]] = {'mark':mark,'score':v[item]['score']}
score = score + v[item]['score']
#mydata['score'] = round(score/len(mydata['fits']),2)
if len(mydata['fits']) >2:
mydata['score'] = round(score/len(mydata['fits']),2)
dict2[str(k)] = mydata
filename = f'data/data_政法委.json'
with open(filename,'w') as fl:
json.dump(dict2,fl , ensure_ascii=False)
print('ok!') In [ ]:
import json
items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
filename = 'data/data_政法委.json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
for k1, v1 in dict2.items():
di = v1[0]
gao = v1[1]
i = 0
m = 0
f = 0
for k,v in dict1.items():
if int(v['score']*100) in range(di,gao+1):
dict1[k]['level'] = k1
i+=1
if v['sex'] == '男':
m = m +1
else:
f = f+1
print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')
print(len(dict1))In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,69]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
score = score+v['score']
i+=1
if v['sex'] == '男':
m = m +1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:0人,男性:{m}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人,男性:{m}人')In [ ]:
import json
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1) and v['sex'] == '男':
score = score+v['score']
i+=1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
for item in nld:
di = item[0]
gao = item[1]
i = 0
score = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1) and v['sex'] == '女':
score = score+v['score']
i+=1
if i ==0:
print(f'{di}~{gao}岁平均成绩:0分,人数:{i}人')
else:
print(f'{di}~{gao}岁平均成绩:{round(score/i,2)}分,人数:{i}人')In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
i = 1
m = 0
f = 0
score = 0
t_score = 0
for k,v in dict1.items():
if v['sex'] == '男':
m = m +1
score = score+v['score']
print(f'平均成绩:{round(score/m,4)}分,男性:{m}人')
t_score = t_score + score
score = 0
for k,v in dict1.items():
if v['sex'] == '女':
f = f +1
score = score+v['score']
print(f'平均成绩:{round(score/f,4)}分,女性:{f}人')
t_score = t_score + score
print(f'平均成绩:{round(t_score/25,4)}分,总体:25人')In [ ]:
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
for k1, v1 in dict2.items():
di = v1[0]
gao = v1[1]
i = 0
m = 0
f = 0
for k,v in dict1.items():
if int(v['score']*100) in range(di,gao+1):
dict1[k]['level'] = k1
i+=1
if v['sex'] == '男':
m = m +1
else:
f = f+1
print(f'{di}~{gao}分人数:{i}人,男性:{m}人,女性:{f}人')
#filename = 'data/result_石家庄.json'
with open(filename,'w') as fl:
json.dump(dict1, fl)
print('ok')In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
dict3 = {}
for item in nld:
di = item[0]
gao = item[1]
age = f'{di}-{gao}'
dict3.setdefault(age,{})
i = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
dict3[age].setdefault(v['level'],0)
if v['sex'] == '女':
dict3[age][v['level']] = dict3[age][v['level']]+1
for k, v in dict3.items():
print(k,v)In [ ]:
nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
with open(filename,'r') as fl:
dict1 = json.load(fl)
dict2 = {}
dict2['不合格'] = [0,255]
dict2['合格'] = [256,332]
dict2['良好'] = [333,367]
dict2['优秀'] = [368,500]
dict3 = {}
for item in nld:
di = item[0]
gao = item[1]
age = f'{di}-{gao}'
dict3.setdefault(age,{})
i = 0
m = 0
f = 0
for k,v in dict1.items():
if v['age'] in range(di,gao+1):
dict3[age].setdefault(v['level'],0)
if v['sex'] == '男':
dict3[age][v['level']] = dict3[age][v['level']]+1
for k, v in dict3.items():
print(k,v)In [ ]:
with open(filename,'r') as fl:
dict1 = json.load(fl)
items = ['BMI','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
for item in items:
score = 0
n = 0
for k, v in dict1.items():
if item in v['fits'].keys():
n = n + 1
score =score + int(v['fits'][item]['score'])
print(item,round(score/n,2),n)In [ ]: