From 677b35bd3e0459265c60346bc86c9761507f88fd Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 15 Apr 2024 20:30:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E5=88=97=E8=AE=B2=E4=B9=89=E7=94=9F?= =?UTF-8?q?=E6=88=90=20=E5=8A=9F=E8=83=BD=20=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/database_tools_2.py | 97 ++++++++++++++++---------------------- 工具v3/系列讲义生成.py | 2 + 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 5dc596fd..1d840e2c 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -1080,18 +1080,14 @@ def GenerateSectionBodyStringfromMariaDB(cursor,problems,sectiontitles,misc,cons idlist = problems[i].split(",") sectionstring = f"\\section{{{sectiontitles[i]}}}\n\\begin{{enumerate}}\n\n" for objid in idlist: - sectionstring += f"\\item {objid} \\ {(obj_dict[objid]['content'] if objid in obj_dict else '目标编号有误')}\n\n" + sectionstring += generateLaTeXobjsfromMariaDB(cursor,objid) sectionstring += "\\end{enumerate}\n\n" bodystring += sectionstring if problems[i][0] == "B": idlist = problems[i].split(",") sectionstring = f"\\section{{{sectiontitles[i]}}}\n\\begin{{enumerate}}\n\n" - for bkid in idlist: - if bkid in bk_dict: - bk = bk_dict[bkid]["content"] - else: - bk = bkid + " \\ 基础知识编号有误" - sectionstring += f"\\item {(bk)}\n\n" + for bnid in idlist: + sectionstring += generateLaTeXbnsfromMariaDB(cursor,bnid) sectionstring += "\\end{enumerate}\n\n" bodystring += sectionstring return bodystring #返回主题内容字符串 @@ -1188,11 +1184,14 @@ def GenerateUsageTexCode(usage_list_raw,misc): #根据topandbottomusagestuple的 grade = misc["字段显示设置"]["届别"] topandbottomusagestuple = misc["字段显示设置"]["使用记录"] usage_list = [] - for u in usage_list_raw: - for g in grade: - if re.findall(g,u[1]) != []: - usage_list.append(u) - break + if len(grade) == 0: + usage_list = usage_list_raw.copy() + else: + for u in usage_list_raw: + for g in grade: + if re.findall(g,u[1]) != []: + usage_list.append(u) + break usages = ChooseUsage(usage_list,topandbottomusagestuple) usages_str = ["\t".join((u[0],u[1],("\t".join(u[2])))) for u in usages] usagecode = re.sub("\\t([\d]\.[\d]{0,10})",GenerateValueColorCode,"\n\n".join(usages_str)) @@ -1228,13 +1227,14 @@ def generateLaTeXBodyContentfromMariaDB(cursor,id,misc): #根据id,读取的json #以下生成obj_list sql = "SELECT obj_ID FROM objcorresp WHERE ID = %s;" cursor.execute(sql,val) + ret_list = cursor.fetchall() obj_list = [] - for id_raw in cursor.fetchall(): + for id_raw in ret_list: obj_id = id_raw[0] sql = "SELECT obj_content FROM lessonobj WHERE objid = %s;" objval = (obj_id,) cursor.execute(sql,objval) - obj_list.append((obj_id,cursor.fetchall()[0][0])) + obj_list.append(f"{obj_id}\t{cursor.fetchall()[0][0]}") sql = "SELECT tagname FROM tagcorresp WHERE ID = %s;" cursor.execute(sql,val) tag_list = [t[0] for t in cursor.fetchall()] @@ -1243,7 +1243,8 @@ def generateLaTeXBodyContentfromMariaDB(cursor,id,misc): #根据id,读取的json remark_list = sorted([f"{t[0]}\t{t[1]}" for t in cursor.fetchall()]) sql = "SELECT date,classname,diff FROM usages WHERE ID = %s;" cursor.execute(sql,val) - usages_raw = sorted([(t[0],t[1],json.loads(t[2])) for t in cursor.fetchall()]) + usages_fetched = [(u[0] if not u[0] is None else "",u[1],json.loads(u[2])) for u in cursor.fetchall()] + usages_raw = sorted(usages_fetched) if not "教师版" in misc or misc["教师版"] == False: output = f"\n\\item {{\\tiny ({id})}} {content}" if "字段显示设置" in misc and "答案" in misc["字段显示设置"] and misc["字段显示设置"]["答案"] == True: @@ -1258,9 +1259,10 @@ def generateLaTeXBodyContentfromMariaDB(cursor,id,misc): #根据id,读取的json remark = r"\\".join(remark_list) if len(remark_list) > 0 else "暂无备注" output += f"\n\n备注: \\textcolor[rgb]{{0,0.5,0.2}}{{{remark}}}\n\n" if "课时目标" in misc["字段显示设置"] and misc["字段显示设置"]["课时目标"] == True: - obj_string = '\n\n'.join(obj_list) - if obj_string.strip() == "": + if len(obj_list) == 0: obj_string = "暂无目标" + else: + obj_string = '\n\n'.join(obj_list) objs = f"\n\n目标:\n\n{obj_string}\n\n" output += objs if "题目标签" in misc["字段显示设置"] and misc["字段显示设置"]["题目标签"] == True: @@ -1285,46 +1287,29 @@ def generateLaTeXBodyContentfromMariaDB(cursor,id,misc): #根据id,读取的json +def generateLaTeXobjsfromMariaDB(cursor,objid): + objid = str(objid).upper().strip() + if objid == "KNONE": + return "" + else: + sql = "SELECT obj_content FROM lessonobj WHERE objid = %s;" + val = (objid,) + cursor.execute(sql,val) + obj_content = cursor.fetchall()[0][0] + output = f"\\item {objid} {obj_content}\n\n" + return output - return content,ans,solution,origin,space,obj_list,tag_list,remark_list,usages_raw - - - # 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 len(adict[id]["ans"]) > 0 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 = 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 len(adict[id]["ans"]) > 0 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 len(adict[id]["solution"]) > 0 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{GenerateUsageTexCode(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 generateLaTeXbnsfromMariaDB(cursor,bnid): + bnid = str(bnid).upper().strip() + sql = "SELECT bn_content FROM basic_knowledges WHERE bn_id = %s;" + val = (bnid,) + cursor.execute(sql,val) + try: + bn_content = cursor.fetchall()[0][0] + except: + bn_content = "基础知识目标编号有误" + output = f"\\item {bn_content}\n\n" + return output def GenerateTeacherBodyString(problems,sectiontitles,prodict,objdict,consecutivenumbering = True,topandbottomusagestuple = (3,3),sectionname = "section", showobjs = True, showtags = True, showans = True, showsolution = True, showusages = True, showorigin = True, showremark = True, colored = False): #生成教师版的.tex文件的主体内容, 各项是否显示为可选 diff --git a/工具v3/系列讲义生成.py b/工具v3/系列讲义生成.py index 57f1a6f6..0b2689a6 100644 --- a/工具v3/系列讲义生成.py +++ b/工具v3/系列讲义生成.py @@ -124,10 +124,12 @@ class MyWindow(QWidget,Ui_Form): consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"] texdata = GenerateSingleLessonNotefromMariaDB(cursor = mycursor, id = lessonid,notesdict=notes_dict,templatepath="./模板文件/讲义模板.txt",outputfilepath = os.path.join(self.outputpath,filename),misc=configjson,consecutivenumbering = consecutivenumbering) papernames.append(notes_dict["notes"][lessonid]["id"]+" \\ "+notes_dict["notes"][lessonid]["name"]) + print(f"已生成 {papernames[-1]} 文件") multitexdata.append(re.findall(r"\\begin{center}\n{\\bf\\large \\papername}\n\\end{center}([\s\S]*\\end\{enumerate\})",texdata)[0]) # print(lessonid) # print(configjson) # print("\n".join(patterns)) + mydb.close() merged = "" for i in range(len(papernames)): merged += "\n\n\\chapter{"+papernames[i]+"}\n\n\n"