Files
jupyter/体测单位/北京农行.ipynb
T
2023-09-19 12:52:48 +08:00

29 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)
    if not os.path.exists(n_name):
        shutil.copyfile(fn,n_name)
        print(n_name)

生成体测报告打印明细表

In [17]:
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')
ok
In [ ]: