This commit is contained in:
512song committed 2024-01-03 22:28:08 +08:00
1 parent 996379d3cb
commit 5e368c4b76
4 files changed
+501 -320

No files matched your search

+404 -2
View File
@@ -4,6 +4,7 @@
"cell_type": "markdown",
"id": "4626da6c-d228-4270-8d8d-c98784a106ad",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": [],
"toc-hr-collapsed": true
},
@@ -493,7 +494,6 @@
"cell_type": "markdown",
"id": "59d38404-e097-4f08-a3fd-565e351f09bb",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": [],
"toc-hr-collapsed": true
},
@@ -1550,10 +1550,412 @@
" print(v['unit'],url)"
]
},
{
"cell_type": "markdown",
"id": "2112bdec-bd4e-46b7-88cb-ec53e70ad844",
"metadata": {},
"source": [
"## 报告添加水印"
]
},
{
"cell_type": "code",
"execution_count": 137,
"id": "ced8ec31-2b80-4ba1-901a-233f0c31c32c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-28T03:47:55.677670Z",
"iopub.status.busy": "2023-12-28T03:47:55.677205Z",
"iopub.status.idle": "2023-12-28T03:48:41.694191Z",
"shell.execute_reply": "2023-12-28T03:48:41.693753Z",
"shell.execute_reply.started": "2023-12-28T03:47:55.677631Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import glob\n",
"from pathlib import Path\n",
"import PyPDF2\n",
"\n",
"\n",
"pdfWriter = PyPDF2.PdfWriter() \n",
"\n",
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118_1'\n",
"new_path = 'file/309118_sy'\n",
"\n",
"filename = 'data/北京农行百日筑基.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"water = PyPDF2.PdfReader('data/气虚质.pdf').pages[0]\n",
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
"for fn in fls:\n",
" reader = PyPDF2.PdfReader(fn)\n",
" writer = PyPDF2.PdfWriter()\n",
" num = len(reader.pages)\n",
" code =str(int(Path(fn).stem.split('-')[0]))\n",
" sy_fn = 'data/'+dict1[code]['unit']+'.pdf'\n",
" water = PyPDF2.PdfReader(sy_fn).pages[0]\n",
" for i in range(num):\n",
" page = reader.pages[i]\n",
" if i == num -1:\n",
" page.merge_page(water)\n",
" writer.add_page(page)\n",
" with open(f'file/309118_sy/{Path(fn).stem}.pdf', 'wb') as target_file:\n",
" writer.write(target_file)\n",
" \n",
"print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "223fa825-da92-4667-bfc4-d359b87d3385",
"metadata": {},
"source": [
"## 核对有体测无报告人员"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "12155bbc-81c7-48c5-a6bf-228184e9382c",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-28T03:13:06.270708Z",
"iopub.status.busy": "2023-12-28T03:13:06.270214Z",
"iopub.status.idle": "2023-12-28T03:13:06.288938Z",
"shell.execute_reply": "2023-12-28T03:13:06.288393Z",
"shell.execute_reply.started": "2023-12-28T03:13:06.270668Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['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']\n"
]
}
],
"source": [
"import os,sys,shutil\n",
"import json\n",
"import glob\n",
"from pathlib import Path\n",
"import PyPDF2\n",
"\n",
"\n",
"pdfWriter = PyPDF2.PdfWriter() \n",
"\n",
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files/309118'\n",
"new_path = 'file/309118_sy'\n",
"\n",
"filename = 'data/北京农行百日筑基.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"list1 = []\n",
"fls = glob.glob(f'{fi_path}/*.pdf')\n",
"for fn in fls:\n",
" code =str(int(Path(fn).stem.split('-')[0]))\n",
" list1.append(code)\n",
"list2 = []\n",
"for k, v in dict1.items():\n",
" if k not in list1 and k!='50':\n",
" list2.append(k)\n",
"print(list2)"
]
},
{
"cell_type": "markdown",
"id": "95c57366-499f-4fa6-9504-2bb67e61d203",
"metadata": {},
"source": [
"## 补充第一次测试人员报告"
]
},
{
"cell_type": "code",
"execution_count": 133,
"id": "edfbc320-a295-4564-b1e5-9165df5fbb22",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-28T03:12:46.687698Z",
"iopub.status.busy": "2023-12-28T03:12:46.687241Z",
"iopub.status.idle": "2023-12-28T03:12:46.720241Z",
"shell.execute_reply": "2023-12-28T03:12:46.719132Z",
"shell.execute_reply.started": "2023-12-28T03:12:46.687658Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"30\n"
]
}
],
"source": [
"import json\n",
"import datetime\n",
"import csv\n",
"from datetime import date\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"item['1']['en'] = 'lung'\n",
"item['2']['en'] = 'grip'\n",
"item['3']['en'] = 'flexion'\n",
"item['4']['en'] = 'jump'\n",
"item['5']['en'] = 'pushup'\n",
"item['6']['en'] = 'balance'\n",
"item['7']['en'] = 'reaction'\n",
"item['8']['en'] = 'step'\n",
"item['9']['en'] = 'situp'\n",
"item['10']['en'] = 'height'\n",
"item['11']['en'] = 'weight'\n",
"\n",
"\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"filename = 'data/北京农行人员名单all.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20231228.csv'\n",
"with open(filename,'r',newline='') as csv_file:\n",
" fl = csv.reader(csv_file,delimiter=',')\n",
" header = next(fl) \n",
" for line in fl:\n",
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
" list1.append(line)\n",
"#f_item = ['lung','grip','flexion','jump','balance','reaction','step','situp']\n",
"#m_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
"for result in list1:\n",
" user = str(result[2])\n",
" if user in list2:\n",
" rq = date.fromisoformat(result[6].replace('/','-'))\n",
" if user in dict1.keys():\n",
" l_xm = []\n",
" m_item = str(result[3]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" re_ta[user]['sex'] = dict1[user]['sex']\n",
" if dict1[user]['sex'] == '男':\n",
" l_xm = ['weight','height','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
" else:\n",
" l_xm = ['weight','height','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
" re_ta[user]['unit'] = dict1[user]['unit']\n",
" birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n",
" #nian = int(birth[0].strip())\n",
" #yue = int(birth[1].strip())\n",
" #ri = int(birth[2].strip())\n",
" #print(k,nian,yue,ri)\n",
" item_name = item[m_item]['en'] \n",
" if item_name in l_xm: \n",
" days = (rq-birth).days \n",
" re_ta[user]['age'] = int(days/365)\n",
" re_ta[user]['month'] = int(days/365*12)\n",
" re_ta[user]['rq'] = result[6]\n",
"\n",
"\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = int(result[4])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" #print(len(re_ta))\n",
"filename = 'data/result_北京农行补充人员.json'\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl, ensure_ascii=False) \n",
"print(len(re_ta))"
]
},
{
"cell_type": "code",
"execution_count": 135,
"id": "8e578850-ea32-45e4-a78f-646c2a7aee1d",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-28T03:20:49.080841Z",
"iopub.status.busy": "2023-12-28T03:20:49.080377Z",
"iopub.status.idle": "2023-12-28T03:20:59.726002Z",
"shell.execute_reply": "2023-12-28T03:20:59.724866Z",
"shell.execute_reply.started": "2023-12-28T03:20:49.080802Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"30\n"
]
}
],
"source": [
"import requests\n",
"import json\n",
"import openpyxl\n",
"\n",
"\n",
"headers = {\n",
" \"Content-Type\": \"application/json; charset=UTF-8\"\n",
" }\n",
"filename = 'data/result_北京农行补充人员.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"list1 = []\n",
"fiie_path ='./北京农行补充/'\n",
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','bmi']\n",
"i=0\n",
"list2 = []\n",
"for k, v in dict1.items():\n",
" list1 = []\n",
" mydata = {}\n",
" \n",
" id = str(k).rjust(4,\"0\")\n",
" mydata['path'] = fiie_path+id+'-'+ v['name']+'.pdf'\n",
" mydata['title'] = '中国农业银行股份有限公司'\n",
" mydata['subtitle'] = '北京市分行'\n",
" mydata['id'] = id\n",
" mydata['name'] = v['name']\n",
" if v['sex'] == '男':\n",
" mydata['gender'] = 'male'\n",
" else:\n",
" mydata['gender'] = 'female'\n",
" \n",
" mydata['month'] = v['month']\n",
" mydata['fits'] = {}\n",
" survey_list = ['tcm','psy','spine']\n",
" for item in survey_list:\n",
" if item in v.keys():\n",
" mydata.setdefault('surveys',{})\n",
" mydata['surveys'][item] = v[item]\n",
" \n",
" \n",
" #mydata['fits'] = {}\n",
" for item in list_item:\n",
" if item in v.keys():\n",
" mydata.setdefault('fits',{})\n",
" if item in ['lung','pushup','step','situp']:\n",
" mark = v[item]['成绩'].split()[0].split('.')[0]\n",
" else:\n",
" mark = v[item]['成绩'].split()[0]\n",
" mydata['fits'][item] = {'mark':mark,'score':v[item]['score']}\n",
" if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n",
" \n",
" list1.append(mydata)\n",
" list2.append([k,v['name']])\n",
" i+=1\n",
" x = requests.post('http://localhost:3003', data = json.dumps(list1), headers=headers)\n",
" #print(id,v['name'],x.text)\n",
" #print(mydata)\n",
" #x.close()\n",
"print(i)"
]
},
{
"cell_type": "markdown",
"id": "3fcb653d-8f2b-4f01-99e0-9e563631563b",
"metadata": {},
"source": [
"## 生成手机验证码"
]
},
{
"cell_type": "code",
"execution_count": 138,
"id": "2fc466e3-80cf-4357-8910-94f8548cd3a5",
"metadata": {
"execution": {
"iopub.execute_input": "2023-12-28T03:57:03.930890Z",
"iopub.status.busy": "2023-12-28T03:57:03.930680Z",
"iopub.status.idle": "2023-12-28T03:57:04.143869Z",
"shell.execute_reply": "2023-12-28T03:57:04.143389Z",
"shell.execute_reply.started": "2023-12-28T03:57:03.930868Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import openpyxl\n",
"import os,sys,shutil\n",
"import json\n",
"import math\n",
"import glob\n",
"import random\n",
"from pathlib import Path\n",
"import pymongo\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"baogao\"]\n",
"\n",
"place_id = 309118\n",
"place_code = '03'\n",
"dw_name = '中国农业银行股份有限公司北京市分行'\n",
"fi_path = '/home/songyi/python/mycrm/flask/pdf/files'\n",
"fls = glob.glob(f'{fi_path}/{str(place_id)}/*.pdf')\n",
"\n",
"code_list = []\n",
"for i in range(10): # 0~9\n",
" code_list.append(str(i))\n",
" \n",
"list1 = []\n",
"i = 0\n",
"while i < len(fls):\n",
" code = random.sample(code_list,4) #随机取4位数\n",
" code_num = ''.join(code) \n",
" if place_code+code_num not in list1:\n",
" list1.append(place_code+code_num)\n",
" i +=1\n",
"i = 0\n",
"list2= []\n",
"for fn in fls:\n",
" dict2 = {}\n",
" fi_name =Path(fn).stem.split('-')[0]\n",
" code = int(fi_name)\n",
" dxm = list1[i]\n",
" dict2 = {'place_id':place_id,'code':dxm,'fn':Path(fn).name}\n",
" list2.append(dict2)\n",
" i +=1\n",
"mycol = mydb[\"pdf\"]\n",
"x = mycol.insert_many(list2)\n",
"print('ok') \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70dbcf3b-4e6e-4462-8d55-dba314460eaf",
"id": "4be9bcbe-bfeb-450e-9863-1d49605979a3",
"metadata": {},
"outputs": [],
"source": []