This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具/合并使用记录并排序.py

34 lines
1.0 KiB
Python

# 合并相同题目的使用记录
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))