This commit is contained in:
512song committed 2021-11-01 10:17:03 +08:00
1 parent 8b780a6e66
commit b208898522
1 file changed
+133 -43
+133 -43
View File
@@ -35,19 +35,19 @@
"\n", "\n",
"name = '中国石油化工股份有限公司安庆炼化分公司'\n", "name = '中国石油化工股份有限公司安庆炼化分公司'\n",
"short_name = '安庆炼化'\n", "short_name = '安庆炼化'\n",
"myquery = { \"name\": name}\n", "myquery = {\"name\": name}\n",
"if mycol.find_one(myquery) is None: \n", "if mycol.find_one(myquery) is None:\n",
" wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n", " wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n",
" sheet = wb.active\n", " sheet = wb.active\n",
" #sheets = wb.sheetnames\n", " # sheets = wb.sheetnames\n",
" depart = []\n", " depart = []\n",
" dict1 = {}\n", " dict1 = {}\n",
" new_code = []\n", " new_code = []\n",
" for n in range(2,sheet.max_row+1):\n", " for n in range(2, sheet.max_row+1):\n",
" m_depart = sheet.cell(n,5).value\n", " m_depart = sheet.cell(n,5).value\n",
" if m_depart not in depart:\n", " if m_depart not in depart:\n",
" depart.append(sheet.cell(n,5).value)\n", " depart.append(sheet.cell(n,5).value)\n",
" #print(sheet.cell(n,5).value)\n", " # print(sheet.cell(n,5).value)\n",
"\n", "\n",
" dict1['name'] = '中国石油化工股份有限公司安庆炼化分公司'\n", " dict1['name'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
" dict1['short_name'] = '安庆炼化'\n", " dict1['short_name'] = '安庆炼化'\n",
@@ -55,8 +55,7 @@
" mycol.insert_one(dict1)\n", " mycol.insert_one(dict1)\n",
" print('ok!')\n", " print('ok!')\n",
"else:\n", "else:\n",
" print('该单位已存在!') \n", " print('该单位已存在!')"
" "
] ]
}, },
{ {
@@ -87,16 +86,16 @@
"dict1 = {}\n", "dict1 = {}\n",
"\n", "\n",
"name = '中国石油化工股份有限公司安庆炼化分公司'\n", "name = '中国石油化工股份有限公司安庆炼化分公司'\n",
"myquery = { \"name\": name}\n", "myquery = {\"name\": name}\n",
"dict1['code'] = 120\n", "dict1['code'] = 120\n",
"dict1['unit'] = '中国石油化工股份有限公司安庆炼化分公司'\n", "dict1['unit'] = '中国石油化工股份有限公司安庆炼化分公司'\n",
"dict1['address'] = '安徽安庆'\n", "dict1['address'] = '安徽安庆'\n",
"dict1['date_begin'] ='2021-09-08'\n", "dict1['date_begin'] = '2021-09-08'\n",
"dict1['date_end'] = '2021-09-30'\n", "dict1['date_end'] = '2021-09-30'\n",
"if mycol.find_one(myquery) is None: \n", "if mycol.find_one(myquery) is None:\n",
" print('体测单位不存在!')\n", " print('体测单位不存在!')\n",
"else:\n", "else:\n",
" myquery1 = { \"code\": dict1['code']}\n", " myquery1 = {\"code\": dict1['code']}\n",
" if mycol1.find_one(myquery1) is None:\n", " if mycol1.find_one(myquery1) is None:\n",
" mycol1.insert_one(dict1)\n", " mycol1.insert_one(dict1)\n",
" print('ok!')\n", " print('ok!')\n",
@@ -132,25 +131,25 @@
"\n", "\n",
"wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n", "wb = openpyxl.load_workbook('data/中国石油化工股份有限公司安庆炼化分公司员工在职人员名单.xlsx')\n",
"sheet = wb.active\n", "sheet = wb.active\n",
"#sheets = wb.sheetnames\n", "# sheets = wb.sheetnames\n",
"list1 = []\n", "list1 = []\n",
"person = {}\n", "person = {}\n",
"new_code = []\n", "new_code = []\n",
"for n in range(2,sheet.max_row+1):\n", "for n in range(2, sheet.max_row+1):\n",
" code = sheet.cell(n,1).value\n", " code = sheet.cell(n, 1).value\n",
" person.setdefault(code,{})\n", " person.setdefault(code, {})\n",
" dict1 = {} \n", " dict1 = {}\n",
" dict1['name'] = sheet.cell(n,2).value\n", " dict1['name'] = sheet.cell(n, 2).value\n",
" dict1['sex'] = sheet.cell(n,3).value\n", " dict1['sex'] = sheet.cell(n, 3).value\n",
" dict1['unit'] = sheet.cell(n,5).value\n", " dict1['unit'] = sheet.cell(n, 5).value\n",
" if sheet.cell(n,4).value is None:\n", " if sheet.cell(n, 4).value is None:\n",
" dict1['birth'] = sheet.cell(n,6).value\n", " dict1['birth'] = sheet.cell(n, 6).value\n",
" else:\n", " else:\n",
" dict1['id_num'] = sheet.cell(n,4).value\n", " dict1['id_num'] = sheet.cell(n, 4).value\n",
" person[code] = dict1\n", " person[code] = dict1\n",
"filename = '安庆炼化人员名单.json'\n", "filename = '安庆炼化人员名单.json'\n",
"with open(filename,'w') as fl:\n", "with open(filename, 'w') as fl:\n",
" json.dump(person, fl,ensure_ascii=False) \n", " json.dump(person, fl, ensure_ascii=False)\n",
"print('ok')" "print('ok')"
] ]
}, },
@@ -199,7 +198,7 @@
" all_person = json.load(fl)\n", " all_person = json.load(fl)\n",
"with open('result.json','r') as fl1:\n", "with open('result.json','r') as fl1:\n",
" res = json.load(fl1)\n", " res = json.load(fl1)\n",
"for k,v in all_person.items():\n", "for k, v in all_person.items():\n",
" if k in exam_person:\n", " if k in exam_person:\n",
" dict2 = {}\n", " dict2 = {}\n",
" dict3 = {}\n", " dict3 = {}\n",
@@ -224,7 +223,7 @@
"x = mycol.insert_many(list1)\n", "x = mycol.insert_many(list1)\n",
"mycol1 = mydb[\"event\"]\n", "mycol1 = mydb[\"event\"]\n",
"myquery = {'code':120}\n", "myquery = {'code':120}\n",
"mycol1.update_one(myquery,{'$push':{'persons':x.inserted_ids}})\n", "mycol1.update_one(myquery, {'$push': {'persons':x.inserted_ids}})\n",
"print('ok!')" "print('ok!')"
] ]
}, },
@@ -693,7 +692,7 @@
"import os,sys\n", "import os,sys\n",
"import pymongo\n", "import pymongo\n",
"from gridfs import GridFS\n", "from gridfs import GridFS\n",
"from bson.objectid import ObjectId\n", "\n",
"\n", "\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n", "myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"tice\"]\n", "mydb = myclient[\"tice\"]\n",
@@ -704,7 +703,6 @@
"x = mycol.find_one(myquery,{s:1})\n", "x = mycol.find_one(myquery,{s:1})\n",
"if x:\n", "if x:\n",
" print(x['report'][sn])\n", " print(x['report'][sn])\n",
" \n",
"else:\n", "else:\n",
" print('no record!')\n", " print('no record!')\n",
"#print(type(x))" "#print(type(x))"
@@ -752,15 +750,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"id": "9e33d1bc-1b71-47f7-928a-16ec435449d6", "id": "9e33d1bc-1b71-47f7-928a-16ec435449d6",
"metadata": { "metadata": {
"execution": { "execution": {
"iopub.execute_input": "2021-10-26T08:21:04.983764Z", "iopub.execute_input": "2021-11-01T01:09:32.605273Z",
"iopub.status.busy": "2021-10-26T08:21:04.982673Z", "iopub.status.busy": "2021-11-01T01:09:32.604346Z",
"iopub.status.idle": "2021-10-26T08:21:09.421348Z", "iopub.status.idle": "2021-11-01T01:09:32.942228Z",
"shell.execute_reply": "2021-10-26T08:21:09.419179Z", "shell.execute_reply": "2021-11-01T01:09:32.940432Z",
"shell.execute_reply.started": "2021-10-26T08:21:04.983506Z" "shell.execute_reply.started": "2021-11-01T01:09:32.605167Z"
}, },
"tags": [] "tags": []
}, },
@@ -815,15 +813,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 13,
"id": "2475a1c3-c2e7-45d6-9685-32e28e606df5", "id": "2475a1c3-c2e7-45d6-9685-32e28e606df5",
"metadata": { "metadata": {
"execution": { "execution": {
"iopub.execute_input": "2021-10-26T13:02:51.590980Z", "iopub.execute_input": "2021-11-01T02:03:59.201350Z",
"iopub.status.busy": "2021-10-26T13:02:51.590050Z", "iopub.status.busy": "2021-11-01T02:03:59.200377Z",
"iopub.status.idle": "2021-10-26T13:02:52.262203Z", "iopub.status.idle": "2021-11-01T02:04:00.932234Z",
"shell.execute_reply": "2021-10-26T13:02:52.260218Z", "shell.execute_reply": "2021-11-01T02:04:00.930325Z",
"shell.execute_reply.started": "2021-10-26T13:02:51.590874Z" "shell.execute_reply.started": "2021-11-01T02:03:59.201245Z"
}, },
"tags": [] "tags": []
}, },
@@ -842,7 +840,7 @@
"\n", "\n",
"wb = openpyxl.load_workbook('file/北海炼化公司职工心理健康量表统计.xlsx')\n", "wb = openpyxl.load_workbook('file/北海炼化公司职工心理健康量表统计.xlsx')\n",
"sheet = wb.active\n", "sheet = wb.active\n",
"#sheets = wb.sheetnames\n", "\n",
"dict1 = {}\n", "dict1 = {}\n",
"for n in range(2,sheet.max_row+1):\n", "for n in range(2,sheet.max_row+1):\n",
" mdm = sheet.cell(n,1).value\n", " mdm = sheet.cell(n,1).value\n",
@@ -851,8 +849,8 @@
" list1 = [1,2,3,4,5,None]\n", " list1 = [1,2,3,4,5,None]\n",
" for i in range(2,42):\n", " for i in range(2,42):\n",
" #if sheet.cell(n,i).value not in list1:\n", " #if sheet.cell(n,i).value not in list1:\n",
" # print(f'error!{mdm}--{sheet.cell(n,i).value}')\n",
" dict2[i-1] = sheet.cell(n,i).value\n", " dict2[i-1] = sheet.cell(n,i).value\n",
" #print(f'error!{mdm}--{sheet.cell(n,i).value}')\n",
" dict1[mdm] = dict2\n", " dict1[mdm] = dict2\n",
"filename = '北海炼化公司职工心理健康量表统计.json'\n", "filename = '北海炼化公司职工心理健康量表统计.json'\n",
"with open(filename,'w') as fl:\n", "with open(filename,'w') as fl:\n",
@@ -860,10 +858,102 @@
"print('ok')" "print('ok')"
] ]
}, },
{
"cell_type": "markdown",
"id": "f400d470-d51e-4226-a1c4-54ac711c7f38",
"metadata": {},
"source": [
"## 查询心理健康量表编号重复"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "61887c54-66be-4158-9721-7a995daf1745",
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-01T02:03:47.177819Z",
"iopub.status.busy": "2021-11-01T02:03:47.176858Z",
"iopub.status.idle": "2021-11-01T02:03:48.719338Z",
"shell.execute_reply": "2021-11-01T02:03:48.717050Z",
"shell.execute_reply.started": "2021-11-01T02:03:47.177713Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"355-479已存在!\n",
"401-379已存在!\n",
"493-765已存在!\n"
]
}
],
"source": [
"import openpyxl\n",
"\n",
"wb = openpyxl.load_workbook('file/北海炼化公司职工心理健康量表统计.xlsx')\n",
"sheet = wb.active\n",
"list1 = []\n",
"dict1 = {}\n",
"i = 0\n",
"for n in range(2,sheet.max_row+1):\n",
" mdm = sheet.cell(n,1).value\n",
" if mdm in list1:\n",
" print(F'{i}-{mdm}已存在!')\n",
" else:\n",
" list1.append(mdm)\n",
" i = i + 1\n",
" "
]
},
{
"cell_type": "markdown",
"id": "641cc9a9-45b2-4b81-953c-75d3a27e35d5",
"metadata": {},
"source": [
"## 统计导入JSON文件记录数"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "499a41ef-1b1f-4973-b733-8c322ac1ce09",
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-01T02:03:52.339731Z",
"iopub.status.busy": "2021-11-01T02:03:52.339110Z",
"iopub.status.idle": "2021-11-01T02:03:52.366118Z",
"shell.execute_reply": "2021-11-01T02:03:52.364000Z",
"shell.execute_reply.started": "2021-11-01T02:03:52.339665Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"538\n"
]
}
],
"source": [
"import json\n",
"filename = '北海炼化公司职工心理健康量表统计.json'\n",
"item = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"print(len(dict1))"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "671d6afe-5ed2-404e-bd8c-df3118ea3743", "id": "8ddd87ea-75f9-4296-8334-c28e6359fedd",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []