This commit is contained in:
512song committed 2025-09-22 12:39:11 +08:00
1 parent 689c26b967
commit ba6f6b413a
2 files changed
+506 -6

No files matched your search

+229 -6
View File
@@ -4,7 +4,6 @@
"cell_type": "markdown",
"id": "1c72f0cf-165b-4025-af9d-6771e4a0a5d1",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@@ -114,7 +113,96 @@
" score = int(result[1])/item[m_item]['divisor'] \n",
" re_ta[user][item_name]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" re_ta[user][item_name]['得分'] =result[2]\n",
"filename = 'data/result_北海炼化2022.json'\n",
"filename = 'data/result_北海炼化2022-1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "d2598172-cede-4baa-920e-3d676c079b7b",
"metadata": {
"execution": {
"iopub.execute_input": "2025-09-17T01:50:24.312281Z",
"iopub.status.busy": "2025-09-17T01:50:24.311666Z",
"iopub.status.idle": "2025-09-17T01:50:24.427182Z",
"shell.execute_reply": "2025-09-17T01:50:24.426684Z",
"shell.execute_reply.started": "2025-09-17T01:50:24.312223Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import csv\n",
"from datetime import date,datetime\n",
"\n",
"\n",
"filename = '../item.json'\n",
"item = {}\n",
"unit = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"for k,v in dict1.items():\n",
" item[k] = v\n",
"\n",
"filename = 'data/北海炼化人员_2022.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"\n",
"re_ta = {}\n",
"dict1 = {}\n",
"list1 = []\n",
"#print(\"\\n运动项目信息:\")\n",
"filename = 'data/138_2210.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",
"for result in list1:\n",
" user = str(result[4])\n",
" m_item = str(result[0]) \n",
" re_ta.setdefault(user,{}) \n",
" re_ta[user]['name'] = str(result[6])\n",
" re_ta[user]['unit'] = str(result[5]) \n",
" \n",
" #re_ta[user]['rq'] = str(result[3]).replace('/','-')\n",
" date_obj = datetime.strptime(result[3], \"%Y/%m/%d\")\n",
" re_ta[user]['rq'] = date_obj.strftime('%Y-%m-%d')\n",
" \n",
" \n",
" \n",
" #item_name = item[m_item]['name']\n",
" re_ta[user].setdefault(m_item,{}) \n",
" score = int(result[1])/item[m_item]['divisor'] \n",
" re_ta[user][m_item]['成绩'] = f'{score} {item[m_item][\"unit\"]}'\n",
" #re_ta[user][item_name]['得分'] =result[2]\n",
"for k,v in re_ta.items():\n",
" v['birth'] = dict2[k]['birth']\n",
" birth = date.fromisoformat(dict2[k]['birth'].replace('/','-'))\n",
" rq = date.fromisoformat(re_ta[user]['rq'].replace('/','-'))\n",
" days = (rq-birth).days \n",
" v['days'] = days\n",
" v['age'] = int(days/365)\n",
" v['sex'] = dict2[k]['sex']\n",
" if 'height' in v.keys() and 'height' in v.keys():\n",
" v.setdefault('bmi',{})\n",
" v['bmi']['成绩'] = v['height']['成绩'].split()[0]+','+v['weight']['成绩'].split()[0]\n",
" \n",
"filename = 'data/result_北海炼化2022-1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(re_ta, fl) \n",
"print('ok')"
@@ -636,6 +724,7 @@
"cell_type": "markdown",
"id": "c103301b-d540-4bf5-861a-0eb2e313e26e",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@@ -1982,7 +2071,9 @@
{
"cell_type": "markdown",
"id": "a51dadfb-30e7-40f3-a437-321aa986a10f",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"# 北海体检情况汇总"
]
@@ -2089,9 +2180,7 @@
{
"cell_type": "markdown",
"id": "76c5c17a-462d-4a7b-95a5-6b895f5a25dc",
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"metadata": {},
"source": [
"# 2024年体质检测"
]
@@ -2353,6 +2442,64 @@
"print('ok!') "
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "c5846968-1f2e-46b5-a79c-e2f129e5c233",
"metadata": {
"execution": {
"iopub.execute_input": "2025-09-17T01:51:05.541822Z",
"iopub.status.busy": "2025-09-17T01:51:05.541072Z",
"iopub.status.idle": "2025-09-17T01:51:05.595736Z",
"shell.execute_reply": "2025-09-17T01:51:05.595210Z",
"shell.execute_reply.started": "2025-09-17T01:51:05.541754Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok!\n"
]
}
],
"source": [
"import json\n",
"import time\n",
"import my_module as My\n",
"\n",
"#list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp','height','weight']\n",
"list_item = ['lung','grip','flexion','jump','pushup','balance','reaction','step','situp']\n",
"filename = 'data/result_北海炼化2022-1.json'\n",
"with open(filename,'r') as fl:\n",
" dict2 = json.load(fl) \n",
"for k, v in dict2.items():\n",
" #print(k)\n",
" if v['sex'] == '男':\n",
" sex = 'M'\n",
" else:\n",
" sex = 'F' \n",
" if 'bmi' in v.keys():\n",
" #bmi_data = v['height']['成绩'].split()[0]+','+ v['weight']['成绩'].split()[0]\n",
" bmi_data = v['bmi']['成绩']\n",
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':'HeightWeight','result':bmi_data}\n",
" dict2[k]['bmi'] = {}\n",
" dict2[k]['bmi']['成绩'] = bmi_data\n",
" dict2[k]['bmi']['score'] = My.cal_bmi(data1)\n",
" for item_en in list_item:\n",
" if item_en in v.keys(): \n",
" data1 = {'code':k,'sex':sex,'age':v['age'],'item':item_en,'result':float(v[item_en]['成绩'].split()[0])}\n",
" #print(k,v['name'])\n",
" dict2[k][item_en]['score'] = My.cal_score(data1)\n",
" #print(k,v[item_en]['成绩'],cal_score(data1))\n",
"\n",
"filename = f'data/result_北海炼化2022-1.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict2,fl , ensure_ascii=False) \n",
"print('ok!') "
]
},
{
"cell_type": "markdown",
"id": "5b9aef88-0341-4af0-8316-c7e2266f4b0c",
@@ -2650,6 +2797,82 @@
"print('ok') "
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "98e43475-06ca-42bc-b352-5c92a554e2c2",
"metadata": {
"execution": {
"iopub.execute_input": "2025-09-17T02:01:52.580879Z",
"iopub.status.busy": "2025-09-17T02:01:52.580448Z",
"iopub.status.idle": "2025-09-17T02:01:52.867257Z",
"shell.execute_reply": "2025-09-17T02:01:52.866600Z",
"shell.execute_reply.started": "2025-09-17T02:01:52.580841Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ok\n"
]
}
],
"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_北海炼化2022-1.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",
" i = 0\n",
" if 'bmi' in dict1[k].keys():\n",
" list2.append(dict1[k]['bmi']['成绩'].split(',')[0])\n",
" list2.append(dict1[k]['bmi']['成绩'].split(',')[1])\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/北海炼化体测情况明细表(2022年).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') "
]
},
{
"cell_type": "markdown",
"id": "b46477dd-f9d0-40b8-ae25-62f3ffb5dc1e",