Files
jupyter/体测单位/东营羊庙.ipynb
T
2023-04-02 12:46:21 +00:00

46 KiB

调查报告线下数据管理

羊庙人员信息导入

In [ ]:
import json

filename = 'data/羊庙测试人员信息.json'

with open(filename,'r') as fl:
    dict1 = json.load(fl) 
dict2 = {}
for k,v in dict1.items():
    for item in v:
        bh = item['avatar_id']
        del item['avatar_id']
        dict2[bh] = item
filename = 'data/羊庙人员名单.json'
with open(filename, 'w') as fl:
    json.dump(dict2, fl, ensure_ascii=False,default=str)
print('ok')

获取参加体测人员编号

In [ ]:
import json
import time
import csv

filename = '../item.json'
item = {}
unit = {}
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
for k,v in dict1.items():
    item[k] = v
re_ta = {}
dict1 = {}
list1 = []
#print("\n运动项目信息:")
filename = 'data/140.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)
list2 = []
for result in list1:
    user = int(result[2])
    if user not in list2:
        list2.append(user)
list2.sort()
print(len(list2))
print(list2)

根据风险筛选统计卡获取信息

In [ ]:
import openpyxl
import json
import time

wb = openpyxl.load_workbook('data/杨庙运动风险筛查统计表.xlsx')
sheet = wb.active
person = {}
for n in range(2, sheet.max_row+1):
    code = int(sheet.cell(n, 1).value)
    person.setdefault(code, {})
    dict1 = {}
    if sheet.cell(n, 8).value is not None:
        name = sheet.cell(n, 8).value
    else:
        name ='不详'
    dict1['name'] = name
    if sheet.cell(n, 9).value is not None:
        dict1['birth'] = str(sheet.cell(n, 9).value).split(' ')[0]
    if sheet.cell(n, 10).value is not None:
        dict1['phone'] = str(sheet.cell(n, 10).value)
    if sheet.cell(n,11).value is not None:
        dict1['id_num'] = sheet.cell(n,11).value
    person[code] = dict1
print(len(person))
filename = 'data/杨庙运动风险筛查统计表信息.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False,default=str)
print('ok')

根据恢复版获取信息

In [ ]:
import openpyxl
import json
import time

wb = openpyxl.load_workbook('data/羊庙恢复版.xlsx')
sheet = wb.active
person = {}
for n in range(2, sheet.max_row+1):
    if sheet.cell(n, 4).value is not None:        
        code = int(sheet.cell(n, 4).value)
        person.setdefault(code, {})
        dict1 = {}
        name = sheet.cell(n, 5).value
        dict1['name'] = name
        dict1['bh'] = n - 1
        dict1['sex'] = sheet.cell(n, 6).value
        if sheet.cell(n, 9).value is not None:
            dict1['phone'] = str(sheet.cell(n, 9).value)
        if sheet.cell(n,8).value is not None:
            dict1['id_num'] = sheet.cell(n,8).value
        if sheet.cell(n,3).value is not None:
            dict1['unit'] = sheet.cell(n,3).value
        person[code] = dict1
print(len(person))
filename = 'data/杨庙恢复版信息.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False,default=str)
print('ok')

风险筛选统计卡可用人员信息

In [ ]:
re_ta = {}
dict1 = {}
list1 = []
#print("\n运动项目信息:")
filename = 'data/140.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)
list2 = []
for result in list1:
    user = int(result[2])
    if user not in list2:
        list2.append(user)
list2.sort()
set1 = set()
filename = 'data/杨庙恢复版信息.json'
with open(filename,'r') as fl:
    dict_base = json.load(fl)
for k, v in dict_base.items():
    set1.add(int(k))
filename = 'data/杨庙运动风险筛查统计表信息.json'

with open(filename,'r') as fl:
    dict1 = json.load(fl)
list_fx = []

for k,v in dict1.items():
    
    if int(k) in list2 and k not in dict_base.keys() and v['name'] != '不详':        
        set1.add(int(k))
