diff --git a/工具v4/Ui_批量收录新题.py b/工具v4/Ui_批量收录新题.py new file mode 100644 index 00000000..a7ea39bd --- /dev/null +++ b/工具v4/Ui_批量收录新题.py @@ -0,0 +1,150 @@ +# -*- 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, QHBoxLayout, QLabel, + QLineEdit, QPlainTextEdit, QPushButton, QSizePolicy, + QSplitter, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(760, 490) + self.plainTextEdit_raw = QPlainTextEdit(Form) + self.plainTextEdit_raw.setObjectName(u"plainTextEdit_raw") + self.plainTextEdit_raw.setGeometry(QRect(10, 30, 281, 441)) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(20, 10, 251, 16)) + self.pushButton_step1 = QPushButton(Form) + self.pushButton_step1.setObjectName(u"pushButton_step1") + self.pushButton_step1.setGeometry(QRect(300, 50, 70, 400)) + font = QFont() + font.setBold(True) + self.pushButton_step1.setFont(font) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(360, 10, 321, 16)) + self.plainTextEdit_compared = QPlainTextEdit(Form) + self.plainTextEdit_compared.setObjectName(u"plainTextEdit_compared") + self.plainTextEdit_compared.setGeometry(QRect(380, 30, 281, 301)) + self.pushButton_step2 = QPushButton(Form) + self.pushButton_step2.setObjectName(u"pushButton_step2") + self.pushButton_step2.setGeometry(QRect(670, 50, 70, 400)) + self.pushButton_step2.setFont(font) + self.splitter = QSplitter(Form) + self.splitter.setObjectName(u"splitter") + self.splitter.setGeometry(QRect(380, 340, 281, 131)) + self.splitter.setOrientation(Qt.Vertical) + self.layoutWidget = QWidget(self.splitter) + self.layoutWidget.setObjectName(u"layoutWidget") + self.horizontalLayout = QHBoxLayout(self.layoutWidget) + self.horizontalLayout.setObjectName(u"horizontalLayout") + self.horizontalLayout.setContentsMargins(0, 0, 0, 0) + self.label_3 = QLabel(self.layoutWidget) + self.label_3.setObjectName(u"label_3") + + self.horizontalLayout.addWidget(self.label_3) + + self.lineEdit_startingid = QLineEdit(self.layoutWidget) + self.lineEdit_startingid.setObjectName(u"lineEdit_startingid") + self.lineEdit_startingid.setDragEnabled(False) + self.lineEdit_startingid.setReadOnly(False) + + self.horizontalLayout.addWidget(self.lineEdit_startingid) + + self.splitter.addWidget(self.layoutWidget) + self.layoutWidget_2 = QWidget(self.splitter) + self.layoutWidget_2.setObjectName(u"layoutWidget_2") + self.horizontalLayout_2 = QHBoxLayout(self.layoutWidget_2) + self.horizontalLayout_2.setObjectName(u"horizontalLayout_2") + self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) + self.label_4 = QLabel(self.layoutWidget_2) + self.label_4.setObjectName(u"label_4") + + self.horizontalLayout_2.addWidget(self.label_4) + + self.lineEdit_editor = QLineEdit(self.layoutWidget_2) + self.lineEdit_editor.setObjectName(u"lineEdit_editor") + + self.horizontalLayout_2.addWidget(self.lineEdit_editor) + + self.splitter.addWidget(self.layoutWidget_2) + self.layoutWidget_3 = QWidget(self.splitter) + self.layoutWidget_3.setObjectName(u"layoutWidget_3") + self.horizontalLayout_3 = QHBoxLayout(self.layoutWidget_3) + self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") + self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0) + self.label_5 = QLabel(self.layoutWidget_3) + self.label_5.setObjectName(u"label_5") + + self.horizontalLayout_3.addWidget(self.label_5) + + self.lineEdit_origin = QLineEdit(self.layoutWidget_3) + self.lineEdit_origin.setObjectName(u"lineEdit_origin") + + self.horizontalLayout_3.addWidget(self.lineEdit_origin) + + self.splitter.addWidget(self.layoutWidget_3) + self.layoutWidget_4 = QWidget(self.splitter) + self.layoutWidget_4.setObjectName(u"layoutWidget_4") + self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_4) + self.horizontalLayout_4.setObjectName(u"horizontalLayout_4") + self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) + self.label_6 = QLabel(self.layoutWidget_4) + self.label_6.setObjectName(u"label_6") + + self.horizontalLayout_4.addWidget(self.label_6) + + self.lineEdit_suffix = QLineEdit(self.layoutWidget_4) + self.lineEdit_suffix.setObjectName(u"lineEdit_suffix") + self.lineEdit_suffix.setEnabled(False) + + self.horizontalLayout_4.addWidget(self.lineEdit_suffix) + + self.checkBox_suffix = QCheckBox(self.layoutWidget_4) + self.checkBox_suffix.setObjectName(u"checkBox_suffix") + + self.horizontalLayout_4.addWidget(self.checkBox_suffix) + + self.splitter.addWidget(self.layoutWidget_4) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6279\u91cf\u6536\u5f55\u65b0\u9898", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u8981\u5904\u7406\u7684\u9898\u76ee(\u6309 item \u5207\u5206, \u53ef\u4ee5\u5305\u542b\u6587\u4ef6\u5934)", None)) + self.pushButton_step1.setText(QCoreApplication.translate("Form", u"\u65b0\u9898\u6bd4\u5bf9", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u542b\u6709\u76f8\u4f3c\u9898\u76ee\u7684LaTeX\u6e90\u4ee3\u7801, \u590d\u5236\u5230LaTeX\u7f16\u8f91\u5668\u4eba\u5de5\u6807\u6ce8", None)) + self.pushButton_step2.setText(QCoreApplication.translate("Form", u"\u6536\u5f55\u9898\u76ee", None)) + self.label_3.setText(QCoreApplication.translate("Form", u"\u8d77\u59cbID", None)) + self.lineEdit_startingid.setInputMask("") + self.lineEdit_startingid.setPlaceholderText(QCoreApplication.translate("Form", u"\u6570\u5b57\u9898\u53f7(\u901a\u5e38\u662f10000n+1)", None)) + self.label_4.setText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005", None)) + self.lineEdit_editor.setPlaceholderText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005\u59d3\u540d", None)) + self.label_5.setText(QCoreApplication.translate("Form", u"\u6765\u6e90", None)) + self.lineEdit_origin.setText(QCoreApplication.translate("Form", u"\u81ea\u62df\u9898\u76ee", None)) + self.lineEdit_origin.setPlaceholderText(QCoreApplication.translate("Form", u"\u9898\u76ee\u6765\u6e90, \u901a\u5e38\u4e3a \u81ea\u62df\u9898\u76ee", None)) + self.label_6.setText(QCoreApplication.translate("Form", u"\u540e\u7f00", None)) + self.lineEdit_suffix.setText(QCoreApplication.translate("Form", u"\u8bd5\u9898", None)) + self.lineEdit_suffix.setPlaceholderText(QCoreApplication.translate("Form", u"\u901a\u5e38\u4e3a \u8bd5\u9898", None)) + self.checkBox_suffix.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u540e\u7f00", None)) + # retranslateUi + diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index 35b4bdcc..bdfde113 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -597,7 +597,7 @@ def AddProblemstoDict2024(startingid,raworigin,problems,editor,indexed,database) if pid > uid: val = (uid, pid) mycursor.execute(sql,val) - print(f"已收录题号: {pid}, 题目类型: {genre}, 题目来源: {origin['来源'] + ('试题'+str(origin['题号'])) if '题号' in origin else ''}, 题目内容: {p.strip()}") + print(f"已收录题号: {pid}, 题目类型: {genre}, 题目来源: {origin['来源'] + (('试题'+str(origin['题号'])) if '题号' in origin else '')}, 题目内容: {p.strip()}") id += 1 idlist.append(pid) else: diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index e1adba6f..2d6b6a10 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -13,6 +13,7 @@ from 指定题号编译pdf import MyWindow_xtby from 根据正确率选择题号 import MyWindow_ndsx from 关键字筛选题号 import MyWindow_sxth from 添加关联题目 import MyWindow_tjgl +from 批量收录新题 import MyWindow_bdsl from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -29,9 +30,13 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮 self.layout_kxth = QVBoxLayout(self.tab_kxth) - self.kxth = MyWindow_kxth(self.database) + self.kxth = MyWindow_kxth(self.database) self.layout_kxth.addWidget(self.kxth) #以上三行为初始化“空闲题号”tab + self.layout_bdsl = QVBoxLayout(self.tab_bdsl) + self.bdsl = MyWindow_bdsl(self.database) + self.layout_bdsl.addWidget(self.bdsl) #以上三行为初始化“新题录入”tab + self.layout_tjgl = QVBoxLayout(self.tab_tjgl) self.tjgl = MyWindow_tjgl(self.database) self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab @@ -86,7 +91,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.xtby.setdbname, self.ndsx.setdbname, self.sxth.setdbname, - self.tjgl.setdbname + self.tjgl.setdbname, + self.bdsl.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/批量收录新题.py b/工具v4/批量收录新题.py new file mode 100644 index 00000000..fb77317c --- /dev/null +++ b/工具v4/批量收录新题.py @@ -0,0 +1,113 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog +from Ui_批量收录新题 import Ui_Form +from database_tools_2 import * + +class MyWindow_bdsl(QWidget,Ui_Form): + def __init__(self,database_name): + super().__init__() + self.database_name = database_name + self.setupUi(self) + self.bind() + + def setdbname(self,string): + self.database_name = string + # print(self.database_name) + + def bind(self): + self.suffix_checked = True + self.checkBox_suffix.toggled.connect(self.togglesuffix) + self.pushButton_step1.clicked.connect(self.execstep1) + self.pushButton_step2.clicked.connect(self.execstep2) + def togglesuffix(self): + self.suffix_checked = self.checkBox_suffix.isChecked() + if self.suffix_checked: + self.lineEdit_suffix.setEnabled(True) + else: + self.lineEdit_suffix.setDisabled(True) + + def execstep1(self): + colors = ["green","orange","blue"] + templatepath = "./模板文件/讲义模板.txt" + + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() + + mycursor.execute("SELECT ID,content FROM problems;") + ret_list = mycursor.fetchall() + pro_dict = {i:j for i,j in ret_list} + treated_dict = {i:pre_treating(pro_dict[i]) for i in pro_dict.keys()} + mydb.close() + + data_raw = self.plainTextEdit_raw.toPlainText() + if data_raw.strip().startswith("\\item"): + data_raw = "\\begin{enumerate}\n"+data_raw + if data_raw.count("\\begin{enumerate}") == data_raw.count("\\end{enumerate}") + 1: + data_raw = data_raw + "\n\\end{enumerate}" + problems_raw = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate\}",data_raw) + data = "\n".join([item.strip() for item in problems_raw]) + problems = [(d.strip()) for d in data.split("\\item") if not d.strip() == ""] + output = "使用说明:\\\\\n rep??????表示使用已有题号??????,\\\\\n s??????表示和??????相同,\\\\\n r??????表示和??????相关\n\n\\begin{enumerate}\n\n" + + + for p in problems: + p_treated = pre_treating(p) + t = stringmaxsim(p_treated,treated_dict,5) + psrstring = "" + for id,simrate in t: + if simrate == 1: + psrstring = "rep"+id+"," + else: + psrstring += id + "," + if psrstring[-1] == ",": + psrstring = psrstring[:-1] + output += f"\\item [{psrstring}] {p}\n\n" + count = 0 + for id,simrate in t: + if simrate > 0.5: + colors = get_color(simrate*2-1) + output += "\n\\definecolor{mycolor}{rgb}"+colors + output += "\n\\begin{tcolorbox}"+f"[colback = mycolor, opacityback = 0.25, colframe = orange!10!white, breakable]\n" + output += f"{simrate:.3f} \\ {id}\n\n" + content = pro_dict[id] + output += f"{content}\n" + output += "\\end{tcolorbox}\n" + count += 1 + output += "\n\n" + output += "\n\\end{enumerate}\n\n" + + texraw = ReadTextFile(templatepath) + texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texraw,("新题比对"+f"{GetDate()}",output)) + self.plainTextEdit_compared.setPlainText(texdata) + + def execstep2(self): + starting_id = self.lineEdit_startingid.text().strip().zfill(6) + raworigin = self.lineEdit_origin.text().strip() + data = self.plainTextEdit_compared.toPlainText() + editor = self.lineEdit_editor.text().strip() + if self.checkBox_suffix.isChecked(): + Indexed = True + else: + Indexed = False + idlistpath = "文本文件/新题收录列表.txt" + problems = GenerateProblemListFromString2024(data) + # pro_dict = load_dict("../题库0.3/Problems.json") + nextspareid = NextSpareID(starting_id,self.database_name) + idlist = AddProblemstoDict2024(nextspareid,raworigin,problems,editor,Indexed,self.database_name) + # save_dict(SortDict(pro_dict),r"../题库0.3/Problems.json") + AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath) + os.system(f"code {idlistpath}") + + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow_bdsl("tikutest") + windows.show() + app.exec() + diff --git a/工具v4/批量收录新题.ui b/工具v4/批量收录新题.ui new file mode 100644 index 00000000..b401cc83 --- /dev/null +++ b/工具v4/批量收录新题.ui @@ -0,0 +1,211 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 批量收录新题 + + + + + 10 + 30 + 281 + 441 + + + + + + + 20 + 10 + 251 + 16 + + + + 要处理的题目(按 item 切分, 可以包含文件头) + + + + + + 300 + 50 + 70 + 400 + + + + + true + + + + 新题比对 + + + + + + 360 + 10 + 321 + 16 + + + + 含有相似题目的LaTeX源代码, 复制到LaTeX编辑器人工标注 + + + + + + 380 + 30 + 281 + 301 + + + + + + + 670 + 50 + 70 + 400 + + + + + true + + + + 收录题目 + + + + + + 380 + 340 + 281 + 131 + + + + Qt::Vertical + + + + + + + 起始ID + + + + + + + + + + false + + + false + + + 数字题号(通常是10000n+1) + + + + + + + + + + + 编辑者 + + + + + + + 编辑者姓名 + + + + + + + + + + + 来源 + + + + + + + 自拟题目 + + + 题目来源, 通常为 自拟题目 + + + + + + + + + + + 后缀 + + + + + + + false + + + 试题 + + + 通常为 试题 + + + + + + + 使用后缀 + + + + + + + + + + diff --git a/工具v4/文本文件/新题收录列表.txt b/工具v4/文本文件/新题收录列表.txt new file mode 100644 index 00000000..c7372d99 --- /dev/null +++ b/工具v4/文本文件/新题收录列表.txt @@ -0,0 +1,3 @@ +20240425-215540 +024789,000589,024790:024794 +