This commit is contained in:
512song committed 2024-11-26 09:31:20 +08:00
1 parent f382b9af15
commit 752e3f388e
2 files changed
+250 -108

No files matched your search

+13 -4
View File
@@ -1,5 +1,17 @@
import sys,os
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
import json
import time
filename = 'data/体质检测标准 (1).json'
with open(filename,'r') as fl:
dict1 = json.load(fl)
filename = 'data/体质检测标准_BMI.json'
with open(filename,'r') as fl:
dict4 = json.load(fl)
def cal_score(data1): def cal_score(data1):
#data = {'name':'张三','sex':'M','age':37,'item':'StepExperiment','result':46}
person = dict1['person'] person = dict1['person']
criteria = dict1['criteria'] criteria = dict1['criteria']
if data1['age'] >59: if data1['age'] >59:
@@ -29,7 +41,6 @@ def cal_score(data1):
return(score) return(score)
def cal_bmi(data1): def cal_bmi(data1):
# data = {'name':'张三','sex':'M','age':37,'item':'HeightWeight','result':'177.7,97.0'}
person = dict4['person'] person = dict4['person']
criteria = dict4['criteria'] criteria = dict4['criteria']
if data1['age'] > 59: if data1['age'] > 59:
@@ -38,9 +49,7 @@ def cal_bmi(data1):
data1['age'] = 20 data1['age'] = 20
info = data1['sex']+str(data1['age']) info = data1['sex']+str(data1['age'])
bz = person[info] bz = person[info]
#print(bz)
result = data1['result'] result = data1['result']
#print(data1['code'],result)
height = int(float(result.split(',')[0])) height = int(float(result.split(',')[0]))
weight = float(result.split(',')[1]) weight = float(result.split(',')[1])
if str(height) not in criteria[bz]: if str(height) not in criteria[bz]:
+237 -104
View File
@@ -1744,27 +1744,12 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"id": "f0608de5-07ae-458c-999e-60968314f058", "id": "f0608de5-07ae-458c-999e-60968314f058",
"metadata": { "metadata": {
"execution": {
"iopub.execute_input": "2024-11-18T07:24:22.978299Z",
"iopub.status.busy": "2024-11-18T07:24:22.977549Z",
"iopub.status.idle": "2024-11-18T07:24:23.255535Z",
"shell.execute_reply": "2024-11-18T07:24:23.254995Z",
"shell.execute_reply.started": "2024-11-18T07:24:22.978234Z"
},
"tags": [] "tags": []
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [ "source": [
"import json\n", "import json\n",
"import openpyxl\n", "import openpyxl\n",
@@ -2122,26 +2107,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"id": "c9262823-f492-4934-a0ce-f8f80c4a1bea", "id": "c9262823-f492-4934-a0ce-f8f80c4a1bea",
"metadata": { "metadata": {},
"execution": { "outputs": [],
"iopub.execute_input": "2024-11-21T06:38:27.978576Z",
"iopub.status.busy": "2024-11-21T06:38:27.977760Z",
"iopub.status.idle": "2024-11-21T06:38:28.260893Z",
"shell.execute_reply": "2024-11-21T06:38:28.260411Z",
"shell.execute_reply.started": "2024-11-21T06:38:27.978502Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [ "source": [
"import openpyxl\n", "import openpyxl\n",
"import json\n", "import json\n",
@@ -2178,26 +2147,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"id": "ffd34b08-40fd-45c5-a2d3-33c460c7b1dd", "id": "ffd34b08-40fd-45c5-a2d3-33c460c7b1dd",
"metadata": { "metadata": {},
"execution": { "outputs": [],
"iopub.execute_input": "2024-11-15T08:58:30.529702Z",
"iopub.status.busy": "2024-11-15T08:58:30.528869Z",
"iopub.status.idle": "2024-11-15T08:58:30.546247Z",
"shell.execute_reply": "2024-11-15T08:58:30.545156Z",
"shell.execute_reply.started": "2024-11-15T08:58:30.529616Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [ "source": [
"import json\n", "import json\n",
"\n", "\n",
@@ -2227,15 +2180,146 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"id": "202dcc9d-1f36-43c4-ad8d-8ee8c9db90ce", "id": "e1a1b329-acf1-4be9-bcf0-736dbe7f8e0b",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import datetime\n",
"import csv\n",
"from datetime import date\n",
"\n",
"\n",
"re_ta = {}\n",
"list1 = []\n",
"filename = 'data/北海炼化人员2024.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/marks_20241124.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",
"\n",
"for result in list1:\n",
" user = str(result[2])\n",
" rq = date.fromisoformat(result[5].replace('/','-'))\n",
" if user in dict1.keys():\n",
" l_xm = []\n",
" m_item = str(result[3]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" re_ta[user]['sex'] = dict1[user]['sex']\n",
" if 'phone' in dict1[user].keys():\n",
" re_ta[user]['phone'] = dict1[user]['phone']\n",
" if dict1[user]['sex'] == '男':\n",
" l_xm = ['bmi','lung','grip','flexion','jump','pushup','balance','reaction','step']\n",
" else:\n",
" l_xm = ['bmi','lung','grip','flexion','jump','balance','reaction','step','situp']\n",
" re_ta[user]['unit'] = dict1[user]['unit']\n",
" birth = date.fromisoformat(dict1[user]['birth'].replace('/','-'))\n",
" item_name = result[3] \n",
" if item_name in l_xm: \n",
" days = (rq-birth).days \n",
" re_ta[user]['age'] = int(days/365)\n",
" re_ta[user]['month'] = int(days/365*12)\n",
" re_ta[user]['rq'] = result[5]\n",
" re_ta[user].setdefault(item_name,{}) \n",
" score = result[4] \n",
" re_ta[user][item_name]['成绩'] = score\n",
"\n",
"filename = 'data/result_北海炼化2024.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl, ensure_ascii=False) \n",
"print(len(re_ta))"
]
},
{
"cell_type": "markdown",
"id": "beaccc86-fddc-4207-b0d6-2124800ff0fd",
"metadata": {},
"source": [
"## 导出测试人员信息"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "17ebb0fd-9a45-47a4-bbe9-f4fb0a3481f6",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['lung','grip','flexion','jump','pushup','situp','banlance','reaction','step']\n",
"title = ['编号','姓名','性别','单位','身高','体重','肺活量','握力','坐位体前屈','纵跳','俯卧撑','一分钟仰卧起坐','单脚站立','选择反应时','台阶指数']\n",
"\n",
"filename = 'data/result_北海炼化2024.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"filename = 'data/北海炼化人员2024.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl)\n",
" \n",
"list1 = []\n",
"for k, v in dict1.items():\n",
" list2 = []\n",
" list2.append(str(k).rjust(5,'0'))\n",
" list2.append(v['name']) \n",
" list2.append(dict2[k]['sex'])\n",
" list2.append(dict2[k]['unit'])\n",
" if 'bmi' in v.keys():\n",
" height = v['bmi']['成绩'].split(',')[0]\n",
" weight = v['bmi']['成绩'].split(',')[1]\n",
" list2.append(height)\n",
" list2.append(weight)\n",
" else:\n",
" list2.append('')\n",
" list2.append('')\n",
" for item in items:\n",
" if item in v.keys():\n",
" list2.append(v[item]['成绩']) \n",
" elif item =='name':\n",
" list2.append(v[item])\n",
" else:\n",
" list2.append('')\n",
" \n",
" list1.append(list2)\n",
"filename = 'data/北海炼化体测情况表2024.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet.append(title)\n",
"for row in list1:\n",
" sheet.append(row)\n",
" \n",
"wb.save(filename)"
]
},
{
"cell_type": "markdown",
"id": "0be2a006-d1c9-4c0f-b1e0-ed347aa5b7ad",
"metadata": {},
"source": [
"## 生成测试得分"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "dd89efe8-13b9-4db8-8c39-2a48888dd635",
"metadata": { "metadata": {
"execution": { "execution": {
"iopub.execute_input": "2024-11-23T10:36:27.159751Z", "iopub.execute_input": "2024-11-26T01:21:08.964696Z",
"iopub.status.busy": "2024-11-23T10:36:27.159001Z", "iopub.status.busy": "2024-11-26T01:21:08.963964Z",
"iopub.status.idle": "2024-11-23T10:36:27.181532Z", "iopub.status.idle": "2024-11-26T01:21:09.431950Z",
"shell.execute_reply": "2024-11-23T10:36:27.181062Z", "shell.execute_reply": "2024-11-26T01:21:09.431433Z",
"shell.execute_reply.started": "2024-11-23T10:36:27.159680Z" "shell.execute_reply.started": "2024-11-26T01:21:08.964630Z"
} }
}, },
"outputs": [ "outputs": [
@@ -2243,65 +2327,114 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"159\n", "ok!\n"
"159\n"
] ]
} }
], ],
"source": [ "source": [
"import json\n", "import json\n",
"import time\n", "import time\n",
"import csv\n", "import my_module as My\n",
"\n", "\n",
"filename = '../item.json'\n", "#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
"item = {}\n", "list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
"unit = {}\n", "filename = 'data/result_北海炼化2024.json'\n",
"with open(filename,'r') as fl:\n", "with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n", " dict2 = json.load(fl) \n",
"for k,v in dict1.items():\n", "for k, v in dict2.items():\n",
" item[k] = v\n", " #print(k)\n",
"re_ta = {}\n", " if v['sex'] == '男':\n",
"dict1 = {}\n", " sex = 'M'\n",
"list1 = []\n", " else:\n",
"filename = 'data/北海炼化人员2024.json'\n", " sex = 'F' \n",
"with open(filename,'r') as fl:\n", " if 'bmi' in v.keys():\n",
" dict1 = json.load(fl) \n", " #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
"\n", " bmi_data = v['bmi']['成绩']\n",
"filename = 'data/marks_20241123.csv'\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
"with open(filename,'r',newline='') as csv_file:\n", " dict2[k]['bmi'] = {}\n",
" fl = csv.reader(csv_file,delimiter=',')\n", " dict2[k]['bmi']['成绩'] = bmi_data\n",
" header = next(fl) \n", " dict2[k]['bmi']['score'] = My.cal_bmi(data1)\n",
" for line in fl:\n", " for item_en in list_item:\n",
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n", " if item_en in v.keys(): \n",
" list1.append(line)\n", " data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
"#print(list1)\n", " #print(k,v['name'])\n",
"for result in list1:\n", " dict2[k][item_en]['score'] = My.cal_score(data1)\n",
" user = str(result[2])\n", " #print(k,v[item_en]['成绩'],cal_score(data1))\n",
" if user in dict1.keys(): \n",
" item_name = result[3] \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = dict1[user]['name']\n",
" re_ta[user]['sex'] = dict1[user]['sex'] \n",
" re_ta[user]['unit'] = dict1[user]['unit']\n",
" re_ta[user]['rq'] = result[5].replace('/','-')\n",
" #re_ta[user]['sub_unit'] = dict1[user]['sub_unit'] \n",
" re_ta[user].setdefault(item_name,{})\n",
" re_ta[user][item_name]['成绩'] = result[4]\n",
"print(len(re_ta))\n",
"filename = 'data/result_北海炼化人员2024.json'\n",
"\n", "\n",
"filename = f'data/result_北海炼化2024.json'\n",
"with open(filename,'w') as fl:\n", "with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl, ensure_ascii=False) \n", " json.dump(dict2,fl , ensure_ascii=False) \n",
"print(len(re_ta))" "print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "378982cd-8f4a-4b61-a87c-a138eb891342",
"metadata": {},
"source": [
"## 生成体测成绩明细表"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "7e5d9787-e982-4afd-8d48-83766f5ed1d0", "id": "a1a12409-aab8-47af-b10d-7ecb20b3b332",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"import json\n",
"import openpyxl\n",
"\n",
"items = ['lung','grip','flexion','jump','pushup','situp','balance','reaction','step']\n",
"bmi = ['height','weight']\n",
"title = ['编号','姓名','性别','单位/部门','身高','体重','bmi','肺活量','','握力','','坐位体前屈','','纵跳','','俯卧撑','','一分钟仰卧起坐','','单脚站立','','选择反应时','','台阶指数']\n",
"\n",
"filename = 'data/result_北海炼化2024.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"\n",
"list1 = []\n",
"for k, v in dict1.items(): #print(k,dict2[str(k)]['name'])\n",
" list2 = []\n",
" list2.append(str(k).rjust(5,'0'))\n",
" list2.append(dict1[k]['name']) \n",
" list2.append(dict1[k]['sex'])\n",
" list2.append(dict1[k]['unit'])\n",
" #list2.append(dict1[k]['phone'])\n",
" i = 0\n",
" if 'bmi' in dict1[k].keys():\n",
" list2.append(dict1[k]['height']['成绩'])\n",
" list2.append(dict1[k]['weight']['成绩'])\n",
" list2.append(dict1[k]['bmi']['score'])\n",
" i+=1\n",
" else:\n",
" list2.append('') \n",
" list2.append('') \n",
" list2.append('') \n",
" \n",
" \n",
" for item in items:\n",
" if item in dict1[k].keys():\n",
" list2.append(dict1[k][item]['成绩'])\n",
" list2.append(dict1[k][item]['score']) \n",
" i+=1\n",
" elif item =='name':\n",
" list2.append(dict1[k][item])\n",
" else:\n",
" list2.append('') \n",
" list2.append('') \n",
" if i>2:\n",
" list1.append(list2)\n",
"filename = 'data/北海炼化体测情况表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet.append(title)\n",
"for row in list1:\n",
" sheet.append(row)\n",
" \n",
"wb.save(filename)\n",
"print('ok') "
]
} }
], ],
"metadata": { "metadata": {