diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index 25f289ff..1b54a2d7 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -705,7 +705,7 @@ def XeLaTeXCompile(filedir,filename): #在filedir目录中用XeLaTeX编译filena flagsuc = False return flagsuc # 若第二次编译成功则返回True, 否则返回False -def GenerateStudentsBodyString(problems,sectiontitles,pro_dict,consecutivenumbering,answered,spaceflag): #生成学生版的.tex文件的主体内容 +def GenerateStudentBodyString(problems,sectiontitles,pro_dict,consecutivenumbering,answered,spaceflag): #生成学生版的.tex文件的主体内容 bodystring = "" if len(problems) == len(sectiontitles): count = 0 @@ -729,5 +729,67 @@ def GenerateStudentsBodyString(problems,sectiontitles,pro_dict,consecutivenumber bodystring += sectionstring return bodystring #返回主题内容字符串 + +def TeachersGetAfterContent(id,prodict,objdict,topandbottomusagestuple): #生成教师版讲义后的答案及空格, topandbottomusagestuple表示保留得分率最高的使用记录与最低的使用记录的个数, 有负数表示不排列 + string = "" + objs = "目标:\n\n%s\n\n"%GenerateObjTexCode(id,prodict,objdict) + tags = "标签: \\textcolor[rgb]{0.5,0.6,0.8}{%s}\n\n"%("; ".join(prodict[id]["tags"])) if not prodict[id]["tags"] == [] else "标签: \n\n" + ans = "答案: \\textcolor{red}{%s}\n\n"%(prodict[id]["ans"] if prodict[id]["ans"] != "" else "暂无答案") + solution = "解答或提示: \\textcolor{magenta}{%s}\n\n"%(prodict[id]["solution"] if prodict[id]["solution"] != "" else "暂无解答") + origin = "来源: %s\n\n"%prodict[id]["origin"] + remark = "备注: \\textcolor[rgb]{0,0.5,0.2}{%s}\n\n"%(prodict[id]["remark"] if prodict[id]["remark"] != "" else "暂无备注") + usages = "使用记录:\n\n%s\n\n"%GenerateUsageTexCode(id,prodict,topandbottomusagestuple) + string += objs + tags + ans + solution + usages + origin + remark + return string #生成教师版讲义后的答案及空格 + +def GenerateObjTexCode(id,prodict,objdict): #生成目标代号对应的学习目标字符串(含蓝色编码) + string = "" + if prodict[id]["objs"] != []: + for objid in prodict[id]["objs"]: + if objid.upper() == "KNONE": + string += "\\textcolor{blue}{%s\t%s}\n\n"%(objid,"无当前有效关联目标") + else: + string += "\\textcolor{blue}{%s\t%s}\n\n"%(objid,objdict[objid]["content"]) + return string #返回目标代码字符串 + +def ChooseUsage(usages,topandbottomusagestuple): #生成题号对应的题目的使用记录, topandbottomusagestuple表示保留得分率最高的使用记录与最低的使用记录的个数, 有负数表示不排列, 两数之和大于记录数则从高到低排列后全部展示 + top,bottom = topandbottomusagestuple + if top < 0 or bottom < 0: + return usages # 返回原本的全部使用记录 + elif top + bottom > len(usages): + return SortUsagesbyAverage(usages) # 返回排列后的使用记录 + else: + return (SortUsagesbyAverage(usages)[:top] + SortUsagesbyAverage(usages)[(-bottom):]) # 返回排序后的最前面top个和最后面bottom个 + +def GenerateUsageTexCode(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 GenerateTeacherBodyString(problems,sectiontitles,prodict,objdict,consecutivenumbering,topandbottomusagestuple): #生成学生版的.tex文件的主体内容 + bodystring = "" + if len(problems) == len(sectiontitles): + count = 0 + for i in range(len(problems)): + idlist = generate_number_set(problems[i],prodict) + sectionstring = "\\section{%s}\n\\begin{enumerate}\n\\setcounter{enumi}{%d}\n\n"%(sectiontitles[i],count if consecutivenumbering else 0) + for id in idlist: + count += 1 + aftercontent = TeachersGetAfterContent(id,prodict,objdict,topandbottomusagestuple) + sectionstring += "\\item (%s) %s\n\n%s"%(id,prodict[id]["content"],aftercontent) + sectionstring += "\\end{enumerate}" + bodystring += sectionstring + else: + idstring = ",".join(problems) + idlist = generate_number_set(idstring,prodict) + sectionstring = "\\begin{enumerate}\n\n" + for id in idlist: + aftercontent = TeachersGetAfterContent(id,prodict,objdict,topandbottomusagestuple) + sectionstring += "\\item (%s) %s\n\n%s"%(id,prodict[id]["content"],aftercontent) + sectionstring += "\\end{enumerate}" + bodystring += sectionstring + return bodystring #返回主题内容字符串 + if __name__ == "__main__": print("数据库工具, import用.") \ No newline at end of file diff --git a/工具v2/json编辑题目综合信息.py b/工具v2/json编辑题目综合信息.py index 3e88f0ad..c60a6a18 100644 --- a/工具v2/json编辑题目综合信息.py +++ b/工具v2/json编辑题目综合信息.py @@ -1,4 +1,4 @@ -id_string = "001477,001478,001540,001685" +id_string = "31243" prodictpath = "../题库0.3/Problems.json" editor = "王伟叶" diff --git a/工具v2/学生讲义制作.py b/工具v2/学生讲义制作.py index 7e01784a..698b2405 100644 --- a/工具v2/学生讲义制作.py +++ b/工具v2/学生讲义制作.py @@ -1,10 +1,12 @@ -problems = ["1:5","6:10","10000:10004"] #题号列表, 每个字符串表示一个分块的题目 +problems = ["1:50"] #题号列表, 每个字符串表示一个分块的题目 notetitle = "测试讲义" #讲义标题, 也是文件标题 sectiontitles = ["课前","课后","附加"] #小节标题列表, 如果与题号列表长度不符则作为不设小节处理 consecutivenumbering = False #不同小节是否连续编号, True表示连续编号, False表示每小节从1开始编号 answered = True #是否展示答案, True表示展示答案, False表示不展示答案 spaceflag = True #是否留空格, True表示留空格, False表示不留空格 + + from database_tools import * prodictpath = "../题库0.3/problems.json" @@ -21,7 +23,7 @@ if sys.platform != "win32": #非win系统用默认字体 latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) -bodystring = GenerateStudentsBodyString(problems,sectiontitles,pro_dict,consecutivenumbering,answered,spaceflag) #生成.tex中的内容主体字符串, 用于替换模板中的相应部分 +bodystring = GenerateStudentBodyString(problems,sectiontitles,pro_dict,consecutivenumbering,answered,spaceflag) #生成.tex中的内容主体字符串, 用于替换模板中的相应部分 latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring SaveTextFile(latex_data,outputfilepath) #保存.tex文件 diff --git a/工具v2/教师讲义制作.py b/工具v2/教师讲义制作.py new file mode 100644 index 00000000..70542c38 --- /dev/null +++ b/工具v2/教师讲义制作.py @@ -0,0 +1,36 @@ +problems = ["1:50000"] #题号列表, 每个字符串表示一个分块的题目 +notetitle = "测试讲义教师版" #讲义标题, 也是文件标题 +sectiontitles = ["课前","课后"] #小节标题列表, 如果与题号列表长度不符则作为不设小节处理 +consecutivenumbering = False #不同小节是否连续编号, True表示连续编号, False表示每小节从1开始编号 +topandbottomusagestuple = (3,-1) #表示保留得分率最高的使用记录与最低的使用记录的个数, 有负数表示不排列 + + + +from database_tools import * + +prodictpath = "../题库0.3/problems.json" +objdictpath = "../题库0.3/lessonobj.json" +pro_dict = load_dict(prodictpath) +obj_dict = load_dict(objdictpath) + +outputdir = "临时文件" #输出文件的目录 +outputfilepath = os.path.join(outputdir,notetitle+".tex") +print("输出文件目录: %s\n输出文件名: %s"%(os.path.join(os.getcwd(),outputdir),notetitle+".tex")) + +latex_raw = ReadTextFile("模板文件/讲义模板.txt") + +if sys.platform != "win32": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + + + +bodystring = GenerateTeacherBodyString(problems,sectiontitles,pro_dict,obj_dict,consecutivenumbering,topandbottomusagestuple) #生成.tex中的内容主体字符串, 用于替换模板中的相应部分 + +latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring +SaveTextFile(latex_data,outputfilepath) #保存.tex文件 + +succeeded = XeLaTeXCompile(outputdir,notetitle+".tex") + + +