1025 lines
29 KiB
Plaintext
1025 lines
29 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "19280f5c-8e34-4a64-8dfb-6353cbf597d2",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 体质检测数据处理"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "112d80f4-607b-41f9-bb30-ac2eb8f52ee2",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 基础数据管理"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b7dfd50f-a614-497d-8f0a-fa1e4c89168a",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 体测项目标准导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "8cd73044-56a8-409b-a873-085feb63af17",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\n",
|
|
"tcbz ={\n",
|
|
" 'HeightWeigh':'身高体重',\n",
|
|
" 'StepExperiment':'台阶指数',\n",
|
|
" 'Lung':'肺活量',\n",
|
|
" 'Proneness':'坐位体前屈',\n",
|
|
" 'PowerfullGrip':'握力',\n",
|
|
" 'OneMinutePushUp':'一分钟仰卧起坐',\n",
|
|
" 'PushUp':'俯卧撑',\n",
|
|
" 'VerticalJump':'纵跳',\n",
|
|
" 'ReactionTime':'选择反应时',\n",
|
|
" 'FootStand':'单脚站立'\n",
|
|
"}\n",
|
|
"wb = openpyxl.load_workbook('data/体质检测标准.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"dict1 = {}\n",
|
|
"dict3 = {}\n",
|
|
"for k, v in tcbz.items():\n",
|
|
" dict3[v] = k\n",
|
|
"sheet = wb.active\n",
|
|
"data1 =list(sheet.values)\n",
|
|
"del data1[0]\n",
|
|
"for item in data1:\n",
|
|
" sex = item[0][6:]\n",
|
|
" if sex =='男':\n",
|
|
" age_sex = 'M'+item[0][:5]\n",
|
|
" else:\n",
|
|
" age_sex = 'F'+item[0][:5]\n",
|
|
" dict1.setdefault(age_sex,{})\n",
|
|
" if item[1] in dict3.keys():\n",
|
|
" xm = dict3[item[1]]\n",
|
|
" dict1[age_sex].setdefault(xm,[])\n",
|
|
" dict1[age_sex][xm].append(item[3]/item[4])\n",
|
|
"dict2 = {}\n",
|
|
"#print(dict1)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" i1 = int(k[1:3])\n",
|
|
" i2 = int(k[-2:])\n",
|
|
" m_sex = k[:1]\n",
|
|
" for i in range(i1,i2+1):\n",
|
|
" dict2[m_sex+str(i)] = k\n",
|
|
"dict3 = {}\n",
|
|
"dict3['person'] = dict2\n",
|
|
"dict3['criteria'] = dict1\n",
|
|
"filename = 'data/体质检测标准.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(dict3, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c36641d8-c54b-43d2-ad9d-ff4cb72deba9",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 身高标准导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2ca52d7b-d77e-452f-98f6-95072a5a1934",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import openpyxl\n",
|
|
"import json\n",
|
|
"\n",
|
|
"tcbz ={\n",
|
|
" 'HeightWeigh':'身高体重',\n",
|
|
" 'StepExperiment':'台阶指数',\n",
|
|
" 'Lung':'肺活量',\n",
|
|
" 'Proneness':'坐位体前屈',\n",
|
|
" 'PowerfullGrip':'握力',\n",
|
|
" 'OneMinutePushUp':'一分钟仰卧起坐',\n",
|
|
" 'PushUp':'俯卧撑',\n",
|
|
" 'VerticalJump':'纵跳',\n",
|
|
" 'ReactionTime':'选择反应时',\n",
|
|
" 'FootStand':'单脚站立'\n",
|
|
"}\n",
|
|
"wb = openpyxl.load_workbook('data/体质检测标准_BMI.xlsx')\n",
|
|
"sheet = wb.active\n",
|
|
"# sheets = wb.sheetnames\n",
|
|
"dict1 = {}\n",
|
|
"dict3 = {}\n",
|
|
"for k, v in tcbz.items():\n",
|
|
" dict3[v] = k\n",
|
|
"sheet = wb.active\n",
|
|
"data1 =list(sheet.values)\n",
|
|
"del data1[0]\n",
|
|
"for item in data1:\n",
|
|
" min_age = int(item[1]/12)\n",
|
|
" max_age = int((item[2]+1)/12) - 1\n",
|
|
" sex = item[0]\n",
|
|
" height = int(item[3])\n",
|
|
" if sex ==0:\n",
|
|
" age_sex = 'M'+str(min_age)+'~'+str(max_age)\n",
|
|
" else:\n",
|
|
" age_sex = 'F'+str(min_age)+'~'+str(max_age)\n",
|
|
" dict1.setdefault(age_sex,{})\n",
|
|
" \n",
|
|
" dict1[age_sex].setdefault(height,[])\n",
|
|
" dict1[age_sex][height].append(item[5]/1000)\n",
|
|
"dict2 = {}\n",
|
|
"#print(dict1)\n",
|
|
"for k, v in dict1.items():\n",
|
|
" i1 = int(k[1:3])\n",
|
|
" i2 = int(k[-2:])\n",
|
|
" m_sex = k[:1]\n",
|
|
" for i in range(i1,i2+1):\n",
|
|
" dict2[m_sex+str(i)] = k\n",
|
|
"dict3 = {}\n",
|
|
"dict3['person'] = dict2\n",
|
|
"dict3['criteria'] = dict1\n",
|
|
"filename = 'data/体质检测标准_BMI.json'\n",
|
|
"with open(filename, 'w') as fl:\n",
|
|
" json.dump(dict3, fl, ensure_ascii=False)\n",
|
|
"print('ok')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "59f5708d-c2d0-4470-b2f4-b9face431865",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算分数"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"id": "f32b266a-7e46-4703-ab61-7cbbc81b5ab1",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-06-09T03:17:48.044584Z",
|
|
"iopub.status.busy": "2023-06-09T03:17:48.044175Z",
|
|
"iopub.status.idle": "2023-06-09T03:17:48.054183Z",
|
|
"shell.execute_reply": "2023-06-09T03:17:48.053116Z",
|
|
"shell.execute_reply.started": "2023-06-09T03:17:48.044557Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[41.3, 46.2, 52.3, 58.8, 68.2]\n",
|
|
"46.2\n",
|
|
"1\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"filename = 'data/体质检测标准.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"person = dict1['person']\n",
|
|
"criteria = dict1['criteria']\n",
|
|
"data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46}\n",
|
|
"info = data['sex']+str(data['age'])\n",
|
|
"bz = person[info]\n",
|
|
"mx = criteria[bz][data['item']]\n",
|
|
"result = data['result']\n",
|
|
"score = -1\n",
|
|
"print(mx)\n",
|
|
"for bz1 in mx:\n",
|
|
" if result < bz1:\n",
|
|
" print(bz1)\n",
|
|
" score = mx.index(bz1,0)\n",
|
|
" break\n",
|
|
" else:\n",
|
|
" score = 5\n",
|
|
"#if score == -1:\n",
|
|
" # score = 5\n",
|
|
"print(score)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "755f8b66-c71c-4138-bd12-dff24e85e36a",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 计算BMI分数"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"id": "b32fbbdd-eb0a-4f0d-8901-e39a727c3ff8",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-06-09T03:07:07.558861Z",
|
|
"iopub.status.busy": "2023-06-09T03:07:07.557966Z",
|
|
"iopub.status.idle": "2023-06-09T03:07:07.572751Z",
|
|
"shell.execute_reply": "2023-06-09T03:07:07.571714Z",
|
|
"shell.execute_reply.started": "2023-06-09T03:07:07.558820Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"M30~39\n",
|
|
"177.7,97.0\n",
|
|
"1\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"filename = 'data/体质检测标准_BMI.json'\n",
|
|
"item = {}\n",
|
|
"unit = {}\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"person = dict1['person']\n",
|
|
"criteria = dict1['criteria']\n",
|
|
"data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}\n",
|
|
"info = data['sex']+str(data['age'])\n",
|
|
"\n",
|
|
"bz = person[info]\n",
|
|
"print(bz)\n",
|
|
"result = data['result']\n",
|
|
"print(result)\n",
|
|
"height = int(float(result.split(',')[0]))\n",
|
|
"weight = float(result.split(',')[1])\n",
|
|
"mx = criteria[bz][str(height)]\n",
|
|
"if weight < mx[0]:\n",
|
|
" score = 1\n",
|
|
"elif weight < mx[1]:\n",
|
|
" score = 3\n",
|
|
"elif weight < mx[2]:\n",
|
|
" score = 5 \n",
|
|
"elif weight <= mx[3]:\n",
|
|
" score = 3 \n",
|
|
"elif weight > mx[3]:\n",
|
|
" score = 1\n",
|
|
"print(score)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "732161bb-98f2-4861-ab66-7a374678bcd8",
|
|
"metadata": {},
|
|
"source": [
|
|
"# 体质检测数据管理"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "bb2db5e8-5dc6-4366-a39c-a3600ee5007c",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 数据导入Mycrm"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "bc98d772-5841-41a3-ad8f-f7d1ff3b5fde",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入系统人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "2cd93f45-6613-4a3f-97e4-5236068e1860",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import time\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"list1 = []\n",
|
|
"filename = 'data/person_134.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",
|
|
"#print(list1)\n",
|
|
"dict1 = {}\n",
|
|
"for result in list1:\n",
|
|
" code = str(result[4])\n",
|
|
" if int(result[1]) == 0:\n",
|
|
" sex = '男'\n",
|
|
" else:\n",
|
|
" sex = '女'\n",
|
|
" \n",
|
|
" m_item = str(result[3]) \n",
|
|
" dict1.setdefault(code,{}) \n",
|
|
" dict1[code]['name'] = result[0]\n",
|
|
" dict1[code]['sex'] = sex\n",
|
|
" dict1[code]['birth'] = result[2]\n",
|
|
"filename = 'data/天津石化人员清单.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1)) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2eb50f19-c15f-4a36-87b7-cd02551d248d",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入测试项目item"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "0eb37435-9c15-40ef-bd4c-2dffc026f59e",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"data_list = []\n",
|
|
"for k, v in dict1.items():\n",
|
|
" data_list.append((int(k),v['name'])) \n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"sql = 'insert into shijiazhuang_item (id,name) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "2ba97298-1e7e-4192-8d69-ea59f98e071a",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入一级部门"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "9f7ed380-95f3-47d4-9eb5-74937af7811f",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"filename = 'data/result_石家庄.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"unit = set()\n",
|
|
"for k, v in dict1.items():\n",
|
|
" #if 'sub_unit' not in v.keys():\n",
|
|
" # print(k,v['name'])\n",
|
|
" unit.add(v['unit'])\n",
|
|
"print(unit) \n",
|
|
"i = 1\n",
|
|
"dict2 = {}\n",
|
|
"for item in unit:\n",
|
|
" dict2[item] = i\n",
|
|
" i+=1\n",
|
|
"data_list = []\n",
|
|
"for k, v in dict2.items():\n",
|
|
" data_list.append((v,k)) \n",
|
|
" \n",
|
|
"sql = 'insert into shijiazhuang_unit (id,name) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "b8a1fa7f-08ff-49bb-8052-9f86b1f2ac18",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入二级部门"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "a13e81f2-467f-42c7-bb46-b547ef7bdd6c",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"filename = 'data/天津石化人员名单.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"unit = set()\n",
|
|
"for k, v in dict1.items():\n",
|
|
" #if 'sub_unit' not in v.keys():\n",
|
|
" # print(k,v['name'])\n",
|
|
" unit.add(v['unit'])\n",
|
|
"print(unit) \n",
|
|
"i = 1\n",
|
|
"dict2 = {}\n",
|
|
"for item in unit:\n",
|
|
" dict2[item] = i\n",
|
|
" i+=1\n",
|
|
"data_list = []\n",
|
|
"dict3 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict3.setdefault(v['unit'],set())\n",
|
|
" dict3[v['unit']].add(v['sub_unit'])\n",
|
|
"i = 1 \n",
|
|
"for k, v in dict3.items():\n",
|
|
" unit_id = dict2[k]\n",
|
|
" for item in v:\n",
|
|
" data_list.append((i,item,unit_id))\n",
|
|
" i+=1\n",
|
|
"sql = 'insert into tianjin_sub_unit (id,name,unit_id) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "12917000-59e0-4f8a-beee-929c6d7b60a0",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 生成部门JSON文件"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5446269c-d324-4a16-b10e-f24d87178d77",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"filename = 'data/shijiazhuang_unit_20230517.csv'\n",
|
|
"with open(filename,'r',newline='') as csv_file:\n",
|
|
" fl = csv.reader(csv_file,delimiter=',')\n",
|
|
" header = next(fl)\n",
|
|
" list1 = []\n",
|
|
" for line in fl:\n",
|
|
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
|
" list1.append({'id':int(line[0]),'name':line[1]})\n",
|
|
"dict1['unit'] = list1\n",
|
|
"\n",
|
|
"filename = 'data/sub_unit_134.csv'\n",
|
|
"with open(filename,'r',newline='') as csv_file:\n",
|
|
" fl = csv.reader(csv_file,delimiter=',')\n",
|
|
" header = next(fl)\n",
|
|
" list1 = []\n",
|
|
" for line in fl:\n",
|
|
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
|
" list1.append({'id':int(line[0]),'name':line[1],'unit_id':int(line[2])})\n",
|
|
"dict1['sub_unit'] = list1\n",
|
|
"print(dict1)\n",
|
|
"\n",
|
|
"filename = 'data/天津石化部门.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1)) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "5e57329d-a0ef-47b2-9866-fe2a911ff01d",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import csv\n",
|
|
"\n",
|
|
"dict1 = {}\n",
|
|
"filename = 'data/shijiazhuang_unit_20230517.csv'\n",
|
|
"with open(filename,'r',newline='') as csv_file:\n",
|
|
" fl = csv.reader(csv_file,delimiter=',')\n",
|
|
" header = next(fl)\n",
|
|
" list1 = []\n",
|
|
" for line in fl:\n",
|
|
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
|
|
" list1.append({'id':int(line[0]),'name':line[1]})\n",
|
|
" dict1[int(line[0])] = line[1]\n",
|
|
"\n",
|
|
"\n",
|
|
"filename = 'data/石家庄石化部门.json'\n",
|
|
"with open(filename,'w') as fl:\n",
|
|
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
|
"print(len(dict1)) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "53bf98fe-0ae9-402f-b8d8-495e8f31df3d",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入人员信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "6af82fd2-b1d6-44b7-8b13-58883b58f8b0",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"filename = 'data/天津石化人员清单.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" person = json.load(fl)\n",
|
|
" \n",
|
|
"filename = 'data/石家庄石化部门.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"\n",
|
|
"i = 1\n",
|
|
"dict2 = {}\n",
|
|
"for item in unit:\n",
|
|
" dict2[item] = i\n",
|
|
" i+=1\n",
|
|
"data_list = []\n",
|
|
"dict3 = {}\n",
|
|
"dict4 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict3.setdefault(v['unit'],set())\n",
|
|
" dict3[v['unit']].add(v['sub_unit']) \n",
|
|
"i = 1 \n",
|
|
"for k, v in dict3.items():\n",
|
|
" unit_id = dict2[k]\n",
|
|
" for item in v:\n",
|
|
" data_list.append((i,item,unit_id))\n",
|
|
" i+=1\n",
|
|
"for item in data_list:\n",
|
|
" sub_id = item[0]\n",
|
|
" dict4[sub_id] = {'name':item[1],'unit':item[2]}\n",
|
|
"dict5 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" id_unit = dict2[v['unit']]\n",
|
|
" sub_name = v['sub_unit']\n",
|
|
" id_sub = 0\n",
|
|
" for k1, v1 in dict4.items():\n",
|
|
" if v1['name'] == sub_name and v1['unit'] == id_unit:\n",
|
|
" id_sub = int(k1)\n",
|
|
" if id_sub >0:\n",
|
|
" dict5[k] = {'unit':id_unit,'sub_unit':id_sub}\n",
|
|
" else:\n",
|
|
" print(k,'not fund')\n",
|
|
"data_list = []\n",
|
|
"for k, v in dict5.items():\n",
|
|
" id = int(k)\n",
|
|
" name = person[k]['name']\n",
|
|
" sex = person[k]['sex']\n",
|
|
" birth = person[k]['birth']\n",
|
|
" phone = ''\n",
|
|
" note = ''\n",
|
|
" unit = v['sub_unit']\n",
|
|
" data_list.append((id,name,sex,birth,unit))\n",
|
|
"sql = 'insert into tianjin_person (id,name,sex,birth,unit_id) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!') \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "c2007c46-38c8-4a20-9917-b0b8743fe2a9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
" \n",
|
|
"filename = 'data/石家庄石化部门.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"dict3 = {}\n",
|
|
"for k,v in dict1.items():\n",
|
|
" dict3[v] = int(k)\n",
|
|
"filename = 'data/result_石家庄.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict2 = json.load(fl)\n",
|
|
"data_list = []\n",
|
|
"for k, v in dict2.items():\n",
|
|
" id = int(k)\n",
|
|
" name = dict2[k]['name']\n",
|
|
" sex = dict2[k]['sex']\n",
|
|
" birth = dict2[k]['birth'] \n",
|
|
" unit = dict3[dict2[k]['unit']]\n",
|
|
" data_list.append((id,name,sex,birth,unit))\n",
|
|
"sql = 'insert into shijiazhuang_person (id,name,sex,birth,unit_id) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!') "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "fd95a45a-c6df-47c3-9941-2d0579b2c5d9",
|
|
"metadata": {},
|
|
"source": [
|
|
"### 导入测试成绩及得分"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "c989de3f-a8ab-47dc-9662-544e4b6a0e2f",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"#### 二级部门导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "360e61e9-7895-484b-a9d6-333bdefa1a86",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict2[v['name']] = int(k)\n",
|
|
"\n",
|
|
"filename = 'data/天津石化部门.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"unit = {}\n",
|
|
"for item in dict1['unit']:\n",
|
|
" unit[item['name']] = item['id']\n",
|
|
"\n",
|
|
"sub_unit = {}\n",
|
|
"for item in dict1['sub_unit']:\n",
|
|
" sub_unit.setdefault(item['unit_id'],[])\n",
|
|
" sub_unit[item['unit_id']].append({'id':item['id'],'name':item['name']})\n",
|
|
" \n",
|
|
"filename = 'data/天津石化人员名单.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"person = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" person[k] = {'unit':v['unit'],'sub_unit':v['sub_unit']}\n",
|
|
"\n",
|
|
" \n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"data_list = []\n",
|
|
"filename = 'data/result_天津.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k, v in dict1.items():\n",
|
|
" for item in v.keys():\n",
|
|
" if item in dict2.keys():\n",
|
|
" item_id = dict2[item]\n",
|
|
" if v[item]['得分'] == '\\\\N':\n",
|
|
" score = None\n",
|
|
" else:\n",
|
|
" score = int(v[item]['得分'])\n",
|
|
" unit_name = person[k]['unit'] \n",
|
|
" sub_unit_name = person[k]['sub_unit']\n",
|
|
" unit_id = unit[unit_name]\n",
|
|
" for items in sub_unit[unit_id]:\n",
|
|
" if items['name'] ==sub_unit_name:\n",
|
|
" sub_id = items['id'] \n",
|
|
" data_list.append((v[item]['成绩'],score,int(k),item_id,unit_id,sub_id))\n",
|
|
" \n",
|
|
"sql = 'insert into tianjin_records (performance,score,avatar_id_id,item_id_id,unit_id_id,sub_unit_id_id) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!') \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "4aeabbbc-5b51-4dd0-b428-83e2012e63c4",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### 一级部门导入"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "cb747368-d3ac-4b29-ae4f-ce207d5fcd43",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict2[v['name']] = int(k)\n",
|
|
"\n",
|
|
"filename = 'data/石家庄石化部门.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl)\n",
|
|
"dict3 = {}\n",
|
|
"for k,v in dict1.items():\n",
|
|
" dict3[v] = int(k)\n",
|
|
" \n",
|
|
"\n",
|
|
"conn = psycopg2.connect(database=\"mycrm\", user=\"postgres\", password=\"songyi\", host=\"localhost\", port=\"5432\")\n",
|
|
"cursor = conn.cursor()\n",
|
|
"data_list = []\n",
|
|
"filename = 'data/result_石家庄.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"for k, v in dict1.items():\n",
|
|
" for item in v.keys():\n",
|
|
" if item in dict2.keys():\n",
|
|
" item_id = dict2[item] \n",
|
|
" if v[item]['得分'] == '':\n",
|
|
" score = None\n",
|
|
" else:\n",
|
|
" score = int(v[item]['得分'])\n",
|
|
" unit_name = v['unit']\n",
|
|
" unit_id = dict3[unit_name]\n",
|
|
" data_list.append((v[item]['成绩'],score,int(k),item_id,unit_id))\n",
|
|
"sql = 'insert into shijiazhuang_records (performance,score,avatar_id_id,item_id_id,unit_id_id) values %s'\n",
|
|
"ex.execute_values(cursor, sql, data_list, page_size=10000)\n",
|
|
"#conn.commit()\n",
|
|
"cursor.close()\n",
|
|
"conn.close()\n",
|
|
"print('ok!')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "51dc35a5-dc07-40a4-9ea7-375ca7f983c3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import psycopg2\n",
|
|
"from psycopg2 import extras as ex\n",
|
|
"\n",
|
|
"filename = '../item.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"dict2 = {}\n",
|
|
"for k, v in dict1.items():\n",
|
|
" dict2[v['name']] = int(k)\n",
|
|
"\n",
|
|
"filename = 'data/天津石化部门.json'\n",
|
|
"with open(filename,'r') as fl:\n",
|
|
" dict1 = json.load(fl) \n",
|
|
"unit = {}\n",
|
|
"for item in dict1['unit']:\n",
|
|
" unit[item['name']] = item['id']\n",
|
|
"print(unit)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "bdb81e20-32ec-4e0e-b2ac-13dac2060068",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"# 体质报告在线管理"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "1485fc89-4fc2-437d-a29e-b4a0aab12aa0",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增体测单位"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"id": "cf345bf0-f11b-459e-9b69-b2843836f6f3",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-08-29T13:51:03.280856Z",
|
|
"iopub.status.busy": "2023-08-29T13:51:03.280394Z",
|
|
"iopub.status.idle": "2023-08-29T13:51:03.399330Z",
|
|
"shell.execute_reply": "2023-08-29T13:51:03.398909Z",
|
|
"shell.execute_reply.started": "2023-08-29T13:51:03.280807Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"place\"]\n",
|
|
"\n",
|
|
"mydict = { \"id\": \"469849\",\"name\": \"长炼医院\", }\n",
|
|
" \n",
|
|
"x = mycol.insert_one(mydict) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "df2d18e2-d2e4-499e-876a-59d8550a8201",
|
|
"metadata": {},
|
|
"source": [
|
|
"## 新增报告信息"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"id": "1acaf159-637e-4101-9881-f6bb79400136",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-05-19T09:08:35.287714Z",
|
|
"iopub.status.busy": "2023-05-19T09:08:35.286693Z",
|
|
"iopub.status.idle": "2023-05-19T09:08:35.304177Z",
|
|
"shell.execute_reply": "2023-05-19T09:08:35.303461Z",
|
|
"shell.execute_reply.started": "2023-05-19T09:08:35.287667Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"mydict = { \"place\": \"714309\",\"code\":\"4\",\"name\": \"朱维\", }\n",
|
|
" \n",
|
|
"x = mycol.insert_one(mydict) "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"id": "ad3078ac-ae53-4bb4-95bd-387631092bf1",
|
|
"metadata": {
|
|
"execution": {
|
|
"iopub.execute_input": "2023-05-20T04:06:02.667541Z",
|
|
"iopub.status.busy": "2023-05-20T04:06:02.667013Z",
|
|
"iopub.status.idle": "2023-05-20T04:06:02.681377Z",
|
|
"shell.execute_reply": "2023-05-20T04:06:02.680428Z",
|
|
"shell.execute_reply.started": "2023-05-20T04:06:02.667502Z"
|
|
},
|
|
"tags": []
|
|
},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{'_id': ObjectId('64673c9319e8481e9c0ad1a3'), 'place': '714309', 'code': '4', 'name': '朱维'}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import pymongo\n",
|
|
"\n",
|
|
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
|
|
"mydb = myclient[\"baogao\"]\n",
|
|
"mycol = mydb[\"pdf\"]\n",
|
|
"\n",
|
|
"mydict = { \"place\": \"714309\",\"code\":\"4\",\"name\": \"朱维\", }\n",
|
|
" \n",
|
|
"x = mycol.find_one(mydict) \n",
|
|
"print(x)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "cc0571b6-1da5-4bcc-96ad-5613cd1198e3",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|