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