对筛选题目所得的题目按照题目个数选择可能更快的速度生成LaTeX文件(先生成总字典还是注意用SQL语句查询)
This commit is contained in:
parent
c438ff7002
commit
8a1c35641a
|
|
@ -1537,7 +1537,7 @@ def GenerateObjTexCode(id,prodict,objdict): #生成目标代号对应的学习
|
|||
if objid.upper() == "KNONE":
|
||||
string += "\n\n%s\t%s"%(objid,"无当前有效关联目标")
|
||||
else:
|
||||
string += "\n\n%s\t%s"%(objid,objdict[objid]["content"])
|
||||
string += "\n\n%s\t%s"%(objid,objdict[objid]["objcontent"])
|
||||
if prodict[id]["objs"] == []:
|
||||
string += "暂未关联\n"
|
||||
string += "\n\n\\end{tcolorbox}\n"
|
||||
|
|
@ -1702,6 +1702,67 @@ def generateDictsfromMariaDB(mycursor):
|
|||
bn_dict[ret[0]]["objs"].append(ret[1])
|
||||
return pro_dict,obj_dict,bn_dict,unit_obj_dict
|
||||
|
||||
def generateLaTeXBodyContentFromDict(id,adict,objdict,misc): #根据id,读取的json内容adict,和字典misc来生成讲义
|
||||
#misc 样例
|
||||
#{
|
||||
# "教师版": True, #如果设置为True则除了 题后空间 之外都进行判断并处理, 否则只处理 题后空间 和 答案
|
||||
# "字段显示设置": {
|
||||
# "题后空间": True,
|
||||
# "课时目标": True,
|
||||
# "题目标签": True,
|
||||
# "答案": True,
|
||||
# "解答与提示": True,
|
||||
# "使用记录": (3,-1),
|
||||
# "使用记录说明": "(a,b)表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||
# "来源": True,
|
||||
# "备注": True,
|
||||
# "届别": []
|
||||
# }
|
||||
# }
|
||||
id = str(id).zfill(6)
|
||||
if not "教师版" in misc or misc["教师版"] == False:
|
||||
output = f"\n\\item {{\\tiny ({id})}} {adict[id]['content']}"
|
||||
if "字段显示设置" in misc and "答案" in misc["字段显示设置"] and misc["字段显示设置"]["答案"] == True:
|
||||
ans = adict[id]["ans"] if not adict[id]["ans"] is None else "暂无答案"
|
||||
output += f"\n\n答案: \\textcolor{{{('red' if ans != '暂无答案' else 'blue')}}}{{{ans}}}\n\n"
|
||||
if "字段显示设置" in misc and "题后空间" in misc["字段显示设置"] and misc["字段显示设置"]["题后空间"] == True:
|
||||
space = f"\n\n\\vspace*{{{adict[id]['space']}}}\n\n" if len(adict[id]["space"]) > 0 else ""
|
||||
output += space
|
||||
else:
|
||||
output = f"\n\\item ({id}) {adict[id]['content']}"
|
||||
if "备注" in misc["字段显示设置"] and misc["字段显示设置"]["备注"] == True:
|
||||
remark = r"\\".join(adict[id]["remark"]) if len(adict[id]["remark"]) > 0 else "暂无备注"
|
||||
output += f"\n\n备注: \\textcolor[rgb]{{0,0.5,0.2}}{{{remark}}}\n\n"
|
||||
if "课时目标" in misc["字段显示设置"] and misc["字段显示设置"]["课时目标"] == True:
|
||||
objs = f"\n\n目标:\n\n{GenerateObjTexCode(id,adict,objdict)}\n\n"
|
||||
output += objs
|
||||
if "题目标签" in misc["字段显示设置"] and misc["字段显示设置"]["题目标签"] == True:
|
||||
tags_raw = adict[id]['tags']
|
||||
if len(tags_raw) == 0:
|
||||
tags = "暂无标签"
|
||||
else:
|
||||
tags = '; '.join(adict[id]['tags'])
|
||||
output += f"\n\n标签: \\textcolor[rgb]{{0.5,0.6,0.8}}{{{tags}}}\n\n"
|
||||
if "答案" in misc["字段显示设置"] and misc["字段显示设置"]["答案"] == True:
|
||||
ans = adict[id]["ans"] if not (adict[id]["ans"]) is None else "暂无答案"
|
||||
output += f"\n\n答案: \\textcolor{{{('red' if ans != '暂无答案' else 'blue')}}}{{{ans}}}\n\n"
|
||||
if "解答与提示" in misc["字段显示设置"] and misc["字段显示设置"]["解答与提示"] == True:
|
||||
solution = adict[id]["solution"] if not adict[id]["solution"] is None else "暂无解答或提示"
|
||||
output += f"\n\n解答或提示: \\textcolor{{magenta}}{{{solution}}}\n\n"
|
||||
if "使用记录" in misc["字段显示设置"] and type(misc["字段显示设置"]["使用记录"]) in (list,tuple) and not -2 in misc["字段显示设置"]["使用记录"]:
|
||||
usages = f"\n\n使用记录:\n\n{GenerateUsageTexCodeFromDict(id,adict,misc['字段显示设置']['使用记录'])}\n\n"
|
||||
output += usages
|
||||
if "来源" in misc["字段显示设置"] and misc["字段显示设置"]["来源"] == True:
|
||||
origin = generate_origin(adict[id]["origin"]) if len(adict[id]["origin"]) > 0 else "未记录来源"
|
||||
output += f"\n\n来源: {origin}\n\n"
|
||||
return output
|
||||
|
||||
|
||||
def GenerateUsageTexCodeFromDict(id,prodict,topandbottomusagestuple): #根据topandbottomusagestuple的要求生成题号为id的题目的缩减版的使用记录列表, topandbottomusagestuple表示保留得分率最高的使用记录与最低的使用记录的个数, 有负数表示不排列, 两数之和大于记录数则从高到低排列后全部展示
|
||||
rawusages = prodict[id]["usages"].copy()
|
||||
usages = ChooseUsage(rawusages,topandbottomusagestuple)
|
||||
usagecode = re.sub("\\t([\d]\.[\d]{0,10})",GenerateValueColorCode,"\n\n".join(usages))
|
||||
return usagecode #返回缩减后的使用记录列表
|
||||
|
||||
def generateLaTeXBodyContentfromMariaDB(cursor,id,misc): #根据id,读取的json内容adict,和字典misc来生成讲义
|
||||
#misc 样例
|
||||
|
|
|
|||
|
|
@ -117,8 +117,14 @@ class MyWindow_sxth(QWidget,Ui_Form):
|
|||
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
|
||||
mycursor = mydb.cursor()
|
||||
bodystring = "\\begin{enumerate}\n\n"
|
||||
for id in tqdm.tqdm(generate_number_set(exp)):
|
||||
bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson)
|
||||
pid_list = generate_number_set(exp)
|
||||
if len(pid_list) < 10:
|
||||
for id in tqdm.tqdm(pid_list):
|
||||
bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson)
|
||||
else:
|
||||
pro_dict,obj_dict,bn_dict,unit_obj_dict = generateDictsfromMariaDB(mycursor)
|
||||
for id in tqdm.tqdm(pid_list):
|
||||
bodystring += generateLaTeXBodyContentFromDict(id,pro_dict,obj_dict,configjson)
|
||||
bodystring += "\\end{enumerate}\n\n"
|
||||
|
||||
midtime = time.time()
|
||||
|
|
|
|||
Reference in New Issue