迁移 关键字筛选题号

This commit is contained in:
weiye.wang 2024-04-25 20:51:17 +08:00
parent 297f826ce0
commit 3befd6b6d0
4 changed files with 633 additions and 2 deletions

View File

@ -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(760, 490)
Form.setWindowOpacity(1.000000000000000)
self.pushButton_content = QPushButton(Form)
self.pushButton_content.setObjectName(u"pushButton_content")
self.pushButton_content.setGeometry(QRect(120, 30, 75, 24))
self.pushButton_obj = QPushButton(Form)
self.pushButton_obj.setObjectName(u"pushButton_obj")
self.pushButton_obj.setGeometry(QRect(120, 60, 75, 24))
self.pushButton_tag = QPushButton(Form)
self.pushButton_tag.setObjectName(u"pushButton_tag")
self.pushButton_tag.setGeometry(QRect(120, 90, 75, 24))
self.pushButton_usage = QPushButton(Form)
self.pushButton_usage.setObjectName(u"pushButton_usage")
self.pushButton_usage.setGeometry(QRect(120, 120, 75, 24))
self.pushButton_origin = QPushButton(Form)
self.pushButton_origin.setObjectName(u"pushButton_origin")
self.pushButton_origin.setGeometry(QRect(120, 150, 75, 24))
self.pushButton_genre = QPushButton(Form)
self.pushButton_genre.setObjectName(u"pushButton_genre")
self.pushButton_genre.setGeometry(QRect(120, 180, 75, 24))
self.pushButton_ans = QPushButton(Form)
self.pushButton_ans.setObjectName(u"pushButton_ans")
self.pushButton_ans.setGeometry(QRect(120, 210, 75, 24))
self.pushButton_solution = QPushButton(Form)
self.pushButton_solution.setObjectName(u"pushButton_solution")
self.pushButton_solution.setGeometry(QRect(120, 240, 75, 24))
self.pushButton_same = QPushButton(Form)
self.pushButton_same.setObjectName(u"pushButton_same")
self.pushButton_same.setGeometry(QRect(120, 270, 75, 24))
self.pushButton_related = QPushButton(Form)
self.pushButton_related.setObjectName(u"pushButton_related")
self.pushButton_related.setGeometry(QRect(120, 300, 75, 24))
self.pushButton_remark = QPushButton(Form)
self.pushButton_remark.setObjectName(u"pushButton_remark")
self.pushButton_remark.setGeometry(QRect(120, 330, 75, 24))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(490, 110, 161, 91))
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(120, 380, 75, 24))
self.pushButton_clearAll = QPushButton(Form)
self.pushButton_clearAll.setObjectName(u"pushButton_clearAll")
self.pushButton_clearAll.setGeometry(QRect(120, 410, 75, 24))
self.label_conditions = QLabel(Form)
self.label_conditions.setObjectName(u"label_conditions")
self.label_conditions.setGeometry(QRect(220, 110, 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(220, 90, 71, 16))
self.checkBox_not = QCheckBox(Form)
self.checkBox_not.setObjectName(u"checkBox_not")
self.checkBox_not.setGeometry(QRect(380, 30, 111, 20))
self.lineEdit_SingleCondition = QLineEdit(Form)
self.lineEdit_SingleCondition.setObjectName(u"lineEdit_SingleCondition")
self.lineEdit_SingleCondition.setGeometry(QRect(220, 60, 261, 20))
self.label_2 = QLabel(Form)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(220, 30, 151, 16))
self.label_3 = QLabel(Form)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(490, 30, 91, 16))
self.lcdNumber_resCount = QLCDNumber(Form)
self.lcdNumber_resCount.setObjectName(u"lcdNumber_resCount")
self.lcdNumber_resCount.setGeometry(QRect(490, 50, 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(490, 240, 161, 201))
self.pushButton_savebuild.setFont(font)
self.checkBox_Detailed = QCheckBox(Form)
self.checkBox_Detailed.setObjectName(u"checkBox_Detailed")
self.checkBox_Detailed.setGeometry(QRect(490, 210, 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

View File

@ -11,6 +11,7 @@ from 获取题号 import MyWindow_hqth
from 单一题号转为图片 import MyWindow_sctp from 单一题号转为图片 import MyWindow_sctp
from 指定题号编译pdf import MyWindow_xtby from 指定题号编译pdf import MyWindow_xtby
from 根据正确率选择题号 import MyWindow_ndsx from 根据正确率选择题号 import MyWindow_ndsx
from 关键字筛选题号 import MyWindow_sxth
from database_tools_2 import * from database_tools_2 import *
class MyWindow(QMainWindow,Ui_MainWindow): class MyWindow(QMainWindow,Ui_MainWindow):
@ -26,9 +27,14 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.pushButton_tiku.clicked.connect(self.SelectTIKU) self.pushButton_tiku.clicked.connect(self.SelectTIKU)
self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮 self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮
self.layout_sxth = QVBoxLayout(self.tab_sxth)
self.sxth = MyWindow_sxth(self.database)
self.layout_sxth.addWidget(self.sxth) #以上三行为初始化“关键字筛选”tab
self.layout_ndsx = QVBoxLayout(self.tab_ndsx) self.layout_ndsx = QVBoxLayout(self.tab_ndsx)
self.ndsx = MyWindow_ndsx(self.database) self.ndsx = MyWindow_ndsx(self.database)
self.layout_ndsx.addWidget(self.ndsx) #以上三行为初始化“选题编译”tab self.layout_ndsx.addWidget(self.ndsx) #以上三行为初始化“按难度筛选”tab
self.layout_xtby = QVBoxLayout(self.tab_xtby) self.layout_xtby = QVBoxLayout(self.tab_xtby)
self.xtby = MyWindow_xtby(self.database) self.xtby = MyWindow_xtby(self.database)
@ -73,7 +79,8 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.jysc.setdbname, self.jysc.setdbname,
self.sctp.setdbname, self.sctp.setdbname,
self.xtby.setdbname, self.xtby.setdbname,
self.ndsx.setdbname self.ndsx.setdbname,
self.sxth.setdbname
]: #在列表中的tab里传送数据库名的连接 ]: #在列表中的tab里传送数据库名的连接
self.sendDBname.connect(func) self.sendDBname.connect(func)
def sendValue(self): def sendValue(self):

View File

@ -0,0 +1,148 @@
from PySide6.QtWidgets import QWidget, QApplication, QLineEdit
from Ui_题号筛选器 import Ui_Form
from database_tools_2 import *
import time,os
class MyWindow_sxth(QWidget,Ui_Form):
def __init__(self,database_name):
super().__init__()
self.database_name = database_name
self.setupUi(self)
self.conditions = []
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
mycursor = mydb.cursor()
mycursor.execute("SELECT count(*) FROM problems WHERE NOT content REGEXP 'OBS';")
self.lcdNumber_resCount.display(mycursor.fetchall()[0][0])
self.bind()
def setdbname(self,string):
self.database_name = string
print(self.database_name)
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 = MatchConditioninMariaDB(self.conditions,self.database_name)
self.lcdNumber_resCount.display(len(self.matchlist))
def build(self):
idlist = sorted(list(self.matchlist))
exp = generate_exp(idlist)
try:
AppendTextFile(f"\n{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt")
except:
SaveTextFile(f"{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt")
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
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 = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
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()

340
工具v4/题号筛选器.ui Normal file
View File

@ -0,0 +1,340 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>760</width>
<height>490</height>
</rect>
</property>
<property name="windowTitle">
<string>题号筛选器</string>
</property>
<property name="windowOpacity">
<double>1.000000000000000</double>
</property>
<widget class="QPushButton" name="pushButton_content">
<property name="geometry">
<rect>
<x>120</x>
<y>30</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>内容</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_obj">
<property name="geometry">
<rect>
<x>120</x>
<y>60</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>目标编号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_tag">
<property name="geometry">
<rect>
<x>120</x>
<y>90</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>标签</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_usage">
<property name="geometry">
<rect>
<x>120</x>
<y>120</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>使用记录</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_origin">
<property name="geometry">
<rect>
<x>120</x>
<y>150</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>出处</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_genre">
<property name="geometry">
<rect>
<x>120</x>
<y>180</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>题目类型</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_ans">
<property name="geometry">
<rect>
<x>120</x>
<y>210</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>答案</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_solution">
<property name="geometry">
<rect>
<x>120</x>
<y>240</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>解答与提示</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_same">
<property name="geometry">
<rect>
<x>120</x>
<y>270</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>相同题号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_related">
<property name="geometry">
<rect>
<x>120</x>
<y>300</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>相关题号</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_remark">
<property name="geometry">
<rect>
<x>120</x>
<y>330</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>备注</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>490</x>
<y>110</y>
<width>161</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>运行</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_undo">
<property name="geometry">
<rect>
<x>120</x>
<y>380</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>撤销上一个</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_clearAll">
<property name="geometry">
<rect>
<x>120</x>
<y>410</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>清除</string>
</property>
</widget>
<widget class="QLabel" name="label_conditions">
<property name="geometry">
<rect>
<x>220</x>
<y>110</y>
<width>261</width>
<height>331</height>
</rect>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>220</x>
<y>90</y>
<width>71</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>当前条件:</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_not">
<property name="geometry">
<rect>
<x>380</x>
<y>30</y>
<width>111</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>选中表示不包含</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_SingleCondition">
<property name="geometry">
<rect>
<x>220</x>
<y>60</y>
<width>261</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>220</x>
<y>30</y>
<width>151</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>输入条件, 用&quot;,&quot;分隔表示&quot;或&quot;</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>490</x>
<y>30</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>筛选结果数目:</string>
</property>
</widget>
<widget class="QLCDNumber" name="lcdNumber_resCount">
<property name="geometry">
<rect>
<x>490</x>
<y>50</y>
<width>161</width>
<height>51</height>
</rect>
</property>
<property name="digitCount">
<number>6</number>
</property>
<property name="value" stdset="0">
<double>0.000000000000000</double>
</property>
</widget>
<widget class="QPushButton" name="pushButton_savebuild">
<property name="geometry">
<rect>
<x>490</x>
<y>240</y>
<width>161</width>
<height>201</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>保存和编译</string>
</property>
</widget>
<widget class="QCheckBox" name="checkBox_Detailed">
<property name="geometry">
<rect>
<x>490</x>
<y>210</y>
<width>79</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>详细信息</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>