20230430
This commit is contained in:
1 parent
f03e964585
commit
5ac233adcc
4 files changed
+574
-141
No files matched your search
+397
-62
@@ -26,27 +26,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"execution_count": null,
|
||||
"id": "8cd73044-56a8-409b-a873-085feb63af17",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-12-11T04:12:38.717398Z",
|
||||
"iopub.status.busy": "2022-12-11T04:12:38.716743Z",
|
||||
"iopub.status.idle": "2022-12-11T04:12:38.819382Z",
|
||||
"shell.execute_reply": "2022-12-11T04:12:38.818678Z",
|
||||
"shell.execute_reply.started": "2022-12-11T04:12:38.717334Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
@@ -111,27 +96,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 73,
|
||||
"execution_count": null,
|
||||
"id": "2ca52d7b-d77e-452f-98f6-95072a5a1934",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-12-11T08:20:52.050056Z",
|
||||
"iopub.status.busy": "2022-12-11T08:20:52.049496Z",
|
||||
"iopub.status.idle": "2022-12-11T08:20:52.311023Z",
|
||||
"shell.execute_reply": "2022-12-11T08:20:52.310420Z",
|
||||
"shell.execute_reply.started": "2022-12-11T08:20:52.049977Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
@@ -198,28 +168,12 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 98,
|
||||
"execution_count": null,
|
||||
"id": "f32b266a-7e46-4703-ab61-7cbbc81b5ab1",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-12-15T01:23:46.345354Z",
|
||||
"iopub.status.busy": "2022-12-15T01:23:46.344556Z",
|
||||
"iopub.status.idle": "2022-12-15T01:23:46.364220Z",
|
||||
"shell.execute_reply": "2022-12-15T01:23:46.363538Z",
|
||||
"shell.execute_reply.started": "2022-12-15T01:23:46.345276Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"[25.9, 31.5, 38.6, 44.0, 50.8]\n",
|
||||
"5\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
@@ -261,15 +215,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 93,
|
||||
"execution_count": 53,
|
||||
"id": "b32fbbdd-eb0a-4f0d-8901-e39a727c3ff8",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2022-12-11T08:42:02.334236Z",
|
||||
"iopub.status.busy": "2022-12-11T08:42:02.333952Z",
|
||||
"iopub.status.idle": "2022-12-11T08:42:02.357384Z",
|
||||
"shell.execute_reply": "2022-12-11T08:42:02.355513Z",
|
||||
"shell.execute_reply.started": "2022-12-11T08:42:02.334210Z"
|
||||
"iopub.execute_input": "2023-04-30T01:48:23.869481Z",
|
||||
"iopub.status.busy": "2023-04-30T01:48:23.868619Z",
|
||||
"iopub.status.idle": "2023-04-30T01:48:23.882339Z",
|
||||
"shell.execute_reply": "2023-04-30T01:48:23.881272Z",
|
||||
"shell.execute_reply.started": "2023-04-30T01:48:23.869438Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
@@ -279,8 +233,8 @@
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"M50~59\n",
|
||||
"175.5,90.2\n",
|
||||
"1\n"
|
||||
"177.0,81.1\n",
|
||||
"5\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -296,7 +250,7 @@
|
||||
" dict1 = json.load(fl) \n",
|
||||
"person = dict1['person']\n",
|
||||
"criteria = dict1['criteria']\n",
|
||||
"data = {'name':'张三','sex':'M','age':59,'item':'HeightWeight','result':'175.5,90.2'}\n",
|
||||
"data = {'name':'张三','sex':'M','age':59,'item':'HeightWeight','result':'177.0,81.1'}\n",
|
||||
"info = data['sex']+str(data['age'])\n",
|
||||
"\n",
|
||||
"bz = person[info]\n",
|
||||
@@ -319,10 +273,391 @@
|
||||
"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": "5167ef1b-8ea5-4079-9468-33ec52f2317e",
|
||||
"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 tianjin_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/天津石化人员名单.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 tianjin_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": "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",
|
||||
"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",
|
||||
"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": "markdown",
|
||||
"id": "fd95a45a-c6df-47c3-9941-2d0579b2c5d9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导入测试成绩及得分"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 50,
|
||||
"id": "360e61e9-7895-484b-a9d6-333bdefa1a86",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-04-29T14:29:07.198753Z",
|
||||
"iopub.status.busy": "2023-04-29T14:29:07.197888Z",
|
||||
"iopub.status.idle": "2023-04-29T14:29:08.464741Z",
|
||||
"shell.execute_reply": "2023-04-29T14:29:08.463607Z",
|
||||
"shell.execute_reply.started": "2023-04-29T14:29:07.198711Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"ok!\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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",
|
||||
"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",
|
||||
" \n",
|
||||
" data_list.append((v[item]['成绩'],score,int(k),item_id))\n",
|
||||
" \n",
|
||||
"sql = 'insert into tianjin_records (performance,score,avatar_id_id,item_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": "code",
|
||||
"execution_count": null,
|
||||
"id": "cb747368-d3ac-4b29-ae4f-ce207d5fcd43",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"filename = 'data/天津石化人员名单.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" if 'num_id' not in v.keys():\n",
|
||||
" print(k,v['name'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "51dc35a5-dc07-40a4-9ea7-375ca7f983c3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
Reference in new issue
Block a user