添加关联题目工作中
This commit is contained in:
parent
ad0e31b495
commit
f98b98663a
|
|
@ -0,0 +1,98 @@
|
||||||
|
# -*- 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, QHBoxLayout, QLabel, QLineEdit,
|
||||||
|
QPushButton, QSizePolicy, QVBoxLayout, QWidget)
|
||||||
|
|
||||||
|
class Ui_Form(object):
|
||||||
|
def setupUi(self, Form):
|
||||||
|
if not Form.objectName():
|
||||||
|
Form.setObjectName(u"Form")
|
||||||
|
Form.resize(351, 104)
|
||||||
|
self.pushButton_exec = QPushButton(Form)
|
||||||
|
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||||
|
self.pushButton_exec.setGeometry(QRect(240, 10, 81, 81))
|
||||||
|
font = QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
self.pushButton_exec.setFont(font)
|
||||||
|
self.widget = QWidget(Form)
|
||||||
|
self.widget.setObjectName(u"widget")
|
||||||
|
self.widget.setGeometry(QRect(30, 10, 196, 80))
|
||||||
|
self.verticalLayout = QVBoxLayout(self.widget)
|
||||||
|
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||||
|
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
self.horizontalLayout = QHBoxLayout()
|
||||||
|
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||||
|
self.label = QLabel(self.widget)
|
||||||
|
self.label.setObjectName(u"label")
|
||||||
|
self.label.setMinimumSize(QSize(60, 0))
|
||||||
|
|
||||||
|
self.horizontalLayout.addWidget(self.label)
|
||||||
|
|
||||||
|
self.lineEdit_oldids = QLineEdit(self.widget)
|
||||||
|
self.lineEdit_oldids.setObjectName(u"lineEdit_oldids")
|
||||||
|
|
||||||
|
self.horizontalLayout.addWidget(self.lineEdit_oldids)
|
||||||
|
|
||||||
|
|
||||||
|
self.verticalLayout.addLayout(self.horizontalLayout)
|
||||||
|
|
||||||
|
self.horizontalLayout_2 = QHBoxLayout()
|
||||||
|
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||||
|
self.label_2 = QLabel(self.widget)
|
||||||
|
self.label_2.setObjectName(u"label_2")
|
||||||
|
|
||||||
|
self.horizontalLayout_2.addWidget(self.label_2)
|
||||||
|
|
||||||
|
self.lineEdit_newid = QLineEdit(self.widget)
|
||||||
|
self.lineEdit_newid.setObjectName(u"lineEdit_newid")
|
||||||
|
|
||||||
|
self.horizontalLayout_2.addWidget(self.lineEdit_newid)
|
||||||
|
|
||||||
|
|
||||||
|
self.verticalLayout.addLayout(self.horizontalLayout_2)
|
||||||
|
|
||||||
|
self.horizontalLayout_3 = QHBoxLayout()
|
||||||
|
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
|
||||||
|
self.label_3 = QLabel(self.widget)
|
||||||
|
self.label_3.setObjectName(u"label_3")
|
||||||
|
self.label_3.setMinimumSize(QSize(60, 0))
|
||||||
|
|
||||||
|
self.horizontalLayout_3.addWidget(self.label_3)
|
||||||
|
|
||||||
|
self.lineEdit_editor = QLineEdit(self.widget)
|
||||||
|
self.lineEdit_editor.setObjectName(u"lineEdit_editor")
|
||||||
|
|
||||||
|
self.horizontalLayout_3.addWidget(self.lineEdit_editor)
|
||||||
|
|
||||||
|
|
||||||
|
self.verticalLayout.addLayout(self.horizontalLayout_3)
|
||||||
|
|
||||||
|
|
||||||
|
self.retranslateUi(Form)
|
||||||
|
|
||||||
|
QMetaObject.connectSlotsByName(Form)
|
||||||
|
# setupUi
|
||||||
|
|
||||||
|
def retranslateUi(self, Form):
|
||||||
|
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u5173\u8054\u9898\u76ee", None))
|
||||||
|
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u5173\u8054\u9898\u76ee", None))
|
||||||
|
self.label.setText(QCoreApplication.translate("Form", u"\u65e7\u9898\u53f7", None))
|
||||||
|
self.label_2.setText(QCoreApplication.translate("Form", u"\u65b0\u8d77\u59cb\u9898\u53f7", None))
|
||||||
|
self.label_3.setText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005", None))
|
||||||
|
# retranslateUi
|
||||||
|
|
||||||
|
|
@ -285,15 +285,21 @@ def NextSpareID(num): #返回adict中下一个空闲的题号
|
||||||
num = int(num)
|
num = int(num)
|
||||||
while str(num).zfill(6) in idlist:
|
while str(num).zfill(6) in idlist:
|
||||||
num += 1
|
num += 1
|
||||||
|
mydb.close()
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def NextSpareIDBlock(num,adict): #返回adict中下一个空闲的题号块
|
def NextSpareIDBlock(num): #返回adict中下一个空闲的题号块
|
||||||
start = NextSpareID(num,adict)
|
mydb = connect(hostname = "wwylss.synology.me", port = "13306", username="root", pwd="Wwy@0018705", db = "tikutest")
|
||||||
larger_ID_list = [int(id) for id in adict.keys() if int(id)>start]
|
mycursor = mydb.cursor()
|
||||||
|
mycursor.execute("SELECT ID FROM problems;")
|
||||||
|
idlist = [ret[0] for ret in mycursor.fetchall()]
|
||||||
|
start = NextSpareID(num)
|
||||||
|
larger_ID_list = [int(id) for id in idlist if int(id)>start]
|
||||||
if larger_ID_list == []:
|
if larger_ID_list == []:
|
||||||
end = 999999
|
end = 999999
|
||||||
else:
|
else:
|
||||||
end = min(larger_ID_list) - 1
|
end = min(larger_ID_list) - 1
|
||||||
|
mydb.close()
|
||||||
return str(start)+":"+str(end)
|
return str(start)+":"+str(end)
|
||||||
|
|
||||||
def GenerateProblemListFromString(data): #从来自.tex文件的字符串生成题目列表, 每个item是一道题目, 新一行的%用作前缀
|
def GenerateProblemListFromString(data): #从来自.tex文件的字符串生成题目列表, 每个item是一道题目, 新一行的%用作前缀
|
||||||
|
|
@ -461,9 +467,7 @@ def AddProblemstoDict2024(startingid,raworigin,problems,editor,indexed): #将来
|
||||||
mydb.close()
|
mydb.close()
|
||||||
return idlist
|
return idlist
|
||||||
|
|
||||||
def CreateIDLinks(old_id_list,new_id_list,*thedict): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项
|
def CreateIDLinks(old_id_list,new_id_list): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项
|
||||||
if len(thedict) == 1 and type(thedict[0]) == dict:
|
|
||||||
new_id_list = [id for id in new_id_list if not id in thedict[0]]
|
|
||||||
if len(old_id_list)>len(new_id_list):
|
if len(old_id_list)>len(new_id_list):
|
||||||
return "新ID个数不足."
|
return "新ID个数不足."
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,57 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||||
|
from Ui_添加关联题目 import Ui_Form
|
||||||
|
from database_tools_2 import *
|
||||||
|
|
||||||
|
class MyWindow(QWidget,Ui_Form):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
|
||||||
|
def bind(self):
|
||||||
|
self.pushButton_exec.clicked.connect(self.exec)
|
||||||
|
|
||||||
|
def exec(self):
|
||||||
|
old_ids = RefinePunctuations(self.lineEdit_oldids.text()).strip() # 需要添加关联题目的id字符串
|
||||||
|
starting_id = self.lineEdit_newid.text().strip() # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20240124修改
|
||||||
|
editor = self.lineEdit_editor.text().strip() # 修改人姓名
|
||||||
|
new_ids = NextSpareIDBlock(starting_id)
|
||||||
|
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(new_ids))
|
||||||
|
print(old_ids,new_ids,editor)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# tempfilepath = "临时文件/problem_edit.json"
|
||||||
|
|
||||||
|
# pro_dict = load_dict("../题库0.3/Problems.json")
|
||||||
|
# obj_dict = load_dict("../题库0.3/LessonObj.json")
|
||||||
|
# pro_dict_raw_string = ReadTextFile("../题库0.3/Problems.json")
|
||||||
|
# configjson = BuildFullScheme
|
||||||
|
|
||||||
|
|
||||||
|
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
|
||||||
|
|
||||||
|
# print("编辑完毕后, 保存关闭文件继续.")
|
||||||
|
# os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
|
||||||
|
|
||||||
|
# editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/Problems.json")
|
||||||
|
|
||||||
|
# pro_dict = load_dict("../题库0.3/Problems.json")
|
||||||
|
|
||||||
|
# if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
|
||||||
|
# SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
|
||||||
|
# print("编译失败, 题库文件退回原状")
|
||||||
|
# else:
|
||||||
|
# print("编译成功, 已汇入题库")
|
||||||
|
# self.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?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>351</width>
|
||||||
|
<height>104</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>添加关联题目</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton_exec">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>240</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>81</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>添加关联题目</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>30</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>196</width>
|
||||||
|
<height>80</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>60</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>旧题号</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_oldids"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>新起始题号</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_newid"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>60</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>编辑者</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_editor"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue