20251124
This commit is contained in:
1 parent
4f0f65a076
commit
aff0303bc9
5 files changed
+2192
-1715
No files matched your search
+142
-138
@@ -1142,7 +1142,7 @@
|
||||
"\n",
|
||||
"title = []\n",
|
||||
"\n",
|
||||
"filename = 'data/surveys_records_宁夏能化.json'\n",
|
||||
"filename = 'data/surveys_records_2025-11-24.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
@@ -1156,17 +1156,18 @@
|
||||
" else:\n",
|
||||
" list2.append('')\n",
|
||||
" for xm in data_title:\n",
|
||||
" if xm in item['data'].keys():\n",
|
||||
" data = json.loads(item['data'])\n",
|
||||
" if xm in data.keys():\n",
|
||||
" if xm =='sport_type':\n",
|
||||
" list2.append(','.join(item['data'][xm]))\n",
|
||||
" list2.append(','.join(data[xm]))\n",
|
||||
" else:\n",
|
||||
" list2.append(item['data'][xm])\n",
|
||||
" list2.append(data[xm])\n",
|
||||
" else:\n",
|
||||
" list2.append('')\n",
|
||||
" \n",
|
||||
" list1.append(list2)\n",
|
||||
"all_title = ['id', 'date_created','name', 'gender', 'birth', 'code', 'unit', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷(20251114).xlsx'\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷(20251123).xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"sheet.append(all_title)\n",
|
||||
@@ -1218,7 +1219,7 @@
|
||||
" password=\"songyi\"\n",
|
||||
")\n",
|
||||
"cur = conn.cursor()\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251114).xlsx',data_only=True)\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251123).xlsx',data_only=True)\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
@@ -1251,6 +1252,80 @@
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d266379b-4797-4f60-a83d-dc2349a48f0b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 核对新增人员"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "91c53866-3725-4ceb-b0eb-23fb14e20561",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"import psycopg2\n",
|
||||
"\n",
|
||||
"conn = psycopg2.connect(\n",
|
||||
" host=\"localhost\",\n",
|
||||
" database=\"tice\",\n",
|
||||
" user=\"mydata\",\n",
|
||||
" password=\"songyi\"\n",
|
||||
")\n",
|
||||
"cur = conn.cursor()\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251123).xlsx',data_only=True)\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"org_id = 1\n",
|
||||
"event_id = 1\n",
|
||||
"sql = \"SELECT code from fitness_person where org_id = %s\"\n",
|
||||
"params = (org_id,)\n",
|
||||
"cur.execute(sql, params)\n",
|
||||
"rows = cur.fetchall()\n",
|
||||
"codes = []\n",
|
||||
"for row in rows:\n",
|
||||
" codes.append(row[0])\n",
|
||||
"\n",
|
||||
"person = {}\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" code = str(sheet.cell(n, 6).value)\n",
|
||||
" if code not in codes:\n",
|
||||
" person.setdefault(code, {})\n",
|
||||
" dict1 = {}\n",
|
||||
" dict1['name'] = sheet.cell(n, 3).value\n",
|
||||
" sex = sheet.cell(n, 4).value\n",
|
||||
" if sex =='male':\n",
|
||||
" dict1['sex'] = '男'\n",
|
||||
" else:\n",
|
||||
" dict1['sex'] = '女'\n",
|
||||
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
|
||||
" if len(birth)==7:\n",
|
||||
" dict1['birth'] = birth+'-01'\n",
|
||||
" else:\n",
|
||||
" dict1['birth'] = birth\n",
|
||||
" dict1['unit'] = sheet.cell(n, 7).value\n",
|
||||
" person[code] = dict1\n",
|
||||
"org_id = 1\n",
|
||||
"data1 = []\n",
|
||||
"for k,v in person.items():\n",
|
||||
" tuple1 = (v['name'],v['sex'],v['unit'],v['birth'],k,org_id)\n",
|
||||
" print(tuple1)\n",
|
||||
" data1.append(tuple1)\n",
|
||||
"sql = \"INSERT INTO fitness_person ( name, sex,unit,birth,code,org_id) VALUES (%s, %s, %s,%s, %s, %s)\" \n",
|
||||
"#print(data1)\n",
|
||||
"cur.executemany(sql, data1)\n",
|
||||
"conn.commit()\n",
|
||||
"\n",
|
||||
"# 关闭连接\n",
|
||||
"cur.close()\n",
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5c2a37a0-18d3-4c89-8dd9-283a417b5c60",
|
||||
@@ -1329,15 +1404,31 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 106,
|
||||
"id": "b7133988-213c-4b52-8d6b-17b56b8ea310",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-11-24T05:18:02.990193Z",
|
||||
"iopub.status.busy": "2025-11-24T05:18:02.989559Z",
|
||||
"iopub.status.idle": "2025-11-24T05:18:03.293675Z",
|
||||
"shell.execute_reply": "2025-11-24T05:18:03.293166Z",
|
||||
"shell.execute_reply.started": "2025-11-24T05:18:02.990132Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"483 ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251114).xlsx',data_only=True)\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251123).xlsx',data_only=True)\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
@@ -1356,21 +1447,23 @@
|
||||
" person[code] = dict1\n",
|
||||
"#print(person)\n",
|
||||
"\n",
|
||||
"filename = 'data/surveys_records_宁夏能化.json'\n",
|
||||
"filename = 'data/surveys_records_2025-11-24.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
"set1 = set()\n",
|
||||
"title = ['date_created', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose_Comment', 'last_recipe_Comment', 'last_lose_weight', 'last_sport_Comment', 'sport_type_Comment']\n",
|
||||
"data_title = ['height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"for item in dict1: \n",
|
||||
" dict2 = {}\n",
|
||||
" code = item['data']['code']\n",
|
||||
" data = json.loads(item['data'])\n",
|
||||
" code = data['code']\n",
|
||||
" rq = item['date_created'].split()[0]\n",
|
||||
" dict2['height'] = str('%.2f' % item['data']['height'])\n",
|
||||
" dict2['weight'] = str('%.2f' %item['data']['weight'])\n",
|
||||
" dict2['next_weight'] = str('%.2f' %(item['data']['weight']-item['data']['next_weight']))\n",
|
||||
" dict2['bmi'] = str('%.2f' %((item['data']['weight']/item['data']['height'])/item['data']['height']*10000))\n",
|
||||
" bmi = (item['data']['weight']/item['data']['height'])/item['data']['height']*10000\n",
|
||||
" dict2['height'] = str('%.2f' % data['height'])\n",
|
||||
" dict2['weight'] = str('%.2f' %data['weight'])\n",
|
||||
" dict2['next_weight'] = str('%.2f' %(data['weight']-data['next_weight']))\n",
|
||||
" dict2['bmi'] = str('%.2f' %((data['weight']/data['height'])/data['height']*10000))\n",
|
||||
" bmi = (data['weight']/data['height'])/data['height']*10000\n",
|
||||
" if bmi<18.5:\n",
|
||||
" bmi_zt = '体重偏轻'\n",
|
||||
" elif bmi >=18.5 and bmi <24.0:\n",
|
||||
@@ -1380,39 +1473,39 @@
|
||||
" else:\n",
|
||||
" bmi_zt = '体重肥胖'\n",
|
||||
" dict2['bmi_zt'] = bmi_zt\n",
|
||||
" dict2['waist'] = str('%.2f' %item['data']['waist'])\n",
|
||||
" dict2['hip'] = str('%.2f' %item['data']['hip'])\n",
|
||||
" whr = item['data']['waist']/item['data']['hip']\n",
|
||||
" if item['data']['gender'] =='male' and whr > 0.9:\n",
|
||||
" dict2['waist'] = str('%.2f' %data['waist'])\n",
|
||||
" dict2['hip'] = str('%.2f' %data['hip'])\n",
|
||||
" whr = data['waist']/data['hip']\n",
|
||||
" if data['gender'] =='male' and whr > 0.9:\n",
|
||||
" whr_zt = '超标'\n",
|
||||
" elif item['data']['gender'] =='female' and whr > 0.85:\n",
|
||||
" elif data['gender'] =='female' and whr > 0.85:\n",
|
||||
" whr_zt = '超标'\n",
|
||||
" else:\n",
|
||||
" whr_zt = '正常'\n",
|
||||
" dict2['whr'] = str('%.2f' %whr)\n",
|
||||
" dict2['whr_zt'] = whr_zt\n",
|
||||
" if 'sport_type' in item['data'].keys(): \n",
|
||||
" dict2['sport_type'] = ','.join(item['data']['sport_type']).replace('other','其他')\n",
|
||||
" dict2['sport_duration'] = str(item['data']['sport_duration'])\n",
|
||||
" dict2['recipe'] = item['data']['recipe']\n",
|
||||
" if 'last_sport' in item['data'].keys(): \n",
|
||||
" dict2['last_sport'] = item['data']['last_sport']\n",
|
||||
" if 'last_sport_time' in item['data'].keys():\n",
|
||||
" dict2['last_sport_time'] = str(item['data']['last_sport_time'])\n",
|
||||
" if 'last_sport-Comment' in item['data'].keys():\n",
|
||||
" dict2['last_sport-Comment'] = item['data']['last_sport-Comment']\n",
|
||||
" dict2['last_recipe'] = item['data']['last_recipe']\n",
|
||||
" if 'last_recipe-Comment' in item['data'].keys(): \n",
|
||||
" dict2['last_recipe-Comment'] = item['data']['last_recipe-Comment']\n",
|
||||
" if 'last_lose' in item['data'].keys(): \n",
|
||||
" dict2['last_lose'] = item['data']['last_lose']\n",
|
||||
" if 'last_lose_weight' in item['data'].keys():\n",
|
||||
" dict2['last_lose_weight'] = str('%.2f' %item['data']['last_lose_weight'])\n",
|
||||
" if 'last_lose-Comment' in item['data'].keys(): \n",
|
||||
" dict2['last_lose-Comment'] = item['data']['last_lose-Comment']\n",
|
||||
" if 'sport_type' in data.keys(): \n",
|
||||
" dict2['sport_type'] = ','.join(data['sport_type']).replace('other','其他')\n",
|
||||
" dict2['sport_duration'] = str(data['sport_duration'])\n",
|
||||
" dict2['recipe'] = data['recipe']\n",
|
||||
" if 'last_sport' in data.keys(): \n",
|
||||
" dict2['last_sport'] = data['last_sport']\n",
|
||||
" if 'last_sport_time' in data.keys():\n",
|
||||
" dict2['last_sport_time'] = str(data['last_sport_time'])\n",
|
||||
" if 'last_sport-Comment' in data.keys():\n",
|
||||
" dict2['last_sport-Comment'] = data['last_sport-Comment']\n",
|
||||
" dict2['last_recipe'] = data['last_recipe']\n",
|
||||
" if 'last_recipe-Comment' in data.keys(): \n",
|
||||
" dict2['last_recipe-Comment'] = data['last_recipe-Comment']\n",
|
||||
" if 'last_lose' in data.keys(): \n",
|
||||
" dict2['last_lose'] = data['last_lose']\n",
|
||||
" if 'last_lose_weight' in data.keys():\n",
|
||||
" dict2['last_lose_weight'] = str('%.2f' %data['last_lose_weight'])\n",
|
||||
" if 'last_lose-Comment' in data.keys(): \n",
|
||||
" dict2['last_lose-Comment'] = data['last_lose-Comment']\n",
|
||||
" if code in person.keys():\n",
|
||||
" person[code][rq] = dict2\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况-1.json'\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况(20251124).json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||||
@@ -1516,15 +1609,15 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 77,
|
||||
"execution_count": 107,
|
||||
"id": "55b20059-ae36-493e-b0c5-c7e35473efc7",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-11-19T10:42:23.125996Z",
|
||||
"iopub.status.busy": "2025-11-19T10:42:23.125745Z",
|
||||
"iopub.status.idle": "2025-11-19T10:42:25.142922Z",
|
||||
"shell.execute_reply": "2025-11-19T10:42:25.142275Z",
|
||||
"shell.execute_reply.started": "2025-11-19T10:42:23.125974Z"
|
||||
"iopub.execute_input": "2025-11-24T05:21:09.966817Z",
|
||||
"iopub.status.busy": "2025-11-24T05:21:09.966532Z",
|
||||
"iopub.status.idle": "2025-11-24T05:21:11.798693Z",
|
||||
"shell.execute_reply": "2025-11-24T05:21:11.798041Z",
|
||||
"shell.execute_reply.started": "2025-11-24T05:21:09.966796Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -1543,7 +1636,7 @@
|
||||
"cur = conn.cursor()\n",
|
||||
"event_id = 1\n",
|
||||
"org_id = 1\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况-1.json'\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况(20251124).json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = ['name','sex','birth','unit']\n",
|
||||
@@ -1612,95 +1705,6 @@
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a068cd21-d751-46f9-9c95-f26cf14ddeb8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"import psycopg2\n",
|
||||
"\n",
|
||||
"conn = psycopg2.connect(\n",
|
||||
" host=\"localhost\",\n",
|
||||
" database=\"tice\",\n",
|
||||
" user=\"mydata\",\n",
|
||||
" password=\"songyi\"\n",
|
||||
")\n",
|
||||
"cur = conn.cursor()\n",
|
||||
"event_id = 1\n",
|
||||
"org_id = 1\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况-1.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = ['name','sex','birth','unit']\n",
|
||||
"xm = ['height','weight','next_weight','bmi','bmi_zt','waist', 'hip','whr','whr_zt' ]\n",
|
||||
"data2 = []\n",
|
||||
"for k,v in dict1.items():\n",
|
||||
" list2 = []\n",
|
||||
" \n",
|
||||
" for k1,v1 in v.items():\n",
|
||||
" #list2 = []\n",
|
||||
" if k1 not in list1:\n",
|
||||
" list2.append(k1)\n",
|
||||
" list2.sort()\n",
|
||||
" \n",
|
||||
" for rq in list2:\n",
|
||||
" for k1, v1 in v[rq].items():\n",
|
||||
" code = k\n",
|
||||
" \n",
|
||||
" sql = \"SELECT id from fitness_person where code = %s and org_id = %s\"\n",
|
||||
" params = (code,org_id)\n",
|
||||
" cur.execute(sql, params)\n",
|
||||
" rows = cur.fetchone()\n",
|
||||
" if rows:\n",
|
||||
" data1 = []\n",
|
||||
" data1.append(event_id)\n",
|
||||
" data1.append(rows[0])\n",
|
||||
" data1.append(datetime.strptime(rq,'%Y-%m-%d'))\n",
|
||||
" data1.append(k)\n",
|
||||
" for item in xm:\n",
|
||||
" data1.append(v[rq][item])\n",
|
||||
" if 'sport_type' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_type'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" if 'sport_type' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_type'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" \n",
|
||||
" if 'sport_duration' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_duration'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" if v[rq]['recipe']=='free':\n",
|
||||
" data1.append('自行控制')\n",
|
||||
" else:\n",
|
||||
" data1.append('减脂餐')\n",
|
||||
" if v[rq]['last_sport']=='是':\n",
|
||||
" data1.append('运动时长:'+str(v[rq]['last_sport_time'])+'分钟')\n",
|
||||
" else:\n",
|
||||
" data1.append('未运动,'+v[rq]['last_sport-Comment'])\n",
|
||||
" if v[rq]['last_recipe']=='是':\n",
|
||||
" data1.append('是')\n",
|
||||
" else:\n",
|
||||
" data1.append('否。'+v[rq]['last_recipe-Comment'])\n",
|
||||
" if v[rq]['last_lose']=='是':\n",
|
||||
" data1.append('是,减重'+str(v[rq]['last_lose_weight'])+'公斤。')\n",
|
||||
" elif 'last_lose-Comment' in v[rq].keys():\n",
|
||||
" data1.append('否。'+v[rq]['last_lose-Comment'])\n",
|
||||
" else:\n",
|
||||
" data1.append('否。')\n",
|
||||
" print(data1)\n",
|
||||
" sql = \"INSERT INTO fitness_record_data (event_id,user_id,date_created, height, weight, next_weight, bmi,bmi_zt,waist, hip, whr,whr_zt, sport_type, sport_duration, recipe, last_sport, last_recipe, last_lose, last_lose_comment)\" \n",
|
||||
"sql = sql + \" VALUES (%s,%s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s)\"\n",
|
||||
"cur.executemany(sql, data2)\n",
|
||||
"conn.commit()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
Reference in new issue
Block a user