From 3a452a32b174710b79b552c2395271f30903451d Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Sun, 16 Jun 2024 16:06:46 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E7=B3=BB=E5=88=97=E8=AE=B2=E4=B9=89?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=8A=9F=E8=83=BD=E5=B7=B2=E9=80=82=E9=85=8D?= =?UTF-8?q?mariadb=E4=B8=8A=E7=9A=84=E8=AE=B2=E4=B9=89=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 57 +++++++++++++++++++++++------ 工具v4/系列讲义生成.py | 75 +++++++++++++++++++------------------- 2 files changed, 84 insertions(+), 48 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index e364166d..c26193af 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -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 = [] @@ -2623,6 +2623,8 @@ def getUnitNumber(string): unitlist = ["暂无对应","第一单元","第二单元","第三单元","第四单元","第五单元","第六单元","第七单元","第八单元","第九单元"] if string in unitlist[1:]: return unitlist.index(string) + + def ExtractProblemIDs(paperdict,pro_dict):#从备课组材料的每一张讲义的dict(paperdict)中提取题号 output = [] @@ -3290,9 +3292,9 @@ def findxiaobenIDs(jsonpath,grade = ""): #根据jsonpath中的校本材料获取 if "校本材料.json" in files: jsonlists.append(os.path.join(loc,"校本材料.json")) for jsonfile in jsonlists: - jsondict = load_dict(jsonfile)["notes"] - for pid in jsondict: - if pid[1:5] == grade or grade == "": + jsondict = load_dict(jsonfile)["notes"] + for pid in jsondict: + if pid[1:5] == grade or grade == "": for part in jsondict[pid]: if type(jsondict[pid][part]) == list and isIDpart(jsondict[pid][part]): jsonIDs += jsondict[pid][part].copy() @@ -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用.") \ No newline at end of file diff --git a/工具v4/系列讲义生成.py b/工具v4/系列讲义生成.py index 33e10cd9..9d9ed08f 100644 --- a/工具v4/系列讲义生成.py +++ b/工具v4/系列讲义生成.py @@ -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,41 +116,40 @@ class MyWindow_jysc(QWidget,Ui_Form): } papernames = [] multitexdata = [] - for notes_dict in jsondicts: - for lessonid in notes_dict["notes"]: - 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"已生成 {papernames[-1]} 文件") - multitexdata.append(texdata) - latex_raw = ReadTextFile("./模板文件/讲义模板.txt") - latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学") #替换掉模板中的姓名学号 + 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[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") + latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学") #替换掉模板中的姓名学号 - if sys.platform == "darwin": #非win系统用默认字体 - latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) - latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + if sys.platform == "darwin": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) - latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(papernames[-1],texdata)) #替换标题和bodystring - outputfilepath = os.path.join(self.outputpath,filename) - SaveTextFile(latex_data,outputfilepath) #保存.tex文件 + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(papernames[-1],texdata)) #替换标题和bodystring + outputfilepath = os.path.join(self.outputpath,filename) + SaveTextFile(latex_data,outputfilepath) #保存.tex文件 - if configjson["编译单个文件"] == True: - outputdir,filename = os.path.split(outputfilepath) - print(f"{filename}编译中...") - if XeLaTeXCompile(outputdir,filename): - print("编译成功") - else: - print("编译失败") - # print(lessonid) + if configjson["编译单个文件"] == True: + outputdir,filename = os.path.split(outputfilepath) + print(f"{filename}编译中...") + if XeLaTeXCompile(outputdir,filename): + print("编译成功") + else: + print("编译失败") + # print(lessonid) # print(configjson) # print("\n".join(patterns)) mydb.close() From 22554f8eb27aadcd94b03aa3c0e832e34cbb64ad Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Sun, 16 Jun 2024 16:37:03 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20findxiaobenIDs=20?= =?UTF-8?q?=E4=BB=A5=E9=80=82=E9=85=8D=E8=AE=B2=E4=B9=89=E5=9C=A8mariadb?= =?UTF-8?q?=E4=B8=8A=E7=9A=84=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index c26193af..75c00d32 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -3285,19 +3285,21 @@ def isIDpart(alist): #判断一个list是不是题号列表 return True -def findxiaobenIDs(jsonpath,grade = ""): #根据jsonpath中的校本材料获取grade做过的题目, grade为空则获取所有目录中的题目 - jsonlists = [] +def findxiaobenIDs(cursor,grade = ""): #根据jsonpath中的校本材料获取grade做过的题目, grade为空则获取所有目录中的题目 + sql = 'SELECT nid,structure FROM notes WHERE NOT obsolete;' + cursor.execute(sql) + ret = cursor.fetchall() + grade = grade.strip() + if len(grade) == 2: + grade = "20"+grade jsonIDs = [] - for loc,dirs,files in os.walk(jsonpath): - if "校本材料.json" in files: - jsonlists.append(os.path.join(loc,"校本材料.json")) - for jsonfile in jsonlists: - jsondict = load_dict(jsonfile)["notes"] - for pid in jsondict: - if pid[1:5] == grade or grade == "": - for part in jsondict[pid]: - if type(jsondict[pid][part]) == list and isIDpart(jsondict[pid][part]): - jsonIDs += jsondict[pid][part].copy() + for nid,structure in ret: + if grade == "" or nid[1:5] == grade: + structure = json.loads(structure) + for key in structure: + for id in structure[key]: + if len(id) == 6: + jsonIDs.append(id) return jsonIDs From d932713f0fb293da1024673168f0b5267094f04b Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Sun, 16 Jun 2024 18:09:30 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E8=B5=8B=E8=83=BD=E5=8D=B7=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=83=BD=E9=80=82=E9=85=8Dmariadb=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=9A=84=E6=9D=90=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/赋能卷生成.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/工具v4/赋能卷生成.py b/工具v4/赋能卷生成.py index 7aeb55aa..5e6d173f 100644 --- a/工具v4/赋能卷生成.py +++ b/工具v4/赋能卷生成.py @@ -32,7 +32,6 @@ class MyWindow_fnsc(QWidget,Ui_Form): mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) mycursor = mydb.cursor() pro_dict,obj_dict,bn_dict,unit_obj_dict = generateDictsfromMariaDB(mycursor) - mydb.close() units_list = [] for self.checkbox in self.findChildren(QCheckBox): if self.checkbox.isChecked(): @@ -48,7 +47,8 @@ class MyWindow_fnsc(QWidget,Ui_Form): elif self.radioButton_median.isChecked(): method = "median" sim_threshold = float(self.lineEdit_threshold.text()) - excludeids = findxiaobenIDs("../备课组",grade = self.lineEdit_grade.text()) + excludeids = findxiaobenIDs(mycursor,grade = self.lineEdit_grade.text()) + mydb.close() papercount = int(self.lineEdit_papercount.text()) output = "" for i in range(papercount): From 732e3a3fe6b875680d73d5dd2d209b082aaef484 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 19:24:59 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E7=BD=91=E9=A1=B5=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=AE=B2=E4=B9=89=20=E9=80=82=E9=85=8D=20=E6=9D=90=E6=96=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E4=B8=8A=E4=BC=A0=E5=80=BCmariadb=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 4 ++-- 工具v4/系列讲义生成.py | 6 ------ 工具v4/网页获取讲义.py | 34 ++++++++++++++-------------------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index 75c00d32..cf285914 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -2534,9 +2534,9 @@ def GenerateSingleLessonTeXfromDict(id,structuredict,notesdict,pro_dict,obj_dict return rawoutput def GenerateSingleLessonNotefromMariaDB(cursor,id,structuredict,notesdict,templatepath,outputfilepath,misc,consecutivenumbering = False): #20240415版讲义生成 - notetitle = id + r" \ " + notesdict["notes"][id]["name"] + notetitle = id + r" \ " + notesdict[id]["name"] structure = structuredict[id[0:5].upper()]["structure"] - note_contents = notesdict["notes"][id] + note_contents = notesdict[id] output = "" sections_list = [] problems_list = [] diff --git a/工具v4/系列讲义生成.py b/工具v4/系列讲义生成.py index 9d9ed08f..f10b8009 100644 --- a/工具v4/系列讲义生成.py +++ b/工具v4/系列讲义生成.py @@ -79,12 +79,6 @@ 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"))) - 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) diff --git a/工具v4/网页获取讲义.py b/工具v4/网页获取讲义.py index 01c1ef66..d73ba719 100644 --- a/工具v4/网页获取讲义.py +++ b/工具v4/网页获取讲义.py @@ -7,7 +7,7 @@ from database_tools_2 import * # raw_pro_dict = load_dict("../题库0.3/Problems.json") # obj_dict = load_dict("../题库0.3/LessonObj.json") # basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json") -jsonpath = "../备课组" +# jsonpath = "../备课组" # jsondicts = {} # for loc,dirs,files in os.walk(jsonpath): # if "校本材料.json" in files: @@ -23,14 +23,7 @@ app = Flask(__name__) @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': - global pid,configjson,uuiddir,outputpath,jsondicts - jsondicts = {} - os.system("git pull origin master --force") - for loc,dirs,files in os.walk(jsonpath): - if "校本材料.json" in files: - currentdict = load_dict(os.path.join(loc,"校本材料.json")) - for key in currentdict["notes"]: - jsondicts[key] = currentdict["notes"][key].copy() + global pid,configjson,uuiddir,outputpath uuiddir = str(uuid.uuid4()) outputpath = os.path.join(os.getcwd(),f"临时文件/{uuiddir}") makedir(outputpath) @@ -41,10 +34,10 @@ def index(): configjson = {"教师版": True, "字段显示设置": { "题后空间": False, - "课时目标": False, - "题目标签": False, + "课时目标": True, + "题目标签": True, "答案": True, - "解答与提示": False, + "解答与提示": True, "使用记录": [-1,-1], "来源": True, "备注": True, @@ -88,18 +81,19 @@ def index(): global filename mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="tikuuser", pwd="Kjmathds_2024", db = "tiku") mycursor = mydb.cursor() + notes_dict = load_notes_dict_from_mariadb(mycursor) + structure_dict = load_structures_dict_from_mariadb(mycursor) if re.findall(r"[A-Za-z]",pid) != []: - if pid in jsondicts: + if pid in notes_dict: try: - filename = pid+jsondicts[pid]["filename"].replace("(","").replace(")","")+".tex" - papertype = pid[0] - grade = pid[3:5] + filename = pid+notes_dict[pid]["filename"].replace("(","").replace(")","")+".tex" + papertype = pid[0:5] + # grade = pid[3:5] # raw_pro_dict = load_dict("../题库0.3/Problems.json") # obj_dict = load_dict("../题库0.3/LessonObj.json") # basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json") - notes_dict = load_dict(f"../备课组/{grade}届/校本材料.json") - consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"] - texdata = GenerateSingleLessonNotefromMariaDB(mycursor,pid,notes_dict,"../工具v3/模板文件/讲义模板.txt",os.path.join(outputpath,filename),configjson,consecutivenumbering) #20240415版讲义生成 + consecutivenumbering = structure_dict[papertype]["consecutivenumbering"] + texdata = GenerateSingleLessonNotefromMariaDB(mycursor,pid,structure_dict,notes_dict,"../工具v4/模板文件/讲义模板.txt",os.path.join(outputpath,filename),configjson,consecutivenumbering) #20240415版讲义生成 mydb.close() return f'''

