Files
jupyter/体测单位/北京农行.ipynb
T
2024-01-03 22:28:08 +08:00

59 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):
    if sheet.cell(n,1).value is not None:
        code = int(sheet.cell(n, 2).value)
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 3).value
        if sheet.cell(n, 4).value ==1:
            sex = '男'
        else:
            sex = '女'
        dict1['sex'] = sex
        birth = str(sheet.cell(n, 5).value).split()[0]
        dict1['birth'] = birth
        dict1['unit'] = sheet.cell(n, 1).value
        if sheet.cell(n,10).value is not None:
            dict1['phone'] = sheet.cell(n, 10).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 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 = []
filename = 'data/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20230918.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)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        re_ta[user]['sex'] = dict1[user]['sex'] 
        re_ta[user]['unit'] = dict1[user]['unit']
        item_name = item[m_item]['name']
        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"]}'
        re_ta[user][item_name]['得分'] = result[5]
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/北京农行人员名单all.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(dict2[k]['sex'])
    list2.append(dict2[k]['unit'])
    for item in items:
        if item in v.keys():
            list2.append(v[item]['成绩'])  
            list2.append(v[item]['得分']) 
        elif item =='name':
            list2.append(v[item])
        else:
            list2.append('') 
            list2.append('')  
    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 os,sys,shutil
import json
import math
import glob
from pathlib import Path

fi_path = 'file/2023-05-23'
old = []
dict2 = {}

filename = 'data/result_北京农行.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

for k, v in dict1.items():
    m_name = v['name']
    m_depart = v['unit']    
    dict2[int(k)] = [m_name,m_depart]

fls = glob.glob(f'{fi_path}/*.pdf')

for fn in fls:
    old.append(os.path.basename(fn).split('.')[0])

for n in old:    
    o_name = f'{fi_path}/{n}.pdf'
    new_path = Path(fi_path,'new',dict1[n]['unit'])
    new_path.mkdir(parents = True, exist_ok = True)
    n_name = Path(new_path,f'{str(n).rjust(5,"0")}-{dict2[int(n)][0]}.pdf')
    if not os.path.exists(n_name):
        shutil.copyfile(o_name,n_name)
        print(n_name)
    
print('ok')

生成人员电话信息表

In [ ]:
import json
import openpyxl
wb = openpyxl.load_workbook('data/农业银行测试手机号码统计表.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}

for n in range(2, sheet.max_row+1):
    if sheet.cell(n,5).value is not None:
        phone = str(sheet.cell(n, 5).value)
        dict1.setdefault(phone,{})
        code = str(sheet.cell(n, 2).value)
        unit = sheet.cell(n, 1).value
        name = sheet.cell(n, 3).value
        sex = sheet.cell(n, 4).value
        dict1[phone]['code'] = code
        dict1[phone]['name'] = name
        #dict1[phone]['unit'] = unit
        #dict1[phone]['sex'] = sex
filename = 'data/农业银行测试手机号码.json'

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False) 
print(len(dict1))

生成验证码

In [ ]:
import random
import json

code_list = []
for i in range(10):   # 0~9
    code_list.append(str(i))
    
list1 = []
#print(code_num)
i = 1
while i < 165:
    code = random.sample(code_list,6)   #随机取6位数
    code_num = ''.join(code)
    if code_num not in list1:
        list1.append(code_num)
        i +=1
print(len(list1))
print(list1)
i = 0
filename = 'data/农业银行测试手机号码.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    dict1[k]['yzm'] = list1[i]
    i +=1
with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False)     

生成下载链接

In [ ]:
filename = 'data/农业银行测试手机号码.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
dict2 = {}
for k, v in dict1.items():
    dict2.setdefault(v['yzm'],{})
    dict2[v['yzm']]['code'] = v['code']
    dict2[v['yzm']]['name'] = v['name']
print(len(dict2))
filename = 'data/yzm.json'
with open(filename,'w') as fl:
    json.dump(dict2, fl, ensure_ascii=False)   

发送短信

