关键字筛选题号功能用pyside6重做完成
This commit is contained in:
parent
8d87bda99b
commit
ef2b069fca
123
工具v2/guipanel.py
123
工具v2/guipanel.py
|
|
@ -1,123 +0,0 @@
|
||||||
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit
|
|
||||||
from Ui_题号筛选器 import Ui_Form
|
|
||||||
from database_tools import *
|
|
||||||
|
|
||||||
class MyWindow(QWidget,Ui_Form):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.setupUi(self)
|
|
||||||
self.conditions = []
|
|
||||||
self.pro_dict = load_dict("../题库0.3/Problems.json")
|
|
||||||
self.lcdNumber_resCount.display(len(self.pro_dict))
|
|
||||||
self.bind()
|
|
||||||
|
|
||||||
def bind(self):
|
|
||||||
self.pushButton_content.clicked.connect(lambda: self.add_content("content"))
|
|
||||||
self.pushButton_obj.clicked.connect(lambda: self.add_content("objs"))
|
|
||||||
self.pushButton_tag.clicked.connect(lambda: self.add_content("tags"))
|
|
||||||
self.pushButton_usage.clicked.connect(lambda: self.add_content("usages"))
|
|
||||||
self.pushButton_origin.clicked.connect(lambda: self.add_content("origin"))
|
|
||||||
self.pushButton_genre.clicked.connect(lambda: self.add_content("genre"))
|
|
||||||
self.pushButton_ans.clicked.connect(lambda: self.add_content("ans"))
|
|
||||||
self.pushButton_solution.clicked.connect(lambda: self.add_content("solution"))
|
|
||||||
self.pushButton_same.clicked.connect(lambda: self.add_content("same"))
|
|
||||||
self.pushButton_related.clicked.connect(lambda: self.add_content("related"))
|
|
||||||
self.pushButton_remark.clicked.connect(lambda: self.add_content("remark"))
|
|
||||||
self.pushButton_undo.clicked.connect(self.undolast)
|
|
||||||
self.pushButton_clearAll.clicked.connect(self.clearConditions)
|
|
||||||
self.pushButton_exec.clicked.connect(self.exec)
|
|
||||||
self.pushButton_savebuild.clicked.connect(self.build)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def add_content(self,field):
|
|
||||||
self.conditions.append((field,self.checkBox_not.isChecked(),self.lineEdit_SingleCondition.text()))
|
|
||||||
self.showConditions()
|
|
||||||
def undolast(self):
|
|
||||||
self.conditions = self.conditions[:-1].copy()
|
|
||||||
self.showConditions()
|
|
||||||
def clearConditions(self):
|
|
||||||
self.conditions = []
|
|
||||||
self.showConditions()
|
|
||||||
def showConditions(self):
|
|
||||||
text = ""
|
|
||||||
for cond in self.conditions:
|
|
||||||
field, flag_not, matchexp = cond
|
|
||||||
text += f"字段 {field} 中{'没有' if flag_not else '有 '}{' 或 '.join([t.strip() for t in matchexp.split(',')])}\n"
|
|
||||||
self.label_conditions.setText(text)
|
|
||||||
def exec(self):
|
|
||||||
self.matchlist = []
|
|
||||||
self.conditions.append(("content",True,"OBSOLETE"))
|
|
||||||
for id in self.pro_dict:
|
|
||||||
if MatchCondition2014(self.pro_dict[id],self.conditions):
|
|
||||||
self.matchlist.append(id)
|
|
||||||
self.conditions = self.conditions[:-1].copy()
|
|
||||||
self.lcdNumber_resCount.display(len(self.matchlist))
|
|
||||||
|
|
||||||
def build(self):
|
|
||||||
exp = generate_exp(self.matchlist)
|
|
||||||
SaveTextFile(exp,"临时文件/题号筛选.txt")
|
|
||||||
prodictpath = "../题库0.3/problems.json"
|
|
||||||
objdictpath = "../题库0.3/lessonobj.json"
|
|
||||||
raw_pro_dict = load_dict(prodictpath)
|
|
||||||
configjson = {
|
|
||||||
"pdf标题": "筛选题目编译",
|
|
||||||
"教师版": True,
|
|
||||||
"字段显示设置": {
|
|
||||||
"题后空间": True,
|
|
||||||
"课时目标": True,
|
|
||||||
"题目标签": True,
|
|
||||||
"答案": True,
|
|
||||||
"解答与提示": True,
|
|
||||||
"使用记录": [3,-1],
|
|
||||||
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
|
||||||
"来源": True,
|
|
||||||
"备注": True,
|
|
||||||
"届别": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
grades = configjson["字段显示设置"]["届别"]
|
|
||||||
pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades)
|
|
||||||
obj_dict = load_dict(objdictpath)
|
|
||||||
|
|
||||||
notetitle = configjson["pdf标题"]
|
|
||||||
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 configjson["教师版"] == True:
|
|
||||||
latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学")
|
|
||||||
|
|
||||||
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)
|
|
||||||
starttime = time.time()
|
|
||||||
bodystring = "\\begin{enumerate}\n\n"
|
|
||||||
for id in generate_number_set(exp):
|
|
||||||
bodystring += generateLaTeXBodyContent(id,pro_dict,obj_dict,configjson)
|
|
||||||
bodystring += "\\end{enumerate}\n\n"
|
|
||||||
|
|
||||||
midtime = time.time()
|
|
||||||
print(f"生成LaTeX文件所花时间: {midtime-starttime:.3f}秒")
|
|
||||||
|
|
||||||
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring
|
|
||||||
SaveTextFile(latex_data,outputfilepath) #保存.tex文件
|
|
||||||
|
|
||||||
if XeLaTeXCompile(outputdir,notetitle+".tex"):
|
|
||||||
print("编译成功")
|
|
||||||
else:
|
|
||||||
print("编译失败")
|
|
||||||
|
|
||||||
endtime = time.time()
|
|
||||||
print(f"生成pdf文件所花时间: {endtime-midtime:.3f}秒")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
app = QApplication([])
|
|
||||||
windows = MyWindow()
|
|
||||||
windows.show()
|
|
||||||
app.exec()
|
|
||||||
|
|
||||||
146
工具v2/关键字筛选题号.py
146
工具v2/关键字筛选题号.py
|
|
@ -1,35 +1,123 @@
|
||||||
keywords_dict = {
|
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit
|
||||||
"id":[""], #题号
|
from Ui_题号筛选器 import Ui_Form
|
||||||
"content":[""], #题面内容
|
|
||||||
"objs":[""], #目标代码
|
|
||||||
"tags":[""], #标签, 如["第二单元"]等
|
|
||||||
"genre":[""], #题目类型, 填空题, 选择题, 解答题
|
|
||||||
"ans":[r""], #答案
|
|
||||||
"solution":[""], #解答与提示
|
|
||||||
"duration":[""], #解题时间(目前未设置)
|
|
||||||
"usages":[""], #使用记录, 数据库中格式为 <日期>\t<届别><班别>\t正确率[\t正确率]... 例如"20230301\t2023届01班\t0.985\t0.211
|
|
||||||
"origin":[""], #题目来源
|
|
||||||
"edit":[""], #导入者及编辑者
|
|
||||||
"same":[""], #相同题目题号
|
|
||||||
"related":[""], #关联题目题号
|
|
||||||
"remark":[""], #备注, 注记
|
|
||||||
"space":[""], #解答题下的空间(em)表示一个m的宽度
|
|
||||||
"unrelated":[""], #无关题目题号
|
|
||||||
# "content2":["双曲线"], #在字段名中加入数字表示这个字段的另一个必要条件
|
|
||||||
}
|
|
||||||
#同一字段名中的条件为"或"的关系, 不同字段名(可加数字表示同一字段)中的条件为"且"的关系
|
|
||||||
outputfilepath = "临时文件/题号筛选.txt"
|
|
||||||
|
|
||||||
from database_tools import *
|
from database_tools import *
|
||||||
|
|
||||||
|
class MyWindow(QWidget,Ui_Form):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.conditions = []
|
||||||
|
self.pro_dict = load_dict("../题库0.3/Problems.json")
|
||||||
|
self.lcdNumber_resCount.display(len(self.pro_dict))
|
||||||
|
self.bind()
|
||||||
|
|
||||||
|
def bind(self):
|
||||||
|
self.pushButton_content.clicked.connect(lambda: self.add_content("content"))
|
||||||
|
self.pushButton_obj.clicked.connect(lambda: self.add_content("objs"))
|
||||||
|
self.pushButton_tag.clicked.connect(lambda: self.add_content("tags"))
|
||||||
|
self.pushButton_usage.clicked.connect(lambda: self.add_content("usages"))
|
||||||
|
self.pushButton_origin.clicked.connect(lambda: self.add_content("origin"))
|
||||||
|
self.pushButton_genre.clicked.connect(lambda: self.add_content("genre"))
|
||||||
|
self.pushButton_ans.clicked.connect(lambda: self.add_content("ans"))
|
||||||
|
self.pushButton_solution.clicked.connect(lambda: self.add_content("solution"))
|
||||||
|
self.pushButton_same.clicked.connect(lambda: self.add_content("same"))
|
||||||
|
self.pushButton_related.clicked.connect(lambda: self.add_content("related"))
|
||||||
|
self.pushButton_remark.clicked.connect(lambda: self.add_content("remark"))
|
||||||
|
self.pushButton_undo.clicked.connect(self.undolast)
|
||||||
|
self.pushButton_clearAll.clicked.connect(self.clearConditions)
|
||||||
|
self.pushButton_exec.clicked.connect(self.exec)
|
||||||
|
self.pushButton_savebuild.clicked.connect(self.build)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def add_content(self,field):
|
||||||
|
self.conditions.append((field,self.checkBox_not.isChecked(),self.lineEdit_SingleCondition.text()))
|
||||||
|
self.showConditions()
|
||||||
|
def undolast(self):
|
||||||
|
self.conditions = self.conditions[:-1].copy()
|
||||||
|
self.showConditions()
|
||||||
|
def clearConditions(self):
|
||||||
|
self.conditions = []
|
||||||
|
self.showConditions()
|
||||||
|
def showConditions(self):
|
||||||
|
text = ""
|
||||||
|
for cond in self.conditions:
|
||||||
|
field, flag_not, matchexp = cond
|
||||||
|
text += f"字段 {field} 中{'没有' if flag_not else '有 '}{' 或 '.join([t.strip() for t in matchexp.split(',')])}\n"
|
||||||
|
self.label_conditions.setText(text)
|
||||||
|
def exec(self):
|
||||||
|
self.matchlist = []
|
||||||
|
self.conditions.append(("content",True,"OBSOLETE"))
|
||||||
|
for id in self.pro_dict:
|
||||||
|
if MatchCondition2014(self.pro_dict[id],self.conditions):
|
||||||
|
self.matchlist.append(id)
|
||||||
|
self.conditions = self.conditions[:-1].copy()
|
||||||
|
self.lcdNumber_resCount.display(len(self.matchlist))
|
||||||
|
|
||||||
|
def build(self):
|
||||||
|
exp = generate_exp(self.matchlist)
|
||||||
|
SaveTextFile(exp,"临时文件/题号筛选.txt")
|
||||||
prodictpath = "../题库0.3/problems.json"
|
prodictpath = "../题库0.3/problems.json"
|
||||||
pro_dict = load_dict(prodictpath)
|
objdictpath = "../题库0.3/lessonobj.json"
|
||||||
|
raw_pro_dict = load_dict(prodictpath)
|
||||||
|
configjson = {
|
||||||
|
"pdf标题": "筛选题目编译",
|
||||||
|
"教师版": True,
|
||||||
|
"字段显示设置": {
|
||||||
|
"题后空间": True,
|
||||||
|
"课时目标": True,
|
||||||
|
"题目标签": True,
|
||||||
|
"答案": True,
|
||||||
|
"解答与提示": True,
|
||||||
|
"使用记录": [3,-1],
|
||||||
|
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||||
|
"来源": True,
|
||||||
|
"备注": True,
|
||||||
|
"届别": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
grades = configjson["字段显示设置"]["届别"]
|
||||||
|
pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades)
|
||||||
|
obj_dict = load_dict(objdictpath)
|
||||||
|
|
||||||
|
notetitle = configjson["pdf标题"]
|
||||||
|
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 configjson["教师版"] == True:
|
||||||
|
latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学")
|
||||||
|
|
||||||
|
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)
|
||||||
|
starttime = time.time()
|
||||||
|
bodystring = "\\begin{enumerate}\n\n"
|
||||||
|
for id in generate_number_set(exp):
|
||||||
|
bodystring += generateLaTeXBodyContent(id,pro_dict,obj_dict,configjson)
|
||||||
|
bodystring += "\\end{enumerate}\n\n"
|
||||||
|
|
||||||
|
midtime = time.time()
|
||||||
|
print(f"生成LaTeX文件所花时间: {midtime-starttime:.3f}秒")
|
||||||
|
|
||||||
|
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring
|
||||||
|
SaveTextFile(latex_data,outputfilepath) #保存.tex文件
|
||||||
|
|
||||||
|
if XeLaTeXCompile(outputdir,notetitle+".tex"):
|
||||||
|
print("编译成功")
|
||||||
|
else:
|
||||||
|
print("编译失败")
|
||||||
|
|
||||||
|
endtime = time.time()
|
||||||
|
print(f"生成pdf文件所花时间: {endtime-midtime:.3f}秒")
|
||||||
|
|
||||||
|
|
||||||
keywords_dict["content9_not"] = ["OBSOLETE"]
|
|
||||||
print(keywords_dict)
|
|
||||||
matchlist = [id for id in pro_dict if MatchCondition(pro_dict[id],keywords_dict)]
|
|
||||||
matchstring = generate_exp(matchlist)
|
|
||||||
|
|
||||||
SaveTextFile(matchstring,outputfilepath)
|
if __name__ == '__main__':
|
||||||
os.system("code -g %s:1"%outputfilepath)
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
keywords_dict = {
|
||||||
|
"id":[""], #题号
|
||||||
|
"content":[""], #题面内容
|
||||||
|
"objs":[""], #目标代码
|
||||||
|
"tags":[""], #标签, 如["第二单元"]等
|
||||||
|
"genre":[""], #题目类型, 填空题, 选择题, 解答题
|
||||||
|
"ans":[r""], #答案
|
||||||
|
"solution":[""], #解答与提示
|
||||||
|
"duration":[""], #解题时间(目前未设置)
|
||||||
|
"usages":[""], #使用记录, 数据库中格式为 <日期>\t<届别><班别>\t正确率[\t正确率]... 例如"20230301\t2023届01班\t0.985\t0.211
|
||||||
|
"origin":[""], #题目来源
|
||||||
|
"edit":[""], #导入者及编辑者
|
||||||
|
"same":[""], #相同题目题号
|
||||||
|
"related":[""], #关联题目题号
|
||||||
|
"remark":[""], #备注, 注记
|
||||||
|
"space":[""], #解答题下的空间(em)表示一个m的宽度
|
||||||
|
"unrelated":[""], #无关题目题号
|
||||||
|
# "content2":["双曲线"], #在字段名中加入数字表示这个字段的另一个必要条件
|
||||||
|
}
|
||||||
|
#同一字段名中的条件为"或"的关系, 不同字段名(可加数字表示同一字段)中的条件为"且"的关系
|
||||||
|
outputfilepath = "临时文件/题号筛选.txt"
|
||||||
|
|
||||||
|
from database_tools import *
|
||||||
|
|
||||||
|
prodictpath = "../题库0.3/problems.json"
|
||||||
|
pro_dict = load_dict(prodictpath)
|
||||||
|
|
||||||
|
|
||||||
|
keywords_dict["content9_not"] = ["OBSOLETE"]
|
||||||
|
print(keywords_dict)
|
||||||
|
matchlist = [id for id in pro_dict if MatchCondition(pro_dict[id],keywords_dict)]
|
||||||
|
matchstring = generate_exp(matchlist)
|
||||||
|
|
||||||
|
SaveTextFile(matchstring,outputfilepath)
|
||||||
|
os.system("code -g %s:1"%outputfilepath)
|
||||||
|
|
@ -109,7 +109,7 @@ MaintainenceMenu.add_command(label = "分类题号字典生成", command = lambd
|
||||||
# 设置 使用 菜单项
|
# 设置 使用 菜单项
|
||||||
UseMenu = Menu(menubar, tearoff = False)
|
UseMenu = Menu(menubar, tearoff = False)
|
||||||
menubar.add_cascade(label = "使用", menu = UseMenu)
|
menubar.add_cascade(label = "使用", menu = UseMenu)
|
||||||
UseMenu.add_command(label = "关键字筛选题号", command = lambda: SetButton("关键字筛选题号",["关键字筛选题号.py"]))
|
UseMenu.add_command(label = "关键字筛选题号", command = lambda: SetButton("关键字筛选题号",[]))
|
||||||
UseMenu.add_separator()
|
UseMenu.add_separator()
|
||||||
UseMenu.add_command(label = "学生讲义制作", command = lambda: SetButton("学生讲义制作",["学生讲义制作.py"]))
|
UseMenu.add_command(label = "学生讲义制作", command = lambda: SetButton("学生讲义制作",["学生讲义制作.py"]))
|
||||||
UseMenu.add_command(label = "教师讲义制作", command = lambda: SetButton("教师讲义制作",["教师讲义制作.py"]))
|
UseMenu.add_command(label = "教师讲义制作", command = lambda: SetButton("教师讲义制作",["教师讲义制作.py"]))
|
||||||
|
|
|
||||||
Reference in New Issue