import json

filename = r"文本文件/题号筛选.txt"
with open(r"..\题库0.3\problems.json","r",encoding = "u8") as f:
    database = f.read()
pro_dict = json.loads(database)
units = ["第一单元","第二单元","第三单元","第四单元","第五单元","第六单元","第七单元","第八单元","第九单元","暂无对应"]
count1 = [0]*10
count2 = [0]*10
count3 = 0
untagged = []
for id in pro_dict:
    for u in range(10):
        unit = units[u]
        if unit in "".join(pro_dict[id]["tags"]):
            count1[u] += 1
            if len(pro_dict[id]["objs"]) > 0:
                count2[u] += 1
    if len(pro_dict[id]["tags"]) == 0:
            count3 += 1
            untagged.append(id)
for u in range(len(units)):
    print(units[u],". 总题数:",count1[u],", 完成对应题数:",count2[u])
print("题库总题数: %d, 已有单元标签题数: %d, 未赋单元标签题数: %d."%(len(pro_dict),len(pro_dict)-count3,count3))
with open (filename,"w",encoding = "u8") as f:
     f.write(",".join(untagged))
print("未赋标签的题号列表已保存至: %s" %filename)
