系列讲义生成功能已适配mariadb上的讲义信息

This commit is contained in:
wangweiye7840 2024-06-16 16:06:46 +08:00
parent bfe9782465
commit 3a452a32b1
2 changed files with 84 additions and 48 deletions

View File

@ -2519,9 +2519,9 @@ def GenerateSectionBodyStringfromDict(problems,sectiontitles,prodict,objdict,bnd
bodystring += sectionstring
return bodystring #返回主题内容字符串
def GenerateSingleLessonTeXfromDict(id,notesdict,pro_dict,obj_dict,bn_dict,misc,consecutivenumbering=False):
structure = notesdict["structures"][id[0].upper()]["structure"]
note_contents = notesdict["notes"][id]
def GenerateSingleLessonTeXfromDict(id,structuredict,notesdict,pro_dict,obj_dict,bn_dict,misc,consecutivenumbering=False):
structure = structuredict[id[0:5].upper()]["structure"]
note_contents = notesdict[id]
sections_list = []
problems_list = []
for key in structure:
@ -2533,9 +2533,9 @@ def GenerateSingleLessonTeXfromDict(id,notesdict,pro_dict,obj_dict,bn_dict,misc,
rawoutput = re.sub(r"\\section\{[^\n]*","",rawoutput)
return rawoutput
def GenerateSingleLessonNotefromMariaDB(cursor,id,notesdict,templatepath,outputfilepath,misc,consecutivenumbering = False): #20240415版讲义生成
def GenerateSingleLessonNotefromMariaDB(cursor,id,structuredict,notesdict,templatepath,outputfilepath,misc,consecutivenumbering = False): #20240415版讲义生成
notetitle = id + r" \ " + notesdict["notes"][id]["name"]
structure = notesdict["structures"][id[0].upper()]["structure"]
structure = structuredict[id[0:5].upper()]["structure"]
note_contents = notesdict["notes"][id]
output = ""
sections_list = []
@ -2573,10 +2573,10 @@ def GenerateSingleLessonNotefromMariaDB(cursor,id,notesdict,templatepath,outputf
print("编译失败")
return latex_data # 返回有错误的latex源代码
def GenerateSingleLessonNote(id,notesdict,metadict,templatepath,outputfilepath,consecutivenumbering = False, answered = False): #20231215版讲义生成
def GenerateSingleLessonNote(id,structuredict, notesdict,metadict,templatepath,outputfilepath,consecutivenumbering = False, answered = False): #20231215版讲义生成
notetitle = id + r" \ " + notesdict["notes"][id]["name"]
structure = notesdict["structures"][id[0].upper()]["structure"]
note_contents = notesdict["notes"][id]
structure = structuredict[id[0:5].upper()]["structure"]
note_contents = notesdict[id]
output = ""
sections_list = []
problems_list = []
@ -2624,6 +2624,8 @@ def getUnitNumber(string):
if string in unitlist[1:]:
return unitlist.index(string)
def ExtractProblemIDs(paperdict,pro_dict):#从备课组材料的每一张讲义的dict(paperdict)中提取题号
output = []
for key in paperdict.keys():
@ -3326,5 +3328,38 @@ def generateUsagedetail(zipfilepath,tempdir,answersheetseekingpath,statsfilename
return outputlist #返回由usages开始的使用记录列表
def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表
sql = "SELECT nid,name,filename,structure FROM notes WHERE NOT obsolete;"
cursor.execute(sql)
ret = cursor.fetchall()
notes_dict = {}
for nid,name,filename,structure in ret:
temp_dict = json.loads(structure)
notes_dict[nid] = {'id':nid,'name':name,'filename':filename}
for key in temp_dict:
notes_dict[nid][key] = temp_dict[key]
return notes_dict
def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表
sql = "SELECT initial,description,consecutivenumbering,structure FROM notestructures WHERE NOT obsolete;"
cursor.execute(sql)
ret = cursor.fetchall()
structures_dict = {}
for initial,description,consecutivenumbering,structure in ret:
structures_dict[initial] = {'initial':initial,'description':description,'consecutivenumbering':bool(consecutivenumbering),'structure':json.loads(structure)}
return structures_dict
def load_answersheets_dict_from_mariadb(cursor): # 从mariadb获取答题纸列表
sql = "SELECT pid,nid,parts,idlist,marks,exclude FROM answersheets WHERE NOT obsolete;"
cursor.execute(sql)
ret = cursor.fetchall()
answersheet_dict = {}
for pid,nid,parts,idlist,marks,exclude in ret:
answersheet_dict[pid] = {'nid':nid}
for key,item in [('parts',parts),('idlist',idlist),('marks',marks),('exclude',exclude)]:
if not item is None:
answersheet_dict[pid][key] = item
return answersheet_dict
if __name__ == "__main__":
print("数据库工具, import用.")

View File

@ -79,14 +79,16 @@ class MyWindow_jysc(QWidget,Ui_Form):
def saveandbuild(self):
patterns = self.lineEdit_regex.text().strip().split(",")
jsonpath = "../备课组" #有json文件的根目录, 文件名需为"校本材料.json"
jsondicts = []
for loc,dirs,files in os.walk(jsonpath):
if "校本材料.json" in files:
jsondicts.append(load_dict(os.path.join(loc,"校本材料.json")))
# jsonpath = "../备课组" #有json文件的根目录, 文件名需为"校本材料.json"
# jsondicts = []
# for loc,dirs,files in os.walk(jsonpath):
# if "校本材料.json" in files:
# jsondicts.append(load_dict(os.path.join(loc,"校本材料.json")))
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
mycursor = mydb.cursor()
notes_dict = load_notes_dict_from_mariadb(mycursor)
structures_dict = load_structures_dict_from_mariadb(mycursor)
raw_pro_dict,obj_dict,bn_dict,unit_obj_dict = generateDictsfromMariaDB(mycursor)
if self.radioButton_teacher.isChecked() and self.checkBox_usages.isChecked() and not self.lineEdit_grades.text().strip() == "":
grades = self.lineEdit_grades.text().strip().split(",")
@ -114,20 +116,19 @@ class MyWindow_jysc(QWidget,Ui_Form):
}
papernames = []
multitexdata = []
for notes_dict in jsondicts:
for lessonid in notes_dict["notes"]:
for lessonid in notes_dict:
coincideflag = False
for lessonpattern in patterns:
if re.findall(lessonpattern,lessonid) != []:
coincideflag = True
break
if coincideflag:
print(f"正在生成 {lessonid} {notes_dict['notes'][lessonid]['filename']} 的 .tex 文件")
filename = notes_dict["notes"][lessonid]["id"]+notes_dict["notes"][lessonid]["filename"]+".tex"
papertype = lessonid[0]
consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"]
texdata = GenerateSingleLessonTeXfromDict(id=lessonid, notesdict=notes_dict, pro_dict=pro_dict, obj_dict=obj_dict,bn_dict=bn_dict,misc = configjson, consecutivenumbering= consecutivenumbering)
papernames.append(notes_dict["notes"][lessonid]["id"]+" \\ "+notes_dict["notes"][lessonid]["name"])
print(f"正在生成 {lessonid} {notes_dict[lessonid]['filename']} 的 .tex 文件")
filename = notes_dict[lessonid]["id"]+notes_dict[lessonid]["filename"]+".tex"
papertype = lessonid[0:5]
consecutivenumbering = structures_dict[papertype]["consecutivenumbering"]
texdata = GenerateSingleLessonTeXfromDict(id=lessonid, structuredict = structures_dict, notesdict=notes_dict, pro_dict=pro_dict, obj_dict=obj_dict,bn_dict=bn_dict,misc = configjson, consecutivenumbering= consecutivenumbering)
papernames.append(notes_dict[lessonid]["id"]+" \\ "+notes_dict[lessonid]["name"])
print(f"已生成 {papernames[-1]} 文件")
multitexdata.append(texdata)
latex_raw = ReadTextFile("./模板文件/讲义模板.txt")