{pid} PDF 文件生成完毕

@@ -128,7 +122,7 @@ def index(): for singleid in problems_list: bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,singleid,configjson) + "\n" bodystring += "\\end{enumerate}\n\n" - templatepath = "../工具v3/模板文件/讲义模板.txt" + templatepath = "../工具v4/模板文件/讲义模板.txt" outputfilepath = os.path.join(outputpath,filename) texdata = ReadTextFile(templatepath) texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texdata,("选题编译",bodystring)) From 736356a46cb04557c4ddb50b34b5f14a9877bb10 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 22:19:05 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B0=8F=E9=97=B2?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=80=82=E9=85=8D=E7=AD=94=E9=A2=98=E7=BA=B8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=94=BE=E5=9C=A8mariadb=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 83 +++++++++++++++++++++++----------- 工具v4/tool_panel.py | 5 +- 工具v4/获取小闲平台使用数据.py | 17 +++++-- 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index cf285914..9e22c699 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -29,6 +29,11 @@ db_pwd = "Kjmathds_2024" db_port = "13306" db_host = "wwylss.synology.me" +currentsemester = "2023" + +def getgrade(currentsemester,gradeindex): + gradelist = {1: "高三", 2:"高二", 3:"高一"} + return gradelist[int(gradeindex)-int(currentsemester)] def get_git_username(): command = "git config --global user.name" @@ -2653,36 +2658,62 @@ def FindFile(dir,filename): #在指定目录及子目录下寻找特定文件名 pathlist.append(path) return pathlist -def FindPaper(xiaoxianpid, answersheetpath): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False - answersheetpathlist = FindFile(answersheetpath,"答题纸对应.json") +def FindPaper(xiaoxianpid, mycursor): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False foundpid = False - for dir in answersheetpathlist: - filepath = os.path.join(dir,"答题纸对应.json") - anssheetjson = load_dict(filepath) - if xiaoxianpid in anssheetjson: - foundpid = True - grade = "20"+re.findall(r"\d{2}届",dir)[0] - nid = anssheetjson[xiaoxianpid]["nid"] - notesjson = load_dict(os.path.join(dir,"校本材料.json")) - if not "idlist" in anssheetjson[xiaoxianpid]: - idlist = [] - for part in anssheetjson[xiaoxianpid]["parts"]: - idlist += notesjson["notes"][nid][part].copy() - else: - idlist = anssheetjson[xiaoxianpid]["idlist"] - if "marks" in anssheetjson[xiaoxianpid]: - marks = anssheetjson[xiaoxianpid]["marks"] - else: - marks = [] - if "exclude" in anssheetjson[xiaoxianpid]: - excludejson = anssheetjson[xiaoxianpid]["exclude"] - else: - excludejson = {} - break + sql = "SELECT nid,parts,idlist,marks,exclude FROM answersheets WHERE not obsolete AND pid = %s;" + val = (xiaoxianpid,) + mycursor.execute(sql,val) + ret = mycursor.fetchall() + if len(ret) == 1: + foundpid = True + nid,parts,idlist,marksraw,excluderaw = ret[0] + if not parts is None: + idlist = [] + sql = "SELECT structure FROM notes WHERE nid = %s AND not obsolete;" + val = (nid,) + mycursor.execute(sql,val) + structure = mycursor.fetchall()[0][0] + for key in json.loads(parts): + idlist += json.loads(structure)[key].copy() + else: + idlist = json.loads(idlist) + marks = [] if marksraw is None else json.loads(marksraw) + exclude = {} if excluderaw is None else json.loads(excluderaw) + grade = nid[1:5]+"届" + # grade = getgrade(currentsemester,gradeindex) if foundpid: - return(nid,grade,idlist,marks,excludejson) + return(nid,grade,idlist,marks,exclude) else: return False + # answersheetpathlist = FindFile(answersheetpath,"答题纸对应.json") + # foundpid = False + # for dir in answersheetpathlist: + # filepath = os.path.join(dir,"答题纸对应.json") + # anssheetjson = load_dict(filepath) + # if xiaoxianpid in anssheetjson: + # foundpid = True + # grade = "20"+re.findall(r"\d{2}届",dir)[0] + # nid = anssheetjson[xiaoxianpid]["nid"] + # notesjson = load_dict(os.path.join(dir,"校本材料.json")) + # if not "idlist" in anssheetjson[xiaoxianpid]: + # idlist = [] + # for part in anssheetjson[xiaoxianpid]["parts"]: + # idlist += notesjson["notes"][nid][part].copy() + # else: + # idlist = anssheetjson[xiaoxianpid]["idlist"] + # if "marks" in anssheetjson[xiaoxianpid]: + # marks = anssheetjson[xiaoxianpid]["marks"] + # else: + # marks = [] + # if "exclude" in anssheetjson[xiaoxianpid]: + # excludejson = anssheetjson[xiaoxianpid]["exclude"] + # else: + # excludejson = {} + # break + # if foundpid: + # return(nid,grade,idlist,marks,excludejson) + # else: + # return False def CheckPaperType(filepath,filename): #根据filepath(通常是小闲的zip解压出的目录)和filename(通常是"小题分_按学号(数学).xlsx")检测试卷类型, 未找到该文件则返回False, 找到文件且是日常试卷返回"日常卷", 找到文件且不是日常试卷返回"考试卷" statsfilepathlist = FindFile(filepath,filename) diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 0ed94460..105681af 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -68,7 +68,7 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.layout_bjtm.addWidget(self.bjtm) #以上三行为初始化“编辑题目”tab self.layout_xxdr = QVBoxLayout(self.tab_xxdr) - self.xxdr = MyWindow_xxdr() + self.xxdr = MyWindow_xxdr(self.database) self.layout_xxdr.addWidget(self.xxdr) #以上三行为初始化“小闲统计数据导入”tab @@ -195,7 +195,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.xzgx.setdbname, self.sjlb.setdbname, self.fnsc.setdbname, - self.pxnd.setdbname + self.pxnd.setdbname, + self.xxdr.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/获取小闲平台使用数据.py b/工具v4/获取小闲平台使用数据.py index da37e028..79fb9a6c 100644 --- a/工具v4/获取小闲平台使用数据.py +++ b/工具v4/获取小闲平台使用数据.py @@ -20,14 +20,15 @@ class MyWindow_xxdr(QWidget,Ui_Form): - def __init__(self): + def __init__(self,database_name): super().__init__() self.setupUi(self) + self.database_name = database_name self.bind() def bind(self): self.tempdir = "临时文件/zips" self.statsfilename = "小题分_按学号(数学).xlsx" - self.answersheetseekingpath = "../备课组" + # self.answersheetseekingpath = "../备课组" self.lineEdit_threshold.setText("0.75") self.tableWidget.setColumnWidth(0,200) self.tableWidget.setColumnWidth(1,280) @@ -51,7 +52,9 @@ class MyWindow_xxdr(QWidget,Ui_Form): - + def setdbname(self,string): + self.database_name = string + print(self.database_name) def getDirPath(self): #选取文件夹中的所有符合答题纸特征的.zip文件并放置在tableWidget中 dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹") @@ -128,9 +131,11 @@ class MyWindow_xxdr(QWidget,Ui_Form): except: pass makedir(self.tempdir) + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() try: xiaoxianpid = ParseZipname(zipfilepath) - paperinfo = FindPaper(xiaoxianpid, self.answersheetseekingpath) + paperinfo = FindPaper(xiaoxianpid, mycursor) gradename = paperinfo[1] idlist = paperinfo[2] excludejson = paperinfo[4] @@ -144,8 +149,10 @@ class MyWindow_xxdr(QWidget,Ui_Form): dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],self.statsfilename)) correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols]) output = CalculateUsages(statsfilepathlist,self.statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date,exclude=RefineExclude(excludejson)) + mydb.close() return output #返回由usages开始的使用记录文本 except: + mydb.close() return 1 #无法生成就返回1 @@ -157,7 +164,7 @@ class MyWindow_xxdr(QWidget,Ui_Form): if __name__ == '__main__': app = QApplication([]) - windows = MyWindow_xxdr() + windows = MyWindow_xxdr("tikutest") windows.show() app.exec() From eacf0380a02ba0d8c2ae0d69668414d831ac283c Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 22:25:52 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E7=AD=94=E9=A2=98=E7=BA=B8=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E4=B8=8E=E8=AE=B2=E4=B9=89=E5=BD=95=E5=85=A5=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E9=80=82=E9=85=8D=E6=95=B0=E6=8D=AE=E5=BA=93=E5=88=87?= =?UTF-8?q?=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/tool_panel.py | 8 +++++--- 工具v4/答题纸对应.py | 9 +++++++-- 工具v4/获取小闲平台使用数据.py | 2 +- 工具v4/讲义结构与内容录入.py | 9 +++++++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 105681af..6ee0427c 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -121,11 +121,11 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.layout_hqth.addWidget(self.hqth) #以上三行为初始化“获取题号”tab self.layout_jglr = QVBoxLayout(self.tab_jglr) - self.jglr = MyWindow_jglr() + self.jglr = MyWindow_jglr(self.database) self.layout_jglr.addWidget(self.jglr) #以上三行为初始化“讲义结构编号录入”tab self.layout_dtlr = QVBoxLayout(self.tab_dtlr) - self.dtlr = MyWindow_dtlr() + self.dtlr = MyWindow_dtlr(self.database) self.layout_dtlr.addWidget(self.dtlr) #以上三行为初始化“答题纸对应信息录入”tab self.layout_jysc = QVBoxLayout(self.tab_jysc) @@ -196,7 +196,9 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.sjlb.setdbname, self.fnsc.setdbname, self.pxnd.setdbname, - self.xxdr.setdbname + self.xxdr.setdbname, + self.jglr.setdbname, + self.dtlr.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/答题纸对应.py b/工具v4/答题纸对应.py index a7c003db..2dd71655 100644 --- a/工具v4/答题纸对应.py +++ b/工具v4/答题纸对应.py @@ -18,9 +18,10 @@ def getindices(string): class MyWindow_dtlr(QWidget,Ui_Form): - def __init__(self): + def __init__(self,database_name): super().__init__() self.setupUi(self) + self.database_name = database_name self.bind() def bind(self): self.label_next.setVisible(False) @@ -29,6 +30,10 @@ class MyWindow_dtlr(QWidget,Ui_Form): self.lineEdit_structure.textChanged.connect(self.setindex) self.comboBox_index.activated.connect(self.activateexec) self.pushButton_exec.clicked.connect(self.exec) + + def setdbname(self,string): + self.database_name = string + # print(self.database_name) def setindex(self): self.comboBox_index.clear() @@ -126,7 +131,7 @@ class MyWindow_dtlr(QWidget,Ui_Form): if __name__ == '__main__': app = QApplication([]) - windows = MyWindow() + windows = MyWindow_dtlr("tikutest") windows.show() app.exec() diff --git a/工具v4/获取小闲平台使用数据.py b/工具v4/获取小闲平台使用数据.py index 79fb9a6c..262afec3 100644 --- a/工具v4/获取小闲平台使用数据.py +++ b/工具v4/获取小闲平台使用数据.py @@ -54,7 +54,7 @@ class MyWindow_xxdr(QWidget,Ui_Form): def setdbname(self,string): self.database_name = string - print(self.database_name) + # print(self.database_name) def getDirPath(self): #选取文件夹中的所有符合答题纸特征的.zip文件并放置在tableWidget中 dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹") diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index 978535ae..033d1aed 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -4,9 +4,10 @@ from database_tools_2 import * class MyWindow_jglr(QWidget,Ui_Form): - def __init__(self): + def __init__(self,database_name): super().__init__() self.setupUi(self) + self.database_name = database_name self.bind() def bind(self): self.label_next.setVisible(False) @@ -14,6 +15,10 @@ class MyWindow_jglr(QWidget,Ui_Form): self.lineEdit_structure.textChanged.connect(self.unvisible) self.comboBox_grade.currentIndexChanged.connect(self.unvisible) self.comboBox_semester.currentIndexChanged.connect(self.unvisible) + + def setdbname(self,string): + self.database_name = string + # print(self.database_name) def unvisible(self): self.label_next.setVisible(False) @@ -105,7 +110,7 @@ class MyWindow_jglr(QWidget,Ui_Form): if __name__ == '__main__': app = QApplication([]) - windows = MyWindow() + windows = MyWindow_jglr("tikutest") windows.show() app.exec() From e67e3e94d113fd2f8e36989cfbf0315f2c194771 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 23:21:31 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E7=AD=94=E9=A2=98=E7=BA=B8=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E4=B8=8E=E8=AE=B2=E4=B9=89=E7=BB=93=E6=9E=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=BD=95=E5=85=A5=20=E4=BF=AE=E6=94=B9=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/答题纸对应.py | 29 +++++++++++++++-------------- 工具v4/讲义结构与内容录入.py | 2 +- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/工具v4/答题纸对应.py b/工具v4/答题纸对应.py index 2dd71655..72a450cd 100644 --- a/工具v4/答题纸对应.py +++ b/工具v4/答题纸对应.py @@ -2,17 +2,16 @@ from PySide6.QtWidgets import QWidget, QApplication, QFileDialog from Ui_答题纸对应 import Ui_Form from database_tools_2 import * -def getindices(string): +def getindices(string,cursor):#根据前七个字符获取以其为首的讲义的后两位 + sql = "SELECT nid FROM notes WHERE NOT obsolete;" + cursor.execute(sql) + ret = cursor.fetchall() indices_list = [] - notesjsonpath = f"../备课组/{string[3:5]}届/校本材料.json" - try: - notesjson = load_dict(notesjsonpath) - for id in notesjson["notes"]: - if id.startswith(string): - indices_list.append(id[-2:]) - return indices_list - except: - return [] + for item in ret: + if item[0].startswith(string): + indices_list.append(item[0][-2:]) + return indices_list.copy() + @@ -52,14 +51,16 @@ class MyWindow_dtlr(QWidget,Ui_Form): def unvisible(self): self.label_next.setVisible(False) def exec(self): + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() nid = f"{self.structure}{self.grade}{self.semester}{self.comboBox_index.currentText()}" - answersheetjson = f"../备课组/{self.grade[-2:]}届/答题纸对应.json" - notesjson = f"../备课组/{self.grade[-2:]}届/校本材料.json" + # answersheetjson = f"../备课组/{self.grade[-2:]}届/答题纸对应.json" + # notesjson = f"../备课组/{self.grade[-2:]}届/校本材料.json" marks_list = re.findall(r"(?:(?:^)|(?:\n))(\d+)分",self.plainTextEdit_marks.toPlainText()) marks_list = [int(mark) for mark in marks_list] - answersheet_dict = load_dict(answersheetjson) - notes_dict = load_dict(notesjson) + answersheet_dict = load_answersheets_dict_from_mariadb(mycursor) + notes_dict = load_notes_dict_from_mariadb(mycursor) new_dict = {} diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index 033d1aed..68c75885 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -76,7 +76,7 @@ class MyWindow_jglr(QWidget,Ui_Form): pid = self.prefix + input("请输入新材料编号(两位数):") name = input("请输入材料名称:") filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):") - if filenameraw.upper() == "Y": + if filenameraw.upper() == "Y" or len(filenameraw.strip()) == 0: filename = name else: filename = filenameraw From 2409413cf5270d78e2599e8ae6e15b98245a7d7e Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 23:57:21 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E8=AE=B2=E4=B9=89=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=8F=8A=E5=86=85=E5=AE=B9=E5=BD=95=E5=85=A5=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/讲义结构与内容录入.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index 68c75885..c41a7c9c 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -23,21 +23,22 @@ class MyWindow_jglr(QWidget,Ui_Form): def unvisible(self): self.label_next.setVisible(False) def exec(self): + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() if not len(self.lineEdit_structure.text()) == 1: print("首字母有误") else: self.label_next.setVisible(True) self.repaint() self.prefix = self.lineEdit_structure.text().upper()+self.comboBox_grade.currentText()+self.comboBox_semester.currentText() - jsonfile = f"../备课组/{self.prefix[3:5]}届/校本材料.json" - notes_dict = load_dict(jsonfile) - + notes_dict = load_notes_dict_from_mariadb(mycursor) + structure_dict = load_structures_dict_from_mariadb(mycursor) # print(len(notes_dict)) - if not self.prefix[0] in notes_dict["structures"]: - AddNew = input("此类型不在列表中, 新增(A)/退出(Q):") + if not self.prefix[0:5] in structure_dict: + AddNew = input("此类型不在列表中, 新增(A)/退出([Q]):") if AddNew[0].upper() == "A": descr = input("类型描述:") - cn = input("编号是否连续(T/F):") + cn = input("编号是否连续(T/[F]):") if cn[0].upper() == "T": cn = True else: @@ -51,7 +52,7 @@ class MyWindow_jglr(QWidget,Ui_Form): for i in range(partscount): partid = input(f"第 {i+1} 部分的代号:") partname = input(f"部分 {partid} 的名称:") - spaceflag = input(f"部分 {partid}: {partname} 中是否要在题目后留空格(T/F):") + spaceflag = input(f"部分 {partid}: {partname} 中是否要在题目后留空格(T/[F]):") if spaceflag[0].upper() == "T": spaceflag = True else: @@ -60,8 +61,9 @@ class MyWindow_jglr(QWidget,Ui_Form): "name": partname, "spaceflag": spaceflag } - notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy() - save_dict(notes_dict,jsonfile) + ####20240616到这里 + # notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy() + # save_dict(notes_dict,jsonfile) else: pass else: @@ -102,6 +104,7 @@ class MyWindow_jglr(QWidget,Ui_Form): notes_dict["notes"] = SortDict(notes_dict["notes"]) save_dict(notes_dict,jsonfile) print("处理完成") + mydb.close() From da99fcb6e3db9bdcc45ad65817272e5b730a7aa7 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Mon, 17 Jun 2024 06:39:16 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E8=AE=B2=E4=B9=89=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=B8=8E=E5=86=85=E5=AE=B9=E5=BD=95=E5=85=A5=E5=8A=A0=E5=B7=A5?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/讲义结构与内容录入.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index c41a7c9c..3752f219 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -39,7 +39,7 @@ class MyWindow_jglr(QWidget,Ui_Form): if AddNew[0].upper() == "A": descr = input("类型描述:") cn = input("编号是否连续(T/[F]):") - if cn[0].upper() == "T": + if len(cn) > 0 and cn[0].upper() == "T": cn = True else: cn = False @@ -53,7 +53,7 @@ class MyWindow_jglr(QWidget,Ui_Form): partid = input(f"第 {i+1} 部分的代号:") partname = input(f"部分 {partid} 的名称:") spaceflag = input(f"部分 {partid}: {partname} 中是否要在题目后留空格(T/[F]):") - if spaceflag[0].upper() == "T": + if len(spaceflag) > 0 and spaceflag[0].upper() == "T": spaceflag = True else: spaceflag = False @@ -61,6 +61,13 @@ class MyWindow_jglr(QWidget,Ui_Form): "name": partname, "spaceflag": spaceflag } + sql = "INSERT INTO notestructures (initial,description,consecutivenumbering,structure) VALUES (%s,%s,%s,%s);" + val = (self.prefix[0:5],descr,cn,json.dumps(new_struct_dict["structure"],ensure_ascii = False)) + mycursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),"添加新讲义结构",self.prefix[0:5]) + mycursor.execute(sql,val) + mydb.commit() ####20240616到这里 # notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy() # save_dict(notes_dict,jsonfile) From f9fa43bb770e3a598b755db6cc89bc9b5dd5ebae Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Mon, 17 Jun 2024 09:38:16 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E8=AE=B2=E4=B9=89=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E4=B8=8E=E5=86=85=E5=AE=B9=E5=BD=95=E5=85=A5=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=80=82=E9=85=8D=20=E8=AE=B2=E4=B9=89=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E4=B8=8A=E4=BC=A0=E8=87=B3mariadb=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 7 ++++--- 工具v4/讲义结构与内容录入.py | 36 +++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index 9e22c699..a5f7f332 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -298,7 +298,7 @@ def generate_classid(string): #返回班级列表 def generate_id_set(string,*thedict): #除了生成题号列表外, 还能根据首字母生成基础知识编号列表或课时目标列表 - string = RefinePunctuations(string) + string = RefinePunctuations(string).upper() if re.findall(r"[BXK]",string) == []: if thedict == (): return generate_number_set(string) @@ -3362,15 +3362,16 @@ def generateUsagedetail(zipfilepath,tempdir,answersheetseekingpath,statsfilename def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表 - sql = "SELECT nid,name,filename,structure FROM notes WHERE NOT obsolete;" + sql = "SELECT nid,name,filename,structure,remarks FROM notes WHERE NOT obsolete;" cursor.execute(sql) ret = cursor.fetchall() notes_dict = {} - for nid,name,filename,structure in ret: + for nid,name,filename,structure,remarks 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] + # notes_dict[nid]["remarks"] = "" if remarks is None else remarks return notes_dict def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表 diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index 3752f219..872fcaf3 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -68,21 +68,18 @@ class MyWindow_jglr(QWidget,Ui_Form): val = (GetDate(),GetTime(),get_git_username(),"添加新讲义结构",self.prefix[0:5]) mycursor.execute(sql,val) mydb.commit() - ####20240616到这里 - # notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy() - # save_dict(notes_dict,jsonfile) else: pass else: numberlist = [] - for id in notes_dict["notes"]: - if self.prefix in id: - numberlist.append(id[-2:]) + for existing_nid in notes_dict: + if self.prefix in existing_nid: + numberlist.append(existing_nid[-2:]) print("该分类下已有材料编号: "+generate_exp(numberlist)) - pid = self.prefix + input("请输入新材料编号(两位数):") - while pid in notes_dict["notes"]: + nid = self.prefix + input("请输入新材料编号(两位数):") + while nid in notes_dict: print("编号重复, 请重新输入.") - pid = self.prefix + input("请输入新材料编号(两位数):") + nid = self.prefix + input("请输入新材料编号(两位数):") name = input("请输入材料名称:") filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):") if filenameraw.upper() == "Y" or len(filenameraw.strip()) == 0: @@ -90,26 +87,35 @@ class MyWindow_jglr(QWidget,Ui_Form): else: filename = filenameraw new_note_dict = { - "id": pid, + "nid": nid, "name": name, "filename": filename } - structure = notes_dict['structures'][self.prefix[0]]['structure'] + new_note_dict_structure = {} + structure = structure_dict[self.prefix[0:5]]['structure'] print(f"此类材料共有 {len(structure)} 个部分, 分别是:") for p in structure: print(f"{p}: {structure[p]['name']}") - new_note_dict[p] = [] + new_note_dict_structure[p] = [] for p in structure: rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:") + rawdata = RefinePunctuations(rawdata) rawdata = re.sub(r"[^BXK\d:,]","",rawdata) if re.findall(r"\d",rawdata) == []: new_note_dict[p] = [] else: new_note_dict[p] = generate_id_set(rawdata) print(f"{p}: {new_note_dict[p]}") - notes_dict["notes"][pid] = new_note_dict.copy() - notes_dict["notes"] = SortDict(notes_dict["notes"]) - save_dict(notes_dict,jsonfile) + temp_dict = new_note_dict.copy() + for key in ["nid","name","filename"]: + temp_dict.pop(key) + sql = "INSERT INTO notes (nid,name,filename,structure) VALUES (%s,%s,%s,%s);" + val = (nid,name,filename,json.dumps(temp_dict,ensure_ascii = False)) + mycursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),"添加新讲义内容",self.prefix) + mycursor.execute(sql,val) + mydb.commit() print("处理完成") mydb.close() From 62b7c75d4d68b834b7577ce0554312dd23221082 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Mon, 17 Jun 2024 10:37:33 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E7=AD=94=E9=A2=98=E7=BA=B8=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=20=E9=80=82=E9=85=8D=20=E8=AE=B2=E4=B9=89=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E8=87=B3mariadb=E7=9A=84=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/答题纸对应.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/工具v4/答题纸对应.py b/工具v4/答题纸对应.py index 72a450cd..e6dc0b51 100644 --- a/工具v4/答题纸对应.py +++ b/工具v4/答题纸对应.py @@ -35,17 +35,20 @@ class MyWindow_dtlr(QWidget,Ui_Form): # print(self.database_name) def setindex(self): + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() self.comboBox_index.clear() self.structure = self.lineEdit_structure.text().upper() self.grade = self.comboBox_grade.currentText() self.semester = self.comboBox_semester.currentText() self.initialstring = f"{self.structure}{self.grade}{self.semester}" - self.indices = getindices(self.initialstring) + self.indices = getindices(self.initialstring,mycursor) self.comboBox_index.addItems(self.indices) if self.indices == []: self.pushButton_exec.setDisabled(True) else: self.pushButton_exec.setEnabled(True) + mydb.close() def activateexec(self): self.pushButton_exec.setEnabled(True) def unvisible(self): @@ -61,20 +64,22 @@ class MyWindow_dtlr(QWidget,Ui_Form): answersheet_dict = load_answersheets_dict_from_mariadb(mycursor) notes_dict = load_notes_dict_from_mariadb(mycursor) + structure_dict = load_structures_dict_from_mariadb(mycursor) new_dict = {} - if not nid in notes_dict["notes"]: + if not nid in notes_dict: print("讲义编号有误.") else: self.label_next.setVisible(True) self.repaint() new_dict["nid"] = nid corresponding_method = input("用何种方式对应? 题号(I)/章节标题(P):") - if corresponding_method[0].upper() == "I": + if corresponding_method.strip() != "" and corresponding_method[0].upper() == "I": new_dict["idlist"] = [] count = 1 id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") + id = RefinePunctuations(id) while len(re.findall(r"[Ss\d,:]",id)) == len(id): if "S" in id.upper(): new_dict["idlist"].append("999999") @@ -84,10 +89,11 @@ class MyWindow_dtlr(QWidget,Ui_Form): new_dict["idlist"] += [i.zfill(6) for i in new_id_list] count += len(new_id_list) id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") + id = RefinePunctuations(id) - elif corresponding_method[0].upper() == "P": - structure = notes_dict["structures"][nid[0]]["structure"] + elif corresponding_method.strip() != "" and corresponding_method[0].upper() == "P": + structure = structure_dict[nid[0:5]]["structure"] count = 1 partslist = [] for key in structure: @@ -95,30 +101,40 @@ class MyWindow_dtlr(QWidget,Ui_Form): count += 1 partslist.append(key) parts_selected_string = input("使用哪些部分(输入数字编号, 用';'分隔):") + parts_selected_string = RefinePunctuations(parts_selected_string).replace(",",";").replace(" ","") parts_selected_index = parts_selected_string.strip().split(";") parts_selected = [] for i in parts_selected_index: parts_selected.append(partslist[int(i)-1]) new_dict["parts"] = parts_selected.copy() if marks_list == []: - marksflag = input("是否为每个结果赋分(Y/N):") - if marksflag[0].upper() == "Y": + marksflag = input("是否为每个结果赋分(Y/[N]):") + if marksflag.strip() != "" and marksflag[0].upper() == "Y": new_dict["marks"] = [] count = 1 - mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") + mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):").strip() while len(re.findall(r"\d",mark)) == len(mark): new_dict["marks"].append(int(mark)) count += 1 - mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") + mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):").strip() else: new_dict["marks"] = marks_list.copy() + sql = "INSERT INTO answersheets (pid,nid,parts,idlist,marks) VALUES (%s,%s,%s,%s,%s);" + parts = None if not "parts" in new_dict else json.dumps(new_dict["parts"],ensure_ascii=False) + idlist = None if not "idlist" in new_dict else json.dumps(new_dict["idlist"],ensure_ascii=False) + marks = None if not "marks" in new_dict else json.dumps(new_dict["marks"],ensure_ascii=False) + val = (self.lineEdit_xiaoxianid.text(),nid,parts,idlist,marks) + mycursor.execute(sql,val) + sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" + val = (GetDate(),GetTime(),get_git_username(),"答题纸挂钩",self.lineEdit_xiaoxianid.text()) + mydb.commit() - answersheet_dict[self.lineEdit_xiaoxianid.text()] = new_dict.copy() - save_dict(answersheet_dict,answersheetjson) + # answersheet_dict[self.lineEdit_xiaoxianid.text()] = new_dict.copy() + # save_dict(answersheet_dict,answersheetjson) self.label_next.setVisible(False) print("设置完成") - + mydb.close() From 85aa1a8d20015ac3cf1c7084f56b672bcf191a82 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Mon, 17 Jun 2024 11:12:45 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E7=B3=BB=E5=88=97=E8=AE=B2=E4=B9=89?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=AD=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=AE=B2?= =?UTF-8?q?=E4=B9=89=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 2 +- 工具v4/系列讲义生成.py | 4 +++- 工具v4/讲义结构与内容录入.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index a5f7f332..7e75fca5 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -3371,7 +3371,7 @@ def load_notes_dict_from_mariadb(cursor): #从mariadb获取讲义列表 notes_dict[nid] = {'id':nid,'name':name,'filename':filename} for key in temp_dict: notes_dict[nid][key] = temp_dict[key] - # notes_dict[nid]["remarks"] = "" if remarks is None else remarks + notes_dict[nid]["remarks"] = "" if remarks is None else remarks return notes_dict def load_structures_dict_from_mariadb(cursor): # 从mariadb获取讲义结构列表 diff --git a/工具v4/系列讲义生成.py b/工具v4/系列讲义生成.py index f10b8009..f60aa5aa 100644 --- a/工具v4/系列讲义生成.py +++ b/工具v4/系列讲义生成.py @@ -110,7 +110,7 @@ class MyWindow_jysc(QWidget,Ui_Form): } papernames = [] multitexdata = [] - for lessonid in notes_dict: + for lessonid in sorted(notes_dict.keys()): coincideflag = False for lessonpattern in patterns: if re.findall(lessonpattern,lessonid) != []: @@ -122,6 +122,8 @@ class MyWindow_jysc(QWidget,Ui_Form): 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) + if notes_dict[lessonid]["remarks"] != "": + texdata += f"\n\n\\newpage\n\n\\section{{备注}}\n\n{notes_dict[lessonid]['remarks']}\n\n" papernames.append(notes_dict[lessonid]["id"]+" \\ "+notes_dict[lessonid]["name"]) print(f"已生成 {papernames[-1]} 文件") multitexdata.append(texdata) diff --git a/工具v4/讲义结构与内容录入.py b/工具v4/讲义结构与内容录入.py index 872fcaf3..2a7b8247 100644 --- a/工具v4/讲义结构与内容录入.py +++ b/工具v4/讲义结构与内容录入.py @@ -113,7 +113,7 @@ class MyWindow_jglr(QWidget,Ui_Form): val = (nid,name,filename,json.dumps(temp_dict,ensure_ascii = False)) mycursor.execute(sql,val) sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);" - val = (GetDate(),GetTime(),get_git_username(),"添加新讲义内容",self.prefix) + val = (GetDate(),GetTime(),get_git_username(),"添加新讲义内容",nid) mycursor.execute(sql,val) mydb.commit() print("处理完成")