修正分年级数据导入中的一个日期bug并增加了全卷自动对应题号功能

This commit is contained in:
WangWeiye 2023-05-26 15:16:50 +08:00
parent e69be89dc1
commit 2ab2e98655
1 changed files with 18 additions and 67 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
@ -10,7 +10,7 @@
"import pandas as pd\n",
"from pathlib import Path\n",
"\n",
"#设置工作目录, 要求工作目录中恰有一个.tex文件和一个.zip文件其余不论\n",
"#设置工作目录, 要求工作目录中恰有一些.tex(.txt)文件和一些.zip文件对应的文件名需相同, 其余不论\n",
"filepath = \"数据导入作业文件\"\n",
"\n",
"# date = str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2)\n",
@ -29,6 +29,10 @@
" #生成文件名tex_file和zip_file\n",
" zip_file, tex_file = fp\n",
"\n",
" newdate = input(os.path.split(zip_file)[-1][:4]+\"使用日期(\"+date+\", 不变按回车, 要变化仅需输入最后几位改变的数字):\")\n",
" newdate = \"\".join(re.findall(r\"\\d\",newdate))\n",
" change_len = len(newdate)\n",
" date = date[:8-change_len]+newdate\n",
"\n",
" #获得题号数据保存在problems_list中\n",
" with open(tex_file,\"r\",encoding = \"utf8\") as f:\n",
@ -47,12 +51,20 @@
" extractedpath.rename(\"临时文件/statsfile.xlsx\")\n",
" df = pd.read_excel(\"临时文件/statsfile.xlsx\")\n",
" problems_indexes = list(df[df.columns[0]][2:])\n",
" autofill = False\n",
" for p in problems_indexes:\n",
" t = input(os.path.split(zip_file)[-1][:4]+\"答题纸区域\"+p+\"的题号为(1-\"+str(len(problems_list))+\", a为自动对应点前的题号):\")\n",
" if not autofill:\n",
" t = input(os.path.split(zip_file)[-1][:4]+\"答题纸区域\"+p+\"的题号为(1-\"+str(len(problems_list))+\", a为自动对应点前的题号, u为之后完全自动对应):\")\n",
" if t.upper() == \"A\":\n",
" correspondence_dict[p] = problems_list[int(re.findall(r\"([\\d]+?)\\.\",p)[0])-1]\n",
" elif t.upper() == \"U\":\n",
" correspondence_dict[p] = problems_list[int(re.findall(r\"([\\d]+?)\\.\",p)[0])-1]\n",
" autofill = True\n",
" elif not (int(t)<1 or int(t)>len(problems_list)):\n",
" correspondence_dict[p] = problems_list[int(t)-1] \n",
" correspondence_dict[p] = problems_list[int(t)-1]\n",
" else:\n",
" correspondence_dict[p] = problems_list[int(re.findall(r\"([\\d]+?)\\.\",p)[0])-1]\n",
"\n",
"\n",
"\n",
"\n",
@ -85,67 +97,6 @@
"zf.close()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"''"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"t"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('数据导入作业文件', 'sj02.zip')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"os.path.split(zip_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {