128 lines
8.6 KiB
Plaintext
128 lines
8.6 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"ename": "KeyboardInterrupt",
|
||
"evalue": "Interrupted by user",
|
||
"output_type": "error",
|
||
"traceback": [
|
||
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
|
||
"\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
||
"Cell \u001b[1;32mIn[2], line 31\u001b[0m\n\u001b[0;32m 29\u001b[0m problems_indexes \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(df[df\u001b[39m.\u001b[39mcolumns[\u001b[39m0\u001b[39m]][\u001b[39m2\u001b[39m:])\n\u001b[0;32m 30\u001b[0m \u001b[39mfor\u001b[39;00m p \u001b[39min\u001b[39;00m problems_indexes:\n\u001b[1;32m---> 31\u001b[0m t \u001b[39m=\u001b[39m \u001b[39minput\u001b[39;49m(\u001b[39m\"\u001b[39;49m\u001b[39m答题纸区域\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m+\u001b[39;49mp\u001b[39m+\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m的题号为(1-\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m+\u001b[39;49m\u001b[39mstr\u001b[39;49m(\u001b[39mlen\u001b[39;49m(problems_list))\u001b[39m+\u001b[39;49m\u001b[39m\"\u001b[39;49m\u001b[39m, a为自动对应点前的题号):\u001b[39;49m\u001b[39m\"\u001b[39;49m)\n\u001b[0;32m 32\u001b[0m \u001b[39mif\u001b[39;00m t\u001b[39m.\u001b[39mupper() \u001b[39m==\u001b[39m \u001b[39m\"\u001b[39m\u001b[39mA\u001b[39m\u001b[39m\"\u001b[39m:\n\u001b[0;32m 33\u001b[0m correspondence_dict[p] \u001b[39m=\u001b[39m problems_list[\u001b[39mint\u001b[39m(re\u001b[39m.\u001b[39mfindall(\u001b[39mr\u001b[39m\u001b[39m\"\u001b[39m\u001b[39m([\u001b[39m\u001b[39m\\\u001b[39m\u001b[39md]+?)\u001b[39m\u001b[39m\\\u001b[39m\u001b[39m.\u001b[39m\u001b[39m\"\u001b[39m,p)[\u001b[39m0\u001b[39m])\u001b[39m-\u001b[39m\u001b[39m1\u001b[39m]\n",
|
||
"File \u001b[1;32mc:\\Users\\weiye\\.conda\\envs\\mathdept\\lib\\site-packages\\ipykernel\\kernelbase.py:1175\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m 1171\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_allow_stdin:\n\u001b[0;32m 1172\u001b[0m \u001b[39mraise\u001b[39;00m StdinNotImplementedError(\n\u001b[0;32m 1173\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 1174\u001b[0m )\n\u001b[1;32m-> 1175\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_input_request(\n\u001b[0;32m 1176\u001b[0m \u001b[39mstr\u001b[39;49m(prompt),\n\u001b[0;32m 1177\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49m_parent_ident[\u001b[39m\"\u001b[39;49m\u001b[39mshell\u001b[39;49m\u001b[39m\"\u001b[39;49m],\n\u001b[0;32m 1178\u001b[0m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mget_parent(\u001b[39m\"\u001b[39;49m\u001b[39mshell\u001b[39;49m\u001b[39m\"\u001b[39;49m),\n\u001b[0;32m 1179\u001b[0m password\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m,\n\u001b[0;32m 1180\u001b[0m )\n",
|
||
"File \u001b[1;32mc:\\Users\\weiye\\.conda\\envs\\mathdept\\lib\\site-packages\\ipykernel\\kernelbase.py:1217\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m 1214\u001b[0m \u001b[39mbreak\u001b[39;00m\n\u001b[0;32m 1215\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m 1216\u001b[0m \u001b[39m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[1;32m-> 1217\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mKeyboardInterrupt\u001b[39;00m(\u001b[39m\"\u001b[39m\u001b[39mInterrupted by user\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39mfrom\u001b[39;00m \u001b[39mNone\u001b[39m\n\u001b[0;32m 1218\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mException\u001b[39;00m:\n\u001b[0;32m 1219\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mlog\u001b[39m.\u001b[39mwarning(\u001b[39m\"\u001b[39m\u001b[39mInvalid Message:\u001b[39m\u001b[39m\"\u001b[39m, exc_info\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n",
|
||
"\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"import zipfile,os,re,time\n",
|
||
"import pandas as pd\n",
|
||
"from pathlib import Path\n",
|
||
"\n",
|
||
"#设置工作目录, 要求工作目录中恰有一个.tex文件和一个.zip文件,其余不论\n",
|
||
"filepath = \"数据导入作业文件\"\n",
|
||
"\n",
|
||
"#生成文件名tex_file和zip_file\n",
|
||
"files = [os.path.join(filepath,f) for f in os.listdir(filepath)]\n",
|
||
"tex_file = [f for f in files if \".tex\" in f or \".txt\" in f][0]\n",
|
||
"zip_file = [f for f in files if \".zip\" in f][0]\n",
|
||
"\n",
|
||
"#获得题号数据,保存在problems_list中\n",
|
||
"with open(tex_file,\"r\",encoding = \"utf8\") as f:\n",
|
||
" tex_data = f.read()\n",
|
||
"problems_list = re.findall(r\"\\(([\\d]{6})\\)\",tex_data)\n",
|
||
"\n",
|
||
"#在zip文件中找到包含正确率数据的文件\n",
|
||
"zf = zipfile.ZipFile(zip_file)\n",
|
||
"statfiles = [f.filename for f in zf.filelist if \"试题分析\" in f.filename]\n",
|
||
"\n",
|
||
"#生成答题纸区域编号与题目ID的对应\n",
|
||
"correspondence_dict = {}\n",
|
||
"if \"statsfile.xlsx\" in os.listdir(\"临时文件\"):\n",
|
||
" os.remove(\"临时文件/statsfile.xlsx\")\n",
|
||
"extractedpath = Path(zf.extract(statfiles[0]))\n",
|
||
"extractedpath.rename(\"临时文件/statsfile.xlsx\")\n",
|
||
"df = pd.read_excel(\"临时文件/statsfile.xlsx\")\n",
|
||
"problems_indexes = list(df[df.columns[0]][2:])\n",
|
||
"for p in problems_indexes:\n",
|
||
" t = input(\"答题纸区域\"+p+\"的题号为(1-\"+str(len(problems_list))+\", a为自动对应点前的题号):\")\n",
|
||
" if t.upper() == \"A\":\n",
|
||
" correspondence_dict[p] = problems_list[int(re.findall(r\"([\\d]+?)\\.\",p)[0])-1]\n",
|
||
" elif not (int(t)<1 or int(t)>len(problems_list)):\n",
|
||
" correspondence_dict[p] = problems_list[int(t)-1] \n",
|
||
"\n",
|
||
"outputstr = \"usages\\n\\n\"\n",
|
||
"\n",
|
||
"for sf in statfiles:\n",
|
||
" #读取文件生成区域列表与难度列表\n",
|
||
" classname = \"2023届高三\"+re.findall(r\"高三([\\d]*?)班\",sf)[0].zfill(2)+\"班\"\n",
|
||
" date = str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2)\n",
|
||
" if \"statsfile.xlsx\" in os.listdir(\"临时文件\"):\n",
|
||
" os.remove(\"临时文件/statsfile.xlsx\")\n",
|
||
" extractedpath = Path(zf.extract(sf))\n",
|
||
" extractedpath.rename(\"临时文件/statsfile.xlsx\")\n",
|
||
" df = pd.read_excel(\"临时文件/statsfile.xlsx\")\n",
|
||
" difficulties = list(df[df.columns[9]][2:])\n",
|
||
" problems_indexes = list(df[df.columns[0]][2:])\n",
|
||
" #生成该班级题目ID对应难度列表组成的字典\n",
|
||
" class_difficulty = {}\n",
|
||
" for i in range(len(difficulties)):\n",
|
||
" if problems_indexes[i] in correspondence_dict:\n",
|
||
" if not correspondence_dict[problems_indexes[i]] in class_difficulty:\n",
|
||
" class_difficulty[correspondence_dict[problems_indexes[i]]] = [difficulties[i]]\n",
|
||
" else:\n",
|
||
" class_difficulty[correspondence_dict[problems_indexes[i]]].append(difficulties[i])\n",
|
||
" #添加到输出字符串中\n",
|
||
" for id in class_difficulty:\n",
|
||
" outputstr += id + \"\\n\" + date + \"\\t\" + classname + \"\\t\" + \"\\t\".join([(\"%.3f\" %float(v)) for v in class_difficulty[id]]) + \"\\n\\n\"\n",
|
||
"\n",
|
||
"with open(\"临时文件/自动转换结果.txt\",\"w\",encoding = \"utf8\") as f:\n",
|
||
" f.write(outputstr)\n",
|
||
"with open(\"../文本文件/metadata.txt\",\"w\",encoding = \"utf8\") as f:\n",
|
||
" f.write(outputstr)\n",
|
||
"zf.close()\n",
|
||
"\n"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": []
|
||
}
|
||
],
|
||
"metadata": {
|
||
"kernelspec": {
|
||
"display_name": "mathdept",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.8.15"
|
||
},
|
||
"orig_nbformat": 4,
|
||
"vscode": {
|
||
"interpreter": {
|
||
"hash": "42dd566da87765ddbe9b5c5b483063747fec4aacc5469ad554706e4b742e67b2"
|
||
}
|
||
}
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|