{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import os,re,json\n", "import pandas as pd\n", "#此处输入题号列表\n", "problems = r\"\"\"\n", "4080,4122,4312,4451,4557,4276,30019,4356,4320,4359,30020,4091,4400,8101,4157,4440,4370,4224,4328,4444,4247\n", "\n", "\n", "\"\"\"\n", "outputfile = r\"临时文件/使用记录结果对比.xlsx\"\n", "\n", "def generate_number_set(string):\n", " string = re.sub(r\"[\\n\\s]\",\"\",string)\n", " string_list = string.split(\",\")\n", " numbers_list = []\n", " for s in string_list:\n", " if not \":\" in s:\n", " numbers_list.append(s.zfill(6))\n", " else:\n", " start,end = s.split(\":\")\n", " for ind in range(int(start),int(end)+1):\n", " numbers_list.append(str(ind).zfill(6))\n", " return numbers_list\n", "\n", "problem_list = generate_number_set(problems)\n", "with open(r\"d:/mathdeptv2/题库0.3/problems.json\",\"r\",encoding = \"utf8\") as f:\n", " jsondata = f.read()\n", "pro_dict = json.loads(jsondata)\n", "class_list = []\n", "\n", "df = pd.DataFrame()\n", "\n", "for id in problem_list:\n", " # print(pro_dict[id][\"content\"])\n", " # print(pro_dict[id][\"usages\"])\n", " for usage in pro_dict[id][\"usages\"]:\n", " classname = re.findall(\"([\\S]*届[\\S]*)\",usage)[0]\n", " if not classname in class_list:\n", " class_list.append(classname)\n", "class_list.sort()\n", "df[\"班级\"] = class_list\n", "\n", "for id in problem_list:\n", " parts = 1\n", " for usage in pro_dict[id][\"usages\"]:\n", " parts = max(parts,len(re.findall(r\"\\d\\.[\\d]{3}\",usage)))\n", " # print(id,parts)\n", " if parts == 1:\n", " df[id] = [\"N/A\"]*len(class_list)\n", " for c in range(len(class_list)):\n", " for usage in pro_dict[id][\"usages\"]:\n", " if class_list[c] in usage:\n", " df[id][c] = float(re.findall(r\"\\d\\.[\\d]{3}\",usage)[0])\n", " else:\n", " for j in range(parts):\n", " df[id+\"_\"+str(j+1)] = [\"N/A\"]*len(class_list)\n", " for c in range(len(class_list)):\n", " for usage in pro_dict[id][\"usages\"]:\n", " if class_list[c] in usage:\n", " results = re.findall(r\"\\d\\.[\\d]{3}\",usage)\n", " for t in range(len(results)):\n", " df[id+\"_\"+str(t+1)][c] = float(results[t])\n", "\n", "df.to_excel(outputfile,index = False)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.231" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "float(\"0.231\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.7 ('base')", "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.9.7" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e4cce46d6be9934fbd27f9ca0432556941ea5bdf741d4f4d64c6cd7f8dfa8fba" } } }, "nbformat": 4, "nbformat_minor": 2 }