20231117
This commit is contained in:
1 parent
066a903916
commit
a4f158504b
2 files changed
+277
-74
No files matched your search
+76
-74
@@ -4,6 +4,7 @@
|
||||
"cell_type": "markdown",
|
||||
"id": "1c72f0cf-165b-4025-af9d-6771e4a0a5d1",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true,
|
||||
"tags": [],
|
||||
"toc-hr-collapsed": true
|
||||
},
|
||||
@@ -15,7 +16,6 @@
|
||||
"cell_type": "markdown",
|
||||
"id": "61f4a6eb-797e-4fe2-95df-e27b316c95f1",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true,
|
||||
"tags": []
|
||||
},
|
||||
"source": [
|
||||
@@ -1063,12 +1063,28 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 100,
|
||||
"id": "1aa45b35-7376-4c50-8275-79b090a6c758",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-11-16T08:39:54.051678Z",
|
||||
"iopub.status.busy": "2023-11-16T08:39:54.051221Z",
|
||||
"iopub.status.idle": "2023-11-16T08:39:54.140085Z",
|
||||
"shell.execute_reply": "2023-11-16T08:39:54.139600Z",
|
||||
"shell.execute_reply.started": "2023-11-16T08:39:54.051641Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"697\n",
|
||||
"697\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import time\n",
|
||||
@@ -1183,9 +1199,16 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "63d5bccf-7351-4a08-863d-b1ca3b263eca",
|
||||
"execution_count": 101,
|
||||
"id": "c0128f52-8697-4258-aba0-89a522fb9cc0",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-11-16T08:39:58.488835Z",
|
||||
"iopub.status.busy": "2023-11-16T08:39:58.488433Z",
|
||||
"iopub.status.idle": "2023-11-16T08:39:58.584720Z",
|
||||
"shell.execute_reply": "2023-11-16T08:39:58.584247Z",
|
||||
"shell.execute_reply.started": "2023-11-16T08:39:58.488803Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -1204,57 +1227,68 @@
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict3 = json.load(fl)\n",
|
||||
"\n",
|
||||
"phone = set()\n",
|
||||
"phone1 = set()\n",
|
||||
"phone = {}\n",
|
||||
"for k,v in dict3.items():\n",
|
||||
" if 'phone' in v.keys():\n",
|
||||
" phone.add(v['phone'])\n",
|
||||
" phone[v['phone']] = k\n",
|
||||
"list1 = []\n",
|
||||
"filename = 'data/Survey_20231114.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",
|
||||
"dict2 = {}\n",
|
||||
"psy,tcm,spine = []\n",
|
||||
"m_rq = '2023-11-14'\n",
|
||||
"rq= date.fromisoformat(m_rq.replace('/','-'))\n",
|
||||
"psy = []\n",
|
||||
"tcm = []\n",
|
||||
"spine = []\n",
|
||||
"\n",
|
||||
"for i in range(0,44):\n",
|
||||
" psy.append(0)\n",
|
||||
"for i in range(0,60):\n",
|
||||
" tcm.append(0)\n",
|
||||
"for i in range(0,26):\n",
|
||||
" spine.append(0)\n",
|
||||
"\n",
|
||||
"for item in list1:\n",
|
||||
" if item[2] in phone: \n",
|
||||
" if item[2] in phone.keys(): \n",
|
||||
" content = json.loads(item[5])\n",
|
||||
" \n",
|
||||
" if phone[item[2]] not in dict1.keys():\n",
|
||||
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
||||
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||||
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||||
" for k, v in content.items():\n",
|
||||
" if 'psy' in k:\n",
|
||||
" i = int(k[3:])\n",
|
||||
" psy[i] = v\n",
|
||||
" \n",
|
||||
" i = int(k[1:])\n",
|
||||
" list2[i-1] = v\n",
|
||||
" dict2[item[2]] = list2\n",
|
||||
"print(dict2) \n",
|
||||
"for k, v in dict3.items():\n",
|
||||
" if 'phone' in v.keys() and v['phone'] in dict2.keys():\n",
|
||||
" if k not in dict1.keys():\n",
|
||||
" dict1.setdefault(k,{})\n",
|
||||
" dict1[k] = dict3[k]\n",
|
||||
" days = (v['rq']-v['birth']).days \n",
|
||||
" dict1[k]['age'] = int(days/365)\n",
|
||||
" dict1[k]['month'] = int(days/365*12)\n",
|
||||
" psy[i-1] = int(v)\n",
|
||||
" if 'tcm' in k:\n",
|
||||
" i = int(k[3:])\n",
|
||||
" tcm[i-1] = int(v)\n",
|
||||
" if 'spine' in k:\n",
|
||||
" i = int(k[5:])\n",
|
||||
" spine[i-1] = int(v)\n",
|
||||
" if 'psy' in item[5]:\n",
|
||||
" dict1[phone[item[2]]]['psy'] = psy\n",
|
||||
" if 'tcm' in item[5]:\n",
|
||||
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
||||
" if 'spine' in item[5]:\n",
|
||||
" dict1[phone[item[2]]]['spine'] = spine\n",
|
||||
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
||||
" \n",
|
||||
" dict1[k]['tcm'] = dict2[str(v['phone'])]\n",
|
||||
" \n",
|
||||
" days = (rq-birth).days \n",
|
||||
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
||||
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
||||
"filename = 'data/result_北海炼化2023.json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict1, fl, ensure_ascii=False) "
|
||||
" json.dump(dict1, fl, ensure_ascii=False) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "c0128f52-8697-4258-aba0-89a522fb9cc0",
|
||||
"id": "5f222727-d5b4-481f-8f1c-bea74b35936b",
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
@@ -1275,7 +1309,6 @@
|
||||
" dict3 = json.load(fl)\n",
|
||||
"\n",
|
||||
"phone = {}\n",
|
||||
"\n",
|
||||
"for k,v in dict3.items():\n",
|
||||
" if 'phone' in v.keys():\n",
|
||||
" phone[v['phone']] = k\n",
|
||||
@@ -1285,50 +1318,19 @@
|
||||
" 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",
|
||||
"dict2 = {}\n",
|
||||
"#psy = []\n",
|
||||
"#m_rq = '2023-11-14'\n",
|
||||
"#rq= date.fromisoformat(m_rq.replace('/','-'))\n",
|
||||
"for item in list1:\n",
|
||||
" if item[2] in phone.keys(): \n",
|
||||
" content = json.loads(item[5])\n",
|
||||
" print(phone[item[2]])\n",
|
||||
" if phone[item[2]] not in dict1.keys():\n",
|
||||
" dict1[phone[item[2]]] = dict3[phone[item[2]]]\n",
|
||||
" rq = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||||
" #dict1[phone[item[2]]]['rq'] = date.fromisoformat(item[6].replace('/','-').split(' ')[0])\n",
|
||||
" \n",
|
||||
" psy = []\n",
|
||||
" tcm = []\n",
|
||||
" spine = []\n",
|
||||
" for k, v in content.items():\n",
|
||||
" if 'psy' in k:\n",
|
||||
" i = int(k[3:])\n",
|
||||
" psy.append(v)\n",
|
||||
" if 'tcm' in k:\n",
|
||||
" i = int(k[3:])\n",
|
||||
" tcm.append(v)\n",
|
||||
" if 'spine' in k:\n",
|
||||
" i = int(k[5:])\n",
|
||||
" spine.append(v)\n",
|
||||
" if len(psy) > 1:\n",
|
||||
" dict1[phone[item[2]]]['psy'] = psy\n",
|
||||
" if len(tcm) > 1:\n",
|
||||
" dict1[phone[item[2]]]['tcm'] = tcm\n",
|
||||
" if len(psy) > 1:\n",
|
||||
" dict1[phone[item[2]]]['spine'] = spine\n",
|
||||
" birth = date.fromisoformat(dict3[phone[item[2]]]['birth'].replace('/','-'))\n",
|
||||
" \n",
|
||||
" days = (rq-birth).days \n",
|
||||
" dict1[phone[item[2]]]['age'] = int(days/365)\n",
|
||||
" dict1[phone[item[2]]]['month'] = int(days/365*12)\n",
|
||||
"filename = 'data/result_北海炼化2023.json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict1, fl, ensure_ascii=False) "
|
||||
"psy = []\n",
|
||||
"tcm = []\n",
|
||||
"spine = []\n",
|
||||
"for i in range(0,44):\n",
|
||||
" psy.append(0)\n",
|
||||
"for i in range(0,60):\n",
|
||||
" tcm.append(0)\n",
|
||||
"for i in range(0,26):\n",
|
||||
" spine.append(0)\n",
|
||||
"print(len(spine))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user