关键字筛选题号 编写中
This commit is contained in:
parent
8f1b409edd
commit
55d9d28093
|
|
@ -0,0 +1,136 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
################################################################################
|
||||
## Form generated from reading UI file '题号筛选器.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.6.2
|
||||
##
|
||||
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
################################################################################
|
||||
|
||||
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
|
||||
QMetaObject, QObject, QPoint, QRect,
|
||||
QSize, QTime, QUrl, Qt)
|
||||
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
||||
QFont, QFontDatabase, QGradient, QIcon,
|
||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||
from PySide6.QtWidgets import (QApplication, QCheckBox, QFrame, QLCDNumber,
|
||||
QLabel, QLineEdit, QPushButton, QSizePolicy,
|
||||
QWidget)
|
||||
|
||||
class Ui_Form(object):
|
||||
def setupUi(self, Form):
|
||||
if not Form.objectName():
|
||||
Form.setObjectName(u"Form")
|
||||
Form.resize(400, 533)
|
||||
Form.setWindowOpacity(1.000000000000000)
|
||||
self.pushButton_content = QPushButton(Form)
|
||||
self.pushButton_content.setObjectName(u"pushButton_content")
|
||||
self.pushButton_content.setGeometry(QRect(20, 20, 75, 24))
|
||||
self.pushButton_obj = QPushButton(Form)
|
||||
self.pushButton_obj.setObjectName(u"pushButton_obj")
|
||||
self.pushButton_obj.setGeometry(QRect(20, 50, 75, 24))
|
||||
self.pushButton_tag = QPushButton(Form)
|
||||
self.pushButton_tag.setObjectName(u"pushButton_tag")
|
||||
self.pushButton_tag.setGeometry(QRect(20, 80, 75, 24))
|
||||
self.pushButton_usage = QPushButton(Form)
|
||||
self.pushButton_usage.setObjectName(u"pushButton_usage")
|
||||
self.pushButton_usage.setGeometry(QRect(20, 110, 75, 24))
|
||||
self.pushButton_origin = QPushButton(Form)
|
||||
self.pushButton_origin.setObjectName(u"pushButton_origin")
|
||||
self.pushButton_origin.setGeometry(QRect(20, 140, 75, 24))
|
||||
self.pushButton_genre = QPushButton(Form)
|
||||
self.pushButton_genre.setObjectName(u"pushButton_genre")
|
||||
self.pushButton_genre.setGeometry(QRect(20, 170, 75, 24))
|
||||
self.pushButton_ans = QPushButton(Form)
|
||||
self.pushButton_ans.setObjectName(u"pushButton_ans")
|
||||
self.pushButton_ans.setGeometry(QRect(20, 200, 75, 24))
|
||||
self.pushButton_solution = QPushButton(Form)
|
||||
self.pushButton_solution.setObjectName(u"pushButton_solution")
|
||||
self.pushButton_solution.setGeometry(QRect(20, 230, 75, 24))
|
||||
self.pushButton_same = QPushButton(Form)
|
||||
self.pushButton_same.setObjectName(u"pushButton_same")
|
||||
self.pushButton_same.setGeometry(QRect(20, 260, 75, 24))
|
||||
self.pushButton_related = QPushButton(Form)
|
||||
self.pushButton_related.setObjectName(u"pushButton_related")
|
||||
self.pushButton_related.setGeometry(QRect(20, 290, 75, 24))
|
||||
self.pushButton_remark = QPushButton(Form)
|
||||
self.pushButton_remark.setObjectName(u"pushButton_remark")
|
||||
self.pushButton_remark.setGeometry(QRect(20, 320, 75, 24))
|
||||
self.pushButton_exec = QPushButton(Form)
|
||||
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||
self.pushButton_exec.setGeometry(QRect(20, 460, 75, 48))
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
self.pushButton_exec.setFont(font)
|
||||
self.pushButton_undo = QPushButton(Form)
|
||||
self.pushButton_undo.setObjectName(u"pushButton_undo")
|
||||
self.pushButton_undo.setGeometry(QRect(20, 370, 75, 24))
|
||||
self.pushButton_clearAll = QPushButton(Form)
|
||||
self.pushButton_clearAll.setObjectName(u"pushButton_clearAll")
|
||||
self.pushButton_clearAll.setGeometry(QRect(20, 400, 75, 24))
|
||||
self.label_conditions = QLabel(Form)
|
||||
self.label_conditions.setObjectName(u"label_conditions")
|
||||
self.label_conditions.setGeometry(QRect(120, 100, 261, 331))
|
||||
self.label_conditions.setFrameShape(QFrame.StyledPanel)
|
||||
self.label_conditions.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop)
|
||||
self.label_conditions.setWordWrap(False)
|
||||
self.label = QLabel(Form)
|
||||
self.label.setObjectName(u"label")
|
||||
self.label.setGeometry(QRect(120, 80, 71, 16))
|
||||
self.checkBox_not = QCheckBox(Form)
|
||||
self.checkBox_not.setObjectName(u"checkBox_not")
|
||||
self.checkBox_not.setGeometry(QRect(280, 20, 111, 20))
|
||||
self.lineEdit_SingleCondition = QLineEdit(Form)
|
||||
self.lineEdit_SingleCondition.setObjectName(u"lineEdit_SingleCondition")
|
||||
self.lineEdit_SingleCondition.setGeometry(QRect(120, 50, 261, 20))
|
||||
self.label_2 = QLabel(Form)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
self.label_2.setGeometry(QRect(120, 20, 151, 16))
|
||||
self.label_3 = QLabel(Form)
|
||||
self.label_3.setObjectName(u"label_3")
|
||||
self.label_3.setGeometry(QRect(120, 440, 91, 16))
|
||||
self.lcdNumber_resCount = QLCDNumber(Form)
|
||||
self.lcdNumber_resCount.setObjectName(u"lcdNumber_resCount")
|
||||
self.lcdNumber_resCount.setGeometry(QRect(120, 460, 161, 51))
|
||||
self.lcdNumber_resCount.setDigitCount(6)
|
||||
self.lcdNumber_resCount.setProperty("value", 0.000000000000000)
|
||||
self.pushButton_savebuild = QPushButton(Form)
|
||||
self.pushButton_savebuild.setObjectName(u"pushButton_savebuild")
|
||||
self.pushButton_savebuild.setGeometry(QRect(300, 460, 81, 51))
|
||||
self.pushButton_savebuild.setFont(font)
|
||||
self.checkBox_Detailed = QCheckBox(Form)
|
||||
self.checkBox_Detailed.setObjectName(u"checkBox_Detailed")
|
||||
self.checkBox_Detailed.setGeometry(QRect(310, 440, 79, 20))
|
||||
|
||||
self.retranslateUi(Form)
|
||||
|
||||
QMetaObject.connectSlotsByName(Form)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u9898\u53f7\u7b5b\u9009\u5668", None))
|
||||
self.pushButton_content.setText(QCoreApplication.translate("Form", u"\u5185\u5bb9", None))
|
||||
self.pushButton_obj.setText(QCoreApplication.translate("Form", u"\u76ee\u6807\u7f16\u53f7", None))
|
||||
self.pushButton_tag.setText(QCoreApplication.translate("Form", u"\u6807\u7b7e", None))
|
||||
self.pushButton_usage.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u8bb0\u5f55", None))
|
||||
self.pushButton_origin.setText(QCoreApplication.translate("Form", u"\u51fa\u5904", None))
|
||||
self.pushButton_genre.setText(QCoreApplication.translate("Form", u"\u9898\u76ee\u7c7b\u578b", None))
|
||||
self.pushButton_ans.setText(QCoreApplication.translate("Form", u"\u7b54\u6848", None))
|
||||
self.pushButton_solution.setText(QCoreApplication.translate("Form", u"\u89e3\u7b54\u4e0e\u63d0\u793a", None))
|
||||
self.pushButton_same.setText(QCoreApplication.translate("Form", u"\u76f8\u540c\u9898\u53f7", None))
|
||||
self.pushButton_related.setText(QCoreApplication.translate("Form", u"\u76f8\u5173\u9898\u53f7", None))
|
||||
self.pushButton_remark.setText(QCoreApplication.translate("Form", u"\u5907\u6ce8", None))
|
||||
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u8fd0\u884c", None))
|
||||
self.pushButton_undo.setText(QCoreApplication.translate("Form", u"\u64a4\u9500\u4e0a\u4e00\u4e2a", None))
|
||||
self.pushButton_clearAll.setText(QCoreApplication.translate("Form", u"\u6e05\u9664", None))
|
||||
self.label_conditions.setText("")
|
||||
self.label.setText(QCoreApplication.translate("Form", u"\u5f53\u524d\u6761\u4ef6:", None))
|
||||
self.checkBox_not.setText(QCoreApplication.translate("Form", u"\u9009\u4e2d\u8868\u793a\u4e0d\u5305\u542b", None))
|
||||
self.label_2.setText(QCoreApplication.translate("Form", u"\u8f93\u5165\u6761\u4ef6, \u7528\",\"\u5206\u9694\u8868\u793a\"\u6216\"", None))
|
||||
self.label_3.setText(QCoreApplication.translate("Form", u"\u7b5b\u9009\u7ed3\u679c\u6570\u76ee:", None))
|
||||
self.pushButton_savebuild.setText(QCoreApplication.translate("Form", u"\u4fdd\u5b58\u548c\u7f16\u8bd1", None))
|
||||
self.checkBox_Detailed.setText(QCoreApplication.translate("Form", u"\u8be6\u7ec6\u4fe1\u606f", None))
|
||||
# retranslateUi
|
||||
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit
|
||||
from Ui_题号筛选器 import Ui_Form
|
||||
from database_tools_2 import *
|
||||
import time,os
|
||||
|
||||
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 MatchCondition2024(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)
|
||||
try:
|
||||
AppendTextFile(f"\n{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt")
|
||||
except:
|
||||
SaveTextFile(f"{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt")
|
||||
prodictpath = "../题库0.3/Problems.json"
|
||||
objdictpath = "../题库0.3/LessonObj.json"
|
||||
raw_pro_dict = load_dict(prodictpath)
|
||||
configjson_detailed = {
|
||||
"pdf标题": "筛选题目编译",
|
||||
"教师版": True,
|
||||
"字段显示设置": {
|
||||
"题后空间": True,
|
||||
"课时目标": True,
|
||||
"题目标签": True,
|
||||
"答案": True,
|
||||
"解答与提示": True,
|
||||
"使用记录": [3,-1],
|
||||
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||
"来源": True,
|
||||
"备注": True,
|
||||
"届别": []
|
||||
}
|
||||
}
|
||||
configjson_simple = {
|
||||
"pdf标题": "筛选题目编译",
|
||||
"教师版": False,
|
||||
"字段显示设置": {
|
||||
"题后空间": True,
|
||||
"课时目标": True,
|
||||
"题目标签": True,
|
||||
"答案": True,
|
||||
"解答与提示": True,
|
||||
"使用记录": [3,-1],
|
||||
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
|
||||
"来源": True,
|
||||
"备注": True,
|
||||
"届别": []
|
||||
}
|
||||
}
|
||||
|
||||
if self.checkBox_Detailed.isChecked():
|
||||
configjson = configjson_detailed
|
||||
else:
|
||||
configjson = configjson_simple
|
||||
|
||||
# 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()
|
||||
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")
|
||||
mycursor = mydb.cursor()
|
||||
bodystring = "\\begin{enumerate}\n\n"
|
||||
for id in generate_number_set(exp):
|
||||
bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,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}秒")
|
||||
os.system("code 临时文件/题号筛选.txt")
|
||||
startfile("临时文件")
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
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)
|
||||
Reference in New Issue