From fcbc5adc74aa5f1fe328a78c6f6a2d8f4a930199 Mon Sep 17 00:00:00 2001 From: 512song Date: Tue, 15 Apr 2025 13:34:28 +0800 Subject: [PATCH] 20250415 --- 体测单位/新疆.ipynb | 172 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 1 deletion(-) diff --git a/体测单位/新疆.ipynb b/体测单位/新疆.ipynb index 7b7254b..1bbee1c 100644 --- a/体测单位/新疆.ipynb +++ b/体测单位/新疆.ipynb @@ -467,10 +467,180 @@ "wb.save(filename)" ] }, + { + "cell_type": "markdown", + "id": "76125cbf-b20b-464c-8d42-dc03715ef1e2", + "metadata": {}, + "source": [ + "## 新疆油田问卷调查" + ] + }, + { + "cell_type": "markdown", + "id": "646db6a3-8f93-46f5-a235-b417a0b8cb6c", + "metadata": {}, + "source": [ + "### 新疆油田问卷导入" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "b39a8f69-b44a-440e-9bbf-b338a39c9e6b", + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-15T04:00:13.557649Z", + "iopub.status.busy": "2025-04-15T04:00:13.557119Z", + "iopub.status.idle": "2025-04-15T04:00:13.580138Z", + "shell.execute_reply": "2025-04-15T04:00:13.579406Z", + "shell.execute_reply.started": "2025-04-15T04:00:13.557581Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "117\n" + ] + } + ], + "source": [ + "import json\n", + "import csv\n", + "import openpyxl\n", + "import time\n", + "from datetime import date\n", + "\n", + "dict1 = {}\n", + "\n", + "\n", + "\n", + "list1 = []\n", + "filename = 'data/Survey_20250415.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", + " list1.append(line)\n", + "for item in list1:\n", + " phone = item[2]\n", + " tcm = [] \n", + " for i in range(0,60):\n", + " tcm.append(0)\n", + " content = json.loads(item[5])\n", + " name = content['name']\n", + " sex = content['gender']\n", + " for k, v in content.items(): \n", + " if 'tcm' in k:\n", + " i = int(k[3:])\n", + " tcm[i-1] = int(v)\n", + " dict1.setdefault(phone,{})\n", + " dict1[phone]['name'] = name\n", + " if sex =='f':\n", + " dict1[phone]['sex'] = '女'\n", + " else:\n", + " dict1[phone]['sex'] = '男' \n", + " dict1[phone]['unit'] = ' '\n", + " dict1[phone]['month'] = 48\n", + " dict1[phone]['tcm'] = tcm\n", + "filename = 'data/result_新疆油田问卷.json'\n", + "\n", + "with open(filename,'w') as fl:\n", + " json.dump(dict1, fl, ensure_ascii=False)\n", + "print(len(dict1))" + ] + }, + { + "cell_type": "markdown", + "id": "22c6125c-272a-4e8f-aaf7-35822cbfb9e2", + "metadata": {}, + "source": [ + "### 新疆油田问卷报告生成" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "c90ff79b-99ec-4b09-b816-7abf87f0b985", + "metadata": { + "execution": { + "iopub.execute_input": "2025-04-15T05:28:57.532669Z", + "iopub.status.busy": "2025-04-15T05:28:57.531849Z", + "iopub.status.idle": "2025-04-15T05:29:23.324205Z", + "shell.execute_reply": "2025-04-15T05:29:23.323731Z", + "shell.execute_reply.started": "2025-04-15T05:28:57.532581Z" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "117\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", + "file_path ='./新疆油田问卷/'\n", + "\n", + "i=0\n", + "list2 = []\n", + "for k, v in dict1.items():\n", + " list1 = []\n", + " mydata = {}\n", + " \n", + " id = str(k)\n", + " mydata['path'] = file_path+id+'-'+ v['name']+'.pdf'\n", + " mydata['title'] = '中国石油新疆油田分公司'\n", + " mydata['subtitle'] = v['unit']\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", + " \n", + " survey_list = ['tcm','psy_yangmiao_old','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", + " \n", + " #if len(mydata['fits']) >2 or len(mydata['surveys']) >0:\n", + " #if len(mydata['fits']) >2 : \n", + " if 'surveys' in mydata.keys():\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": "code", "execution_count": null, - "id": "f44c57ed-aac8-481a-9126-0dadcbe0190c", + "id": "508c76b5-b51f-43d5-8247-05a57cd0249c", "metadata": {}, "outputs": [], "source": []