In [ ]:
import json
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
try:    
    secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
    secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
    cred = credential.Credential(secretId, secretKey) 
    httpProfile = HttpProfile()
    httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
    httpProfile.reqTimeout = 30    # 请求超时时间,单位为秒(默认60秒)
    httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
    clientProfile = ClientProfile()
    clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
    clientProfile.language = "en-US"
    clientProfile.httpProfile = httpProfile
    client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
    req = models.SendSmsRequest()
    req.SmsSdkAppId = "1400140089"
    req.SignName = "坤铭教育"
    req.TemplateId = "1875765"    
    req.TemplateParamSet = ["北京石油分公司体测者","01740518"]
    req.PhoneNumberSet = ["+8613793180751"]
    req.SessionContext = ""
    req.ExtendCode = ""
    req.SenderId = ""
    resp = client.SendSms(req)
    print(resp.to_json_string(indent=2))
except TencentCloudSDKException as err:
    print(err)
In [ ]:
dict1 = json.loads(resp.to_json_string(indent=2))
print(dict1['SendStatusSet'][0]["Message"])

批量发送短信(测试)

In [ ]:

from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.sms.v20210111 import sms_client, models
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
import json

filename = 'data/短信测试手机号码.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    phone = '+86'+str(k)
    yzm = v['yzm']
    try:    
        secretId = "AKID22rVyvSqbikXFFvav31ykc9YmqjN6KYc"
        secretKey = "51XVL1YxDKI6mJh8au6DDuTskS1RhwJX"
        cred = credential.Credential(secretId, secretKey) 
        httpProfile = HttpProfile()
        httpProfile.reqMethod = "POST"  # post请求(默认为post请求)
        httpProfile.reqTimeout = 30    # 请求超时时间,单位为秒(默认60秒)
        httpProfile.endpoint = "sms.tencentcloudapi.com"  # 指定接入地域域名(默认就近接入)
        clientProfile = ClientProfile()
        clientProfile.signMethod = "TC3-HMAC-SHA256"  # 指定签名算法
        clientProfile.language = "en-US"
        clientProfile.httpProfile = httpProfile
        client = sms_client.SmsClient(cred, "ap-guangzhou", clientProfile)
        req = models.SendSmsRequest()
        req.SmsSdkAppId = "1400140089"
        req.SignName = "坤铭教育"
        req.TemplateId = "1808914"    
        req.TemplateParamSet = [yzm]
        req.PhoneNumberSet = [phone]
        req.SessionContext = ""
        req.ExtendCode = ""
        req.SenderId = ""
        #resp = client.SendSms(req)
        dict2 = json.loads(resp.to_json_string(indent=2))

        print(v['name'],dict2['SendStatusSet'][0]["Message"])
    except TencentCloudSDKException as err:
        print(v['name'],err)

第二次体测

人员信息导入

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):
    if sheet.cell(n,1).value is not None:
        code = int(sheet.cell(n, 1).value)
        person.setdefault(code, {})
        dict1 = {}
        dict1['name'] = sheet.cell(n, 3).value
        if sheet.cell(n, 4).value ==1:
            sex = '男'
        else:
            sex = '女'
        dict1['sex'] = sex
        birth = str(sheet.cell(n, 5).value).split()[0]
        dict1['birth'] = birth
        dict1['unit'] = sheet.cell(n, 2).value
        if sheet.cell(n,6).value is not None:
            dict1['phone'] = sheet.cell(n, 6).value        
        person[code] = dict1

filename = 'data/北京农行人员名单2308.json'
with open(filename, 'w') as fl:
    json.dump(person, fl, ensure_ascii=False)
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 = []
filename = 'data/北京农行人员名单2308.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20230825.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)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        re_ta[user]['sex'] = dict1[user]['sex'] 
        re_ta[user]['unit'] = dict1[user]['unit']
        item_name = item[m_item]['name']
        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_北京农行0825.json'

with open(filename,'w') as fl:
    json.dump(re_ta, fl, ensure_ascii=False) 
print(len(re_ta))
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 = []
filename = 'data/北京农行人员名单2308.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20230825.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)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        re_ta[user]['sex'] = dict1[user]['sex'] 
        re_ta[user]['unit'] = dict1[user]['unit']
        item_name = item[m_item]['name']
        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_北京农行0825.json'

