database_tools中新写了AppendUsageData2024, 更新了判断是否是新使用记录的逻辑
This commit is contained in:
parent
6f1c68c8e4
commit
8acff410b9
|
|
@ -655,6 +655,47 @@ def AppendUsageData(prodict,field_id_and_content): #添加使用记录数据
|
|||
output += "\n".join(oldlist)+"\n\n"
|
||||
return (field,id,content,output) #返回四元组: 题号, 字段, 内容, 待确定是否要添加的字符串(不含FORCE字样的行为旧结果,含FORCE字样的行为新结果,FORCE是运行后强制添加)
|
||||
|
||||
def AppendUsageData2024(prodict,field_id_and_content):
|
||||
field,id,content = field_id_and_content
|
||||
lines = [re.sub(r"\s+",r"\t",line.strip()) for line in content.strip().split("\n")]
|
||||
pending_list = []
|
||||
for line in lines:
|
||||
if not "FORCE" in line.upper():
|
||||
time_stripped = re.sub(r"^\d{4,}\t","",line) #读取去除时间的数据
|
||||
if time_stripped in "\n".join(prodict[id][field]):
|
||||
print(f"******题号 {id} 的 {field} 字段, 内容 {line} 已存在")
|
||||
else:
|
||||
usage = parseUsage(line)
|
||||
oldusages = prodict[id]["usages"]
|
||||
importflag = True
|
||||
for u in oldusages:
|
||||
oldusage = parseUsage(u)
|
||||
if usage["classid"] == oldusage["classid"] and abs(datestrtotimestamp(usage["date"])-datestrtotimestamp(oldusage["date"])) < 7*86400 and usagelistdifference(usage["difficulties"],oldusage["difficulties"])<0.05:
|
||||
print(f"######班级 {usage['classid']} 在题号为 {id} 的题目处已有非常类似的使用记录, 不作记录")
|
||||
importflag = False
|
||||
break
|
||||
elif usage["classid"] == oldusage["classid"]:
|
||||
print(f"!!!!!!班级 {usage['classid']} 在题号为 {id} 的题目处已有使用记录, 在pending list中记录")
|
||||
oldinfo = [v for v in prodict[id][field] if usage['classid'] in v]
|
||||
pending_list = pending_list + [(id,line,oldinfo)]
|
||||
importflag = False
|
||||
break
|
||||
if importflag:
|
||||
prodict[id][field].append(line)
|
||||
print(f"已于 {id} 的 {field} 字段执行添加, 内容为 {line}")
|
||||
else:
|
||||
line = re.sub(r"\s+",r"\t",re.sub(r"FORCE","",line.upper())).strip()
|
||||
prodict[id][field].append(line)
|
||||
print(f"&&&&&&&&&&&& 已于 {id} 的 {field} 字段执行强制添加, 内容为 {line} &&&&&&")
|
||||
output = ""
|
||||
for item in pending_list:
|
||||
id,new,oldlist = item
|
||||
output += id + "\n"
|
||||
output += new+"\tFORCE\n"
|
||||
output += "\n".join(oldlist)+"\n\n"
|
||||
return (field,id,content,output) #返回四元组: 题号, 字段, 内容, 待确定是否要添加的字符串(不含FORCE字样的行为旧结果,含FORCE字样的行为新结果,FORCE是运行后强制添加)
|
||||
|
||||
|
||||
def ImportMetadata(prodict,objdict,fieldsdict,metadatafilepath,pendingdatafilepath): #metadata自动修改, 根据字段自适应修改, 参数为题库字典, 目标字典, 字段字典, metadata文本文件路径, 待确定是否替换的内容的存放路径
|
||||
data_to_modify = ObtainDatatoModify(metadatafilepath,fieldsdict)
|
||||
outputstring = "usages\n\n"
|
||||
|
|
|
|||
Reference in New Issue