From ff5f16d5405148216a81e25bb8bddc8c0c87dc0d Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Wed, 26 Apr 2023 21:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=20=E5=90=88=E5=B9=B6?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=AE=B0=E5=BD=95=E5=B9=B6=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=20=E5=B7=A5=E5=85=B7=E5=B9=B6=E5=8A=A0=E5=85=A5=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具/合并使用记录并排序.py | 34 ++++++++++++++++++++++++++++++++++ 工具/工具面板.py | 3 +++ 2 files changed, 37 insertions(+) create mode 100644 工具/合并使用记录并排序.py diff --git a/工具/合并使用记录并排序.py b/工具/合并使用记录并排序.py new file mode 100644 index 00000000..62786bde --- /dev/null +++ b/工具/合并使用记录并排序.py @@ -0,0 +1,34 @@ +# 合并相同题目的使用记录 + +import re,json,os + +with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f: + database = f.read() +pro_dict = json.loads(database) +same_groups = [] + +# 生成有使用记录的相同题目组 +for id in pro_dict: + same = pro_dict[id]["same"] + if not len(pro_dict[id]["usages"]) == 0 and len(same) > 0: + same_groups.append([id]+same) + +# 合并使用记录并排序 +for same_group in same_groups: + current_usages = [] + for id in same_group: + for usage in pro_dict[id]["usages"]: + if not usage in current_usages: + current_usages.append(usage) + current_usages.sort() + for id in same_group: + pro_dict[id]["usages"] = current_usages.copy() + +# 对所有使用记录排序 +for id in pro_dict: + usages = pro_dict[id]["usages"].copy() + usages.sort() + pro_dict[id]["usages"] = usages.copy() + +with open(r"../题库0.3/Problems.json","w",encoding = "u8") as f: + f.write(json.dumps(pro_dict,indent = 4, ensure_ascii= False)) \ No newline at end of file diff --git a/工具/工具面板.py b/工具/工具面板.py index 84c72591..2fe1a11a 100644 --- a/工具/工具面板.py +++ b/工具/工具面板.py @@ -106,6 +106,8 @@ def run_command1(): call(["python","错题重做来源清点.py"]) elif selectedtool == "统考数据导入": call(["python","统考数据导入.py"]) + elif selectedtool == "合并使用记录并排序": + call(["python","合并使用记录并排序.py"]) LabelTool.config(text = selectedtool+"STEP1命令执行完毕") button1.place_forget() @@ -148,6 +150,7 @@ MaintainenceMenu = Menu(menubar, tearoff = False) menubar.add_cascade(label = "维护", menu = MaintainenceMenu) MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("批量添加字段数据",1,["文本文件/metadata.txt","批量添加字段数据.py"])) MaintainenceMenu.add_command(label = "手动统计结果转换", command = lambda: SetButton("手动统计结果转换",1,["文本文件/metadata.txt","文本文件/手动统计结果.txt"])) +MaintainenceMenu.add_command(label = "合并使用记录并排序", command = lambda: SetButton("合并使用记录并排序",1,[])) MaintainenceMenu.add_separator() MaintainenceMenu.add_command(label = "LaTeX界面修改题目内容", command = lambda: SetButton("latex修改题目",2,["latex界面修改题目内容.py"])) MaintainenceMenu.add_command(label = "修改题目综合信息", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"]))