with open(filename,'w') as fl:
    json.dump(re_ta, fl, ensure_ascii=False) 
print(len(re_ta))

查看项目不足人员

In [ ]:
import json
import time
import csv

filename = 'data/result_北京农行0825.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
i= 0
for k, v in dict1.items():
    if len(v.keys())< 8:
        print(k,v['name'])

导出测试人员信息

In [ ]:
import json
import openpyxl


filename = 'data/result_北京农行0825.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
list1 =[]
for k, v in dict1.items():
    list2 = []
    list2 = [k,v['name'],v['sex'],v['unit']]
    list1.append(list2)
filename = 'data/北京农行测试人员202308.xlsx'
wb = openpyxl.Workbook()
sheet = wb.active

for row in list1:
    sheet.append(row)
    
wb.save(filename)

检查性别

In [ ]:
import json


filename = 'data/result_北京农行0825.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    if v['sex'] == '男' and '一分钟仰卧起坐' in v.keys():
        print(k,'应为女性!')
    if v['sex'] == '女' and '俯卧撑' in v.keys():
        print(k,'应为男性!')

手工数据生成SQL

In [ ]:
import openpyxl
import json


wb = openpyxl.load_workbook('data/北京农行测试人员202308.xlsx')
sheet = wb.active
# sheets = wb.sheetnames
dict1 = {}

data1 =list(sheet.values)
del data1[0]
list1 = []
for item in data1:
    code = int(item[0])
    list1.append((309118,code,5,item[4],'2023-08-23','2023-08-23 22:00:00'))
print(list1)

核对问卷人员信息

In [ ]:
import json
import csv


filename = 'data/北京农行人员名单2308.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 
    
filename = 'data/Survey_20230913.csv'
with open(filename,'r',newline='') as csv_file:
    fl = csv.reader(csv_file,delimiter=',')
    header = next(fl)    
    for line in fl:
        code = str(line[4])
        name = line[3]
        
        if code not in dict1.keys() or name!= dict1[code]['name']:
            print(code,name)
        
        

合并人员信息

In [ ]:
import json

filename = 'data/北京农行人员名单2308.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 k, v in dict2.items():
    dict1[k] = v
filename = 'data/北京农行人员名单all.json'

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False) 
print(len(re_ta))

报告按部门分类

In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path

fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'
new_path = 'file/309118'
old = []
dict2 = {}

filename = 'data/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
fls = glob.glob(f'{fi_path}/*.pdf')
for fn in fls:
    fi_name =Path(fn).stem.split('-')[0]
    code = int(fi_name)
    unit_path = Path(new_path,dict1[str(code)]['unit'])
    unit_path.mkdir(parents = True, exist_ok = True)
    n_name = Path(unit_path,Path(fn).stem+'.pdf')
    if not os.path.exists(n_name):
        shutil.copyfile(fn,n_name)
        print(n_name)

生成体测报告打印明细表

In [ ]:
import os,sys,shutil
import json
import glob
from pathlib import Path
import openpyxl

fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'
new_path = 'file/309118'
list1 = []
filename = 'data/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
fls = glob.glob(f'{fi_path}/*.pdf')
for fn in fls:
    list2 = []
    fi_name =Path(fn).stem.split('-')[0]    
    code = int(fi_name)
    unit = dict1[str(code)]['unit']
    list2 = [fi_name,Path(fn).stem.split('-')[1],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')

数据分析

获取清理后数据

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
filename = 'data/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

re_ta = {}
list1 = []
#print("\n运动项目信息:")
filename = 'data/places_result_20230922-1695356859947.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)
for result in list1:
    user = str(result[2])
    if user in dict1.keys():        
        m_item = str(result[3])    
        re_ta.setdefault(user,{})    
        re_ta[user]['name'] = dict1[user]['name']
        
        re_ta[user]['sex'] = dict1[user]['sex']
        re_ta[user]['birth'] = dict1[user]['birth'].replace('-','/')
        item_name = item[m_item]['name']
        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"]}'
        re_ta[user][item_name]['得分'] =result[5]

print(len(re_ta))
liwai = []
for k, v in re_ta.items():
    if (len(v)<8 and '身高' in v and '体重' in v) or (len(v)<7 and '身高' not in v and '体重' not in v) :
        liwai.append(k)
print(liwai)
for k in liwai:
    del re_ta[k]
print(len(re_ta))
filename = 'data/result_北京农行all.json'
with open(filename,'w') as fl:
    json.dump(re_ta, fl, ensure_ascii=False) 
print('ok')
print(len(re_ta))

计算人员年龄

In [ ]:
import json
import datetime

filename = 'data/result_北京农行all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    #print(k,v)
    if '.' in v['birth']:
        birth = v['birth'].split()[0].split('.')
    else:
        birth = v['birth'].split()[0].split('/')
    
    nian = int(birth[0].strip())
    yue = int(birth[1].strip())
    ri = int(birth[2].strip())
    #print(k,nian,yue,ri)
    if int(k) < 199:
        days = (datetime.date(2023, 5, 11)-datetime.date(nian,yue,ri)).days
    else:
        days = (datetime.date(2023, 8, 24)-datetime.date(nian,yue,ri)).days
    v['age'] = int(days/365)
filename = 'data/result_北京农行all.json'
with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False) 
print('ok')    

汇总人员信息及成绩

In [ ]:
import json


items = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']

with open(filename,'r') as fl:
    dict1 = json.load(fl) 
for k,v in dict1.items():
    print(k)
    score = 0
    i = 0    
    for k1,v1 in v.items():  
        if k1 in items:
            score = score + int(v1['得分'])
            i+=1
    dict1[k]['score'] = round(score/i,2)            

with open(filename,'w') as fl:
    json.dump(dict1, fl, ensure_ascii=False) 
print('ok')

计算测试等级

In [ ]:
import 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}人')

with open(filename,'w') as fl:
    json.dump(dict1, fl) 
print('ok')

根据年龄汇总人员信息及成绩

In [ ]:
import json

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
            
    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}岁平均成绩:{round(score/i,2)}分,人数:{i}人')
    else:
        print(f'{di}~{gao}岁平均成绩:0分,人数:0人') 

根据年龄汇总人员信息及成绩(女)

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}岁平均成绩:{round(score/i,2)}分,人数:{i}人')
    else:
        print(f'{di}~{gao}岁平均成绩:0分,人数:0人') 

计算平均成绩

In [ ]:
import json

nld = [[20,24],[25,29],[30,34],[35,39],[40,44],[45,49],[50,54],[55,80]]
#filename = 'data/result_石家庄.json'
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/522,4)}分,总体:522人')

计算各年龄段测试等级(女)

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 = ['体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']
for item in items:
    score = 0
    n = 0
    for k, v in dict1.items():
        if item in v.keys():
            n = n + 1
            score =score + int(v[item]['得分'])
    print(item,round(score/n,2),n)

百日筑基

整理人员信息

In [ ]:
import json
import openpyxl

filename = 'data/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict2 = json.load(fl)
list1 = ['握力组', '平衡组', '平和质', '气虚质', '阳虚质', '阴虚质', '痰湿质', '湿热质', '血瘀质', '气郁质', '特禀质']    
wb = openpyxl.load_workbook('data/北京农行体测分组情况.xlsx')
#sheet = wb.active
#sheets = wb.sheetnames
for item in list1:
    sheet  = wb[item]
    for n in range(2, sheet.max_row+1):
        if sheet.cell(n,1).value is not None:
            code = int(sheet.cell(n, 1).value)
            person.setdefault(code, {})
            dict1 = {}
            dict1['name'] = dict2[str(code)]['name']
            dict1['phone'] = dict2[str(code)]['phone']
            dict1['unit'] = item
            name = sheet.cell(n, 2).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

item = {
    '血瘀质':'term_6547430d71970_aIWYoQ',
    '湿热质':'term_6547428956b35_BlEnpY',
    '痰湿质':'term_654742123c1bd_hPSDR4',
    '气虚质':'term_654741bc7c0fe_bf0PLC',
    '气郁质':'term_6547415695b85_5FAHbR',
    '阴虚质':'term_654740fdb2e6b_0pBU7m',
    '阳虚质':'term_654740777e521_tsKUsG',
    '特禀质':'term_65473fd157db4_FmXOE9',
    '平和质':'term_65473f50247a5_bGI0dX',
    '平衡组':'term_65473efbcc37f_dJgc2H',
    '握力组':'term_65472c788dbf6_5Hj3iw'
}
filename = 'data/北京农行百日筑基.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)
for k, v in dict1.items():
    url = 'https://appvaCALBPV5946.h5.xiaoeknow.com/p/course/camp/'+item[v['unit']]
    print(v['unit'],url)

报告添加水印

In [137]:
import os,sys,shutil
import json
import glob
from pathlib import Path
import PyPDF2


pdfWriter = PyPDF2.PdfWriter() 

fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118_1'
new_path = 'file/309118_sy'

filename = 'data/北京农行百日筑基.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

water = PyPDF2.PdfReader('data/气虚质.pdf').pages[0]
fls = glob.glob(f'{fi_path}/*.pdf')
for fn in fls:
    reader = PyPDF2.PdfReader(fn)
    writer = PyPDF2.PdfWriter()
    num = len(reader.pages)
    code =str(int(Path(fn).stem.split('-')[0]))
    sy_fn = 'data/'+dict1[code]['unit']+'.pdf'
    water = PyPDF2.PdfReader(sy_fn).pages[0]
    for i in range(num):
        page = reader.pages[i]
        if i == num -1:
            page.merge_page(water)
        writer.add_page(page)
    with open(f'file/309118_sy/{Path(fn).stem}.pdf', 'wb') as target_file:
        writer.write(target_file)
    
print('ok!')    
ok!

核对有体测无报告人员

In [134]:
import os,sys,shutil
import json
import glob
from pathlib import Path
import PyPDF2


pdfWriter = PyPDF2.PdfWriter() 

fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'
new_path = 'file/309118_sy'

filename = 'data/北京农行百日筑基.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl)

list1 = []
fls = glob.glob(f'{fi_path}/*.pdf')
for fn in fls:
    code =str(int(Path(fn).stem.split('-')[0]))
    list1.append(code)
list2 = []
for k, v in dict1.items():
    if k not in list1 and k!='50':
        list2.append(k)
print(list2)
['11', '27', '28', '29', '31', '32', '34', '42', '47', '52', '60', '64', '75', '84', '85', '87', '98', '103', '104', '105', '106', '111', '113', '114', '118', '119', '123', '137', '151', '162', '222']

补充第一次测试人员报告

In [133]:
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/北京农行人员名单all.json'
with open(filename,'r') as fl:
    dict1 = json.load(fl) 

filename = 'data/places_result_20231228.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])
    if user in list2:
        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']
            re_ta[user]['unit'] = dict1[user]['unit']
            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[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))
30
In [135]:
import requests
import json
import openpyxl


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 ='./北京农行补充/'
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'] = 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']
    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 or len(mydata['surveys']) >0:
        
        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)
30

生成手机验证码

In [138]:
import openpyxl
import os,sys,shutil
import json
import math
import glob
import random
from pathlib import Path
import pymongo

myclient = pymongo.MongoClient('mongodb://localhost:27017/')
mydb = myclient["baogao"]

place_id = 309118
place_code = '03'
dw_name = '中国农业银行股份有限公司北京市分行'
fi_path = '/home/songyi/python/mycrm/flask/pdf/files'
fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')

code_list = []
for i in range(10):   # 0~9
    code_list.append(str(i))
    
list1 = []
i = 0
while i < len(fls):
    code = random.sample(code_list,4)   #随机取4位数
    code_num = ''.join(code)    
    if place_code+code_num not in list1:
        list1.append(place_code+code_num)
        i +=1
i = 0
list2= []
for fn in fls:
    dict2 = {}
    fi_name =Path(fn).stem.split('-')[0]
    code = int(fi_name)
    dxm = list1[i]
    dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}
    list2.append(dict2)
    i +=1
mycol = mydb["pdf"]
x = mycol.insert_many(list2)
print('ok') 
ok
In [ ]: