From 70437821ab24e2b501433371e6858ae92d20a495 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Wed, 28 Jun 2023 22:54:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=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=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/database_tools.py | 28 ++++++++++++++++++++++++++++ 工具v2/合并使用记录并排序.py | 11 +++++++++++ 2 files changed, 39 insertions(+) create mode 100644 工具v2/合并使用记录并排序.py diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 48750840..66e21a4d 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -600,5 +600,33 @@ def jsonEditProblemMetadata(id_string,prodict,editor): #用vscode在json模式 editlist.append(id) return(generate_exp(editlist)) # 返回编辑过的题号字符串 +def GetSamePairs(prodict): #获取已标注的相同题目组 + same_groups = [] + for id in prodict: + same = prodict[id]["same"] + if len(same) > 0 and not len(prodict[id]["usages"]) == 0: + same_groups.append([id]+same) + return(same_groups) #返回相同题目组, 每组由一些相同的题目构成 + +def ShareSameUsages(prodict,same_group): #对same_group中的所有题号共享使用记录 + current_usages = [] + for id in same_group: + for usage in prodict[id]["usages"]: + if not usage in current_usages: + current_usages = current_usages + [usage] + for id in same_group: + prodict[id]["usages"] = current_usages.copy() + return((same_group,current_usages)) #返回same_group中的题号列表 及 所有题号记录 组成的二元组 + +def SortUsages(prodict): + for id in prodict: + usages = prodict[id]["usages"].copy() + usages.sort() + prodict[id]["usages"] = usages.copy() + return 0 #返回0 + + + + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file diff --git a/工具v2/合并使用记录并排序.py b/工具v2/合并使用记录并排序.py new file mode 100644 index 00000000..45329094 --- /dev/null +++ b/工具v2/合并使用记录并排序.py @@ -0,0 +1,11 @@ +prodictpath = "../题库0.3/Problems.json" + +from database_tools import * + + +prodict = load_dict(prodictpath) +same_groups = GetSamePairs(prodict) +for sg in same_groups: + ShareSameUsages(prodict,sg) +SortUsages(prodict) +save_dict(prodict,prodictpath) \ No newline at end of file