#print(len(list_fx))
#print(len(set1)) 
for item in list2:
    if item not in set1:
        print(item)

补充恢复版信息

In [ ]:
filename = 'data/杨庙恢复版信息.json'
with open(filename,'r') as fl:
    dict_base = json.load(fl)
for k, v in dict_base.items():
    set1.add(int(k))
filename = 'data/杨庙运动风险筛查统计表信息.json'

with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k,v in dict_base.items():
    if k in dict1.keys() and 'phone' not in v.keys() and 'phone' in dict1[k].keys():
        #print(k,v['name'])
        dict_base[k]['phone'] =  dict1[k]['phone']

for k, v in dict1.items():
    if int(k) in list2 and k not in dict_base.keys():
        dict_base[k] = v
        
print(len(dict_base))
#print(dict_base)
filename = 'data/羊庙人员名单.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)
i = 1
for k, v in dict_base.items():
    if 'bh' not in v.keys():
        name = v['name']
        n = 0
        for k1,v1 in dict2.items():
            if name == v1['name']:
                bh = k1
                n = n+1
        if n ==1:
            dict_base[k]['bh'] = bh
        else:
            print(i,k,v['name'])
            i+=1
filename = 'data/杨庙补充汇总信息.json'
with open(filename, 'w') as fl:
    json.dump(dict_base, fl, ensure_ascii=False,default=str)
print('ok')

导出汇总信息

In [ ]:
filename = 'data/杨庙补充汇总信息.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
list_item = ['name','bh','sex','phone','unit','id_num']
list_data = []

for k, v in dict1.items():
    list_mx = []
    list_mx.append(k)
    for item in list_item:
        if item in v.keys():
            list_mx.append(v[item])
        else:
            list_mx.append('')
    list_data.append(list_mx)
#print(list_data)     
filename = 'data/羊庙汇总情况表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list_data:
    sheet.append(row)
    
wb.save(filename) 
print('ok!')

成年问卷导入

In [ ]:
import openpyxl
import json

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)
wb = openpyxl.load_workbook('data/羊庙问卷统计表(成年组).xlsx')
sheet = wb.active
# sheets = wb.sheetnames

dict1 = {}
no_xinli = [108,389,268,270]
sheet = wb.active
data1 =list(sheet.values)
list_bh = data1[0][1:]
del data1[0]
print(len(list_bh))
for i in range(1,len(list_bh)+1):
    list2 = []
    
    for item in data1:
        list2.append(item[i])
    dict1[list_bh[i-1]] = list2
for k, v in dict1.items():
    #if 0 in v:
    #    print(k)
    if str(k) not in dict2.keys():
        print(k,'不在清理名单中')

#print(dict1)

成年问卷导出

In [ ]:
import openpyxl
import json

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict3 = json.load(fl)
wb = openpyxl.load_workbook('data/羊庙问卷统计表(成年组).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}
list_bh = []
no_xinli = [108,389,268,270]
zy = [2,7,9,11,12,21,24]
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)
s = ''
for k,v in dict1.items():
    if str(k) in dict3.keys(): 
        if dict3[str(k)]['sex'] ==1:
            sex = "m"
        else:
            sex = "f"
        dict2 = {}
        list_mx = []
        list_mx.append(f'"Gender":"{sex}"')
        list_mx.append(f'"Age":"M"')
        dict2['surveyId'] = "merge1"
        dict2['name'] = dict3[str(k)]['name'] 
        name = dict3[str(k)]['name'] 
        dict2['code'] = str(k)
        ss = ''
        
        if k not in no_xinli:
            for i in range(0,47):
                list_mx.append(f'"q{i+1}M":{v[i]}')        
        
        for i in range(1,61):
            if i not in zy:
                list_mx.append(f'"q{i}":{v[46+i]}')
        for i in range(1,27):
            list_mx.append(f'"qv{i}":{v[106+i]}')
        ss = ','.join(list_mx)
        ss ='{'+ss+'}'
        dict2['data'] = ss
        sj = '2023-03-28 20:02:00'
        s= s+f'("merge1","{name}","{str(k)}",\'{ss}\',"{sj}"),'
        #print(dict2)
print(s)

老年问卷导入

In [ ]:
import openpyxl
import json

filename = 'data/杨庙体测明确人员信息(20230328).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 = {}
no_xinli = [286]
sheet = wb.active
data1 =list(sheet.values)
list_bh = data1[0][1:]
print(list_bh)
del data1[0]
print(len(list_bh))
for i in range(1,len(list_bh)+1):
    list2 = []
    
    for item in data1:
        list2.append(item[i])
    dict1[list_bh[i-1]] = list2
for k, v in dict1.items():
    #if 0 in v or ' ' in v:
    #    print(k)
    if str(k) not in dict2.keys():
        print(k,'不在清理名单中')
#print(dict1)

老年问卷导出

In [ ]:
import openpyxl
import json

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict3 = json.load(fl)
wb = openpyxl.load_workbook('data/羊庙问卷统计表(老年组).xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}

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'] ==1:
            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-03-28 20:02:00'
        s= s+f'("merge1","{name}","{str(k)}",\'{ss}\',"{sj}"),'
        #print(dict2)
print(s)

统计网络问卷信息

In [ ]:
filename = 'data/merge1.json'

with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)
filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)
dict3 = {}
for k, v in dict1.items():
    print(len(v))
    for item in v:
        phone = item['phone']
        dict3.setdefault(phone,{})
        #dict3[phone]['data'] = v['data']
        for k1,v1 in dict2.items():
            if 'phone' in v1.keys() and phone == v1['phone']:
                dict3[phone]['bh'] = k1
print(dict3)
for k, v in dict2.items():
    for k1, v1 in dict2.items():
        
    if 'bh' not in v.keys():
        print(k)

按照测试编号管理

导入测试人员信息表(符合条件)

In [ ]:
import openpyxl
import json
import time

wb = openpyxl.load_workbook('data/杨庙体测明确人员信息表(20230328).xlsx')
sheet = wb.active
person = {}
for n in range(2, sheet.max_row+1):
    code = int(sheet.cell(n, 1).value)
    person.setdefault(code, {})
    dict1 = {}
    name = sheet.cell(n, 2).value   
    dict1['name'] = name
    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['phone'] = str(sheet.cell(n, 5).value)
    if sheet.cell(n,6).value is not None:
        dict1['unit'] = sheet.cell(n,6).value    
    person[code] = dict1
filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False,default=str)
print('ok')

体测报告更名按部门分组

In [ ]:
import os,sys,shutil
import json
import math

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
old = []
depart = []
for k, v in dict1.items():
    m_depart = v['unit']
    if m_depart not in depart:
        depart.append(m_depart)
        
fi_path = '/data/pdf/ydyb/140/2023-03-29'


# 创建部门办公室    
m_path = 'file/140'
for pn in depart:
    if not os.path.exists(m_path + '/' + pn):
        os.mkdir(m_path + '/' + pn)
fl=os.listdir(fi_path)
for fn in fl:
    if os.path.isfile(fi_path + '/' + fn):
        ofn = int(fn.split('.')[0])
        old.append(ofn) 
old.sort()
for n in old:    
    o_name = f'{fi_path}/{n}.pdf'
    unit = dict1[str(n)]['unit']
    name = dict1[str(n)]['name']
    n_name = f'{m_path}/{unit}/{str(n).rjust(5,"0")}-{name}.pdf'
    #print(o_name,n_name)
    if not os.path.exists(n_name):
        shutil.copyfile(o_name,n_name)
        print(n_name)

生成体检报告情况表

In [ ]:
import os,sys,shutil
import openpyxl
import json

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
old = []
depart = []
for k, v in dict1.items():
    m_depart = v['unit']
    if m_depart not in depart:
        depart.append(m_depart)
        
fi_path = '/data/pdf/ydyb/140/2023-03-29'
fl=os.listdir(fi_path)
for fn in fl:
    if os.path.isfile(fi_path + '/' + fn):
        ofn = int(fn.split('.')[0])
        old.append(ofn) 
old.sort()
list1 = []
for n in old:
    list2 =[]
    unit = dict1[str(n)]['unit']
    name = dict1[str(n)]['name']
    list2 = [str(n).rjust(5,"0"),name,unit]
    list1.append(list2)

filename = 'data/杨庙体测报告明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
title = ['体测编号','姓名','单位']
sheet.append(title)
for row in list1:
    sheet.append(row)
    
wb.save(filename) 
print('ok!')

生成脊柱问卷信息表

In [ ]:
import json
import pymysql
import openpyxl

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)
xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']
title = ['编号','姓名','性别']
for item in xm:
    title.append(item)
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = 'SELECT a.phone ,a.name,a.code,a.data  FROM Survey as a WHERE a.surveyId ="merge1"'
cursor.execute(sql)
results = cursor.fetchall()
list2 =[]
for result in results:    
    c=json.loads(result[3])
    if result[2] is None:
        phone = result[0]
        for k,v in dict1.items():
            if 'phone' in v.keys() and phone ==v['phone']:
                list1 = []
                code = k
                name = v['name']
                list1.append(code)
                list1.append(name)
                list1.append(v['sex'])
                for item in xm:
                    if item in c.keys():
                        list1.append(c[item])
                    else:
                        list1.append('')
                list2.append(list1)
    else:
        list1 = []
        code = result[2]
        name = result[1]
        list1.append(code)
        list1.append(name)
        list1.append(v['sex'])
        for item in xm:
            if item in c.keys():
                list1.append(c[item])
            else:
                list1.append('')   
        list2.append(list1)
filename = 'data/杨庙脊柱问卷明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
sheet.append(title)
for row in list2:
    sheet.append(row)
    
wb.save(filename) 
print('ok!')      
In [ ]:
import json
import pymysql

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)
xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = 'SELECT a.phone ,a.name,a.code,a.data  FROM Survey as a WHERE a.surveyId ="merge1"'
cursor.execute(sql)
results = cursor.fetchall()
for result in results:
    c=json.loads(result[3])
    print(c, type(c))

查询中年组心理测评人员

In [ ]:
import json
import pymysql

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)
xm = ['qv1','qv2','qv3','qv4','qv5','qv6','qv7','qv8','qv9','qv10','qv11','qv12','qv13','qv14','qv15','qv16','qv17','qv18','qv19','qv20','qv21','qv22','qv23','qv24','qv25','qv26']
db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = 'SELECT a.phone ,a.name,a.code,a.data  FROM Survey as a WHERE a.surveyId ="merge1"'
cursor.execute(sql)
results = cursor.fetchall()
list2 =[]
for result in results:
    c=json.loads(result[3])
    if 'q1M' in c.keys():
        if result[2] is None:
            phone = result[0]
            for k,v in dict1.items():
                if 'phone' in v.keys() and phone ==v['phone']:
                    list1 = []
                    code = k
                    name = v['name']
                    list1.append(code)
                    list1.append(name)
                    list1.append(v['sex'])
                    list1.append(v['birth'])
                    list1.append(v['unit'])
                    list2.append(list1)
        else:
            list1 = []
            code = result[2]
            name = result[1]
            list1.append(code)
            list1.append(name)
            list1.append(dict1[code]['sex'])
            list1.append(dict1[code]['birth'])
            list1.append(dict1[code]['unit'])
            
            list2.append(list1)
filename = 'data/杨庙心理问卷成年组人员明细表.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active
#sheet.append(title)
for row in list2:
    sheet.append(row)
    
wb.save(filename) 
print('ok!')      

成年人心理问卷体测报告更名按部门分组

In [ ]:
import os,sys,shutil
import json
import math

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
old = []
depart = []
wb = openpyxl.load_workbook('data/杨庙心理问卷成年组人员明细表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames

list_bh = []

for n in range(1,sheet.max_row+1):
    list_bh.append(int(sheet.cell(n, 1).value))    
    m_depart = sheet.cell(n, 5).value
    if m_depart not in depart:
        depart.append(m_depart)
        
fi_path = '/data/pdf/ydyb/140/2023-04-01'


# 创建部门办公室    
m_path = 'file/140wenjuan'
for pn in depart:
    if not os.path.exists(m_path + '/' + pn):
        os.mkdir(m_path + '/' + pn)
fl=os.listdir(fi_path)
for fn in fl:
    if os.path.isfile(fi_path + '/' + fn):
        ofn = int(fn.split('.')[0])
        if ofn in list_bh:
            old.append(ofn) 
old.sort()
for n in old:    
    o_name = f'{fi_path}/{n}.pdf'
    unit = dict1[str(n)]['unit']
    name = dict1[str(n)]['name']
    n_name = f'{m_path}/{unit}/{str(n).rjust(5,"0")}-{name}.pdf'
    #print(o_name,n_name)
    if not os.path.exists(n_name):
        shutil.copyfile(o_name,n_name)
        print(n_name)

杨庙社区处方分组

人员分组

高血压人员

In [60]:
import os,sys,shutil
import json
import math

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

wb = openpyxl.load_workbook('data/杨庙运动风险筛查统计表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames

list_gxy = []

for n in range(2,sheet.max_row+1):
    code = sheet.cell(n, 1).value
    if sheet.cell(n, 3).value is not None:
        code = sheet.cell(n, 1).value
        gxy = sheet.cell(n, 3).value
        if str(code) in dict1.keys() and int(gxy) ==1:
            list_gxy.append(str(code))
print(list_gxy)
['437', '422', '417', '416', '415', '403', '399', '397', '393', '392', '389', '387', '382', '377', '376', '371', '365', '364', '362', '361', '357', '355', '353', '351', '349', '346', '345', '344', '340', '335', '333', '332', '330', '329', '328', '326', '323', '322', '317', '315', '314', '309', '306', '305', '294', '293', '291', '282', '281', '279', '278', '277', '276', '274', '273', '272', '271', '270', '265', '264', '262', '261', '259', '258', '256', '239', '236', '223', '221', '219', '214', '213', '212', '209', '208', '191', '188', '187', '186', '183', '179', '174', '172', '168', '167', '166', '164', '162', '160', '157', '156', '140', '139', '138', '137', '136', '135', '127', '124', '123', '122', '121', '116', '115', '111', '110', '106', '103', '100', '98', '97', '96', '95', '94', '89', '76', '74', '73', '58', '53', '52', '46', '42', '41', '40', '39', '35', '34', '30', '28', '26', '25', '23', '16', '13', '12', '11', '8', '6', '5']

失眠人员

In [55]:
import json
import pymysql

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)

db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = 'SELECT a.phone ,a.name,a.code,a.data  FROM Survey as a WHERE a.surveyId ="merge1"'
cursor.execute(sql)
results = cursor.fetchall()
list_sm =[]
for result in results:
    c=json.loads(result[3])
    if 'qv7' in c.keys() and c['qv7'] ==1:
        if result[2] is None:
            phone = result[0]
            for k,v in dict1.items():
                if 'phone' in v.keys() and phone ==v['phone']:
                    list_sm.append(k) 
        else:
            list_sm.append(result[2])
print(list_sm)
['134', '147', '177', '181', '185', '193', '200', '201', '208', '213', '251', '263', '292', '320', '347', '358', '374', '383', '410', '435', '434', '437', '433', '155', '113', '108', '97', '92', '245', '71', '70', '69', '65', '64', '60', '58', '54', '32', '180', '217', '411', '414', '370', '381', '389', '270', '278', '192', '190', '196', '17', '13', '12', '11', '5', '4', '436', '121', '122', '124', '133', '137', '138', '141', '142', '143', '150', '157', '158', '160', '167', '115', '114', '111', '103', '96', '94', '93', '89', '87', '85', '83', '79', '77', '233', '234', '236', '74', '73', '59', '55', '53', '52', '49', '48', '47', '43', '42', '35', '34', '26', '23', '172', '171', '175', '186', '289', '290', '294', '310', '309', '316', '199', '202', '207', '209', '210', '211', '219', '222', '223', '229', '415', '6002', '346', '349', '357', '362', '363', '365', '369', '371', '373', '379', '376', '372', '378', '393', '400', '314', '324', '323', '328', '330', '332', '334', '343', '259', '267', '271', '273', '277', '276', '282', '345']

脊柱调理人员

In [69]:
import json
import pymysql

filename = 'data/杨庙体测明确人员信息(20230328).json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
#print(dict1)

db = pymysql.connect(host = "localhost",user = "songyi",password = "yylzs",database = "ydyb" )
cursor = db.cursor()
sql = 'SELECT a.phone ,a.name,a.code,a.data  FROM Survey as a WHERE a.surveyId ="merge1"'
cursor.execute(sql)
results = cursor.fetchall()
list_jz =[]
for result in results:
    c=json.loads(result[3])
    if ('qv1' in c.keys() and c['qv1'] ==1) or ('qv18' in c.keys() and c['qv18'] ==1):
        if result[2] is None:
            phone = result[0]
            for k,v in dict1.items():
                if 'phone' in v.keys() and phone ==v['phone']:
                    list_jz.append(k) 
        else:
            list_jz.append(result[2])
print(list_jz)
['107', '127', '134', '147', '146', '161', '177', '181', '185', '193', '200', '201', '208', '213', '251', '263', '292', '295', '313', '319', '320', '98765', '342', '360', '358', '359', '374', '6000', '6003', '423', '435', '434', '155', '156', '113', '108', '104', '245', '253', '71', '70', '69', '66', '65', '64', '63', '61', '58', '54', '46', '45', '32', '174', '180', '404', '411', '414', '427', '361', '381', '268', '266', '270', '417', '303', '192', '190', '194', '195', '196', '17', '16', '13', '12', '11', '9', '8', '7', '6', '5', '4', '436', '121', '122', '124', '123', '130', '126', '133', '136', '135', '137', '139', '140', '142', '143', '144', '151', '150', '157', '158', '159', '160', '166', '118', '117', '116', '115', '111', '110', '109', '103', '101', '98', '96', '95', '94', '89', '88', '87', '86', '83', '82', '80', '79', '77', '231', '237', '233', '234', '239', '236', '243', '244', '242', '256', '257', '258', '164', '163', '74', '75', '67', '59', '57', '56', '53', '52', '49', '48', '47', '43', '41', '40', '37', '36', '35', '34', '33', '31', '30', '26', '25', '24', '23', '172', '171', '175', '179', '183', '186', '187', '188', '289', '290', '293', '294', '296', '305', '308', '310', '309', '316', '203', '199', '202', '207', '214', '211', '219', '221', '222', '223', '229', '401', '399', '403', '406', '415', '6002', '430', '346', '349', '348', '353', '357', '355', '351', '362', '364', '365', '369', '368', '371', '373', '377', '379', '376', '372', '378', '382', '386', '393', '392', '396', '400', '314', '318', '323', '322', '326', '325', '328', '331', '330', '332', '334', '335', '337', '333', '344', '259', '262', '264', '260', '265', '267', '272', '271', '273', '275', '277', '276', '281', '283', '282', '286', '345']
In [70]:
dict2 = {}
dict2.setdefault('高血压',[])
dict2['高血压'] = list_gxy
dict2.setdefault('失眠',[])
for item in list_sm:
    if item not in list_gxy:
        dict2['失眠'].append(item)

dict2.setdefault('脊柱调理',[])
for item in list_jz:
    if item not in list_gxy and item not in list_sm:
        dict2['脊柱调理'].append(item)

list_other = []
for item in dict1.keys():
    if item not in list_gxy and item not in list_sm and item not in list_jz:
        list_other.append(item)
dict2['整体调理'] = list_other
print(dict2)
list1 = []
for k, v in dict2.items():
    for item in v:
        list2 = [k,item,dict1[item]['name'],dict1[item]['sex'],dict1[item]['birth'],dict1[item]['unit']]
        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!')      
        
{'高血压': ['437', '422', '417', '416', '415', '403', '399', '397', '393', '392', '389', '387', '382', '377', '376', '371', '365', '364', '362', '361', '357', '355', '353', '351', '349', '346', '345', '344', '340', '335', '333', '332', '330', '329', '328', '326', '323', '322', '317', '315', '314', '309', '306', '305', '294', '293', '291', '282', '281', '279', '278', '277', '276', '274', '273', '272', '271', '270', '265', '264', '262', '261', '259', '258', '256', '239', '236', '223', '221', '219', '214', '213', '212', '209', '208', '191', '188', '187', '186', '183', '179', '174', '172', '168', '167', '166', '164', '162', '160', '157', '156', '140', '139', '138', '137', '136', '135', '127', '124', '123', '122', '121', '116', '115', '111', '110', '106', '103', '100', '98', '97', '96', '95', '94', '89', '76', '74', '73', '58', '53', '52', '46', '42', '41', '40', '39', '35', '34', '30', '28', '26', '25', '23', '16', '13', '12', '11', '8', '6', '5'], '失眠': ['134', '147', '177', '181', '185', '193', '200', '201', '251', '263', '292', '320', '347', '358', '374', '383', '410', '435', '434', '433', '155', '113', '108', '92', '245', '71', '70', '69', '65', '64', '60', '54', '32', '180', '217', '411', '414', '370', '381', '192', '190', '196', '17', '4', '436', '133', '141', '142', '143', '150', '158', '114', '93', '87', '85', '83', '79', '77', '233', '234', '59', '55', '49', '48', '47', '43', '171', '175', '289', '290', '310', '316', '199', '202', '207', '210', '211', '222', '229', '6002', '363', '369', '373', '379', '372', '378', '400', '324', '334', '343', '267'], '脊柱调理': ['107', '146', '161', '295', '313', '319', '98765', '342', '360', '359', '6000', '6003', '423', '104', '253', '66', '63', '61', '45', '404', '427', '268', '266', '303', '194', '195', '9', '7', '130', '126', '144', '151', '159', '118', '117', '109', '101', '88', '86', '82', '80', '231', '237', '243', '244', '242', '257', '163', '75', '67', '57', '56', '37', '36', '33', '31', '24', '296', '308', '203', '401', '406', '430', '348', '368', '386', '396', '318', '325', '331', '337', '260', '275', '283', '286'], '整体调理': ['2', '3', '10', '15', '18', '22', '27', '29', '38', '44', '51', '62', '68', '72', '78', '81', '84', '90', '91', '99', '105', '112', '119', '120', '128', '129', '132', '145', '148', '149', '152', '153', '154', '165', '169', '170', '173', '176', '178', '184', '189', '197', '198', '204', '205', '206', '215', '216', '218', '220', '224', '225', '227', '228', '235', '238', '240', '241', '248', '249', '250', '255', '269', '284', '285', '287', '297', '301', '302', '307', '321', '327', '336', '352', '354', '356', '375', '391', '394', '395', '402', '405', '407', '408', '412', '418', '419', '420', '421', '424', '429', '431', '432', '6001', '98776']}
ok!
In [ ]: