迁移 单元挂钩

This commit is contained in:
weiye.wang 2024-04-25 22:56:50 +08:00
parent a5712273e6
commit 31a4ccfbc1
5 changed files with 215 additions and 7 deletions

View File

@ -0,0 +1,58 @@
# -*- 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, QLabel, QLineEdit, QPushButton,
QRadioButton, QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(760, 490)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(200, 190, 54, 16))
self.radioButton_phase2 = QRadioButton(Form)
self.radioButton_phase2.setObjectName(u"radioButton_phase2")
self.radioButton_phase2.setGeometry(QRect(200, 240, 191, 20))
self.lineEdit_ids = QLineEdit(Form)
self.lineEdit_ids.setObjectName(u"lineEdit_ids")
self.lineEdit_ids.setGeometry(QRect(200, 210, 271, 20))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(490, 160, 71, 111))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.radioButton_phase1 = QRadioButton(Form)
self.radioButton_phase1.setObjectName(u"radioButton_phase1")
self.radioButton_phase1.setGeometry(QRect(200, 170, 141, 20))
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u5355\u5143\u6302\u94a9", None))
self.label.setText(QCoreApplication.translate("Form", u"\u9898\u53f7", None))
self.radioButton_phase2.setText(QCoreApplication.translate("Form", u"\u6536\u5f55\u5355\u5143\u4fe1\u606f\u81f3metadata\u9636\u6bb5", None))
self.lineEdit_ids.setPlaceholderText(QCoreApplication.translate("Form", u"\u8f93\u5165\u9898\u53f7, \u7559\u7a7a\u8868\u793a\u9488\u5bf9\u6240\u6709\u6ca1\u6709\u5bf9\u5e94\u5355\u5143\u7684\u9898\u76ee", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u8fd0\u884c", None))
self.radioButton_phase1.setText(QCoreApplication.translate("Form", u"\u81ea\u9002\u5e94\u8d4b\u4e88\u5355\u5143\u4fe1\u606f", None))
# retranslateUi

View File

@ -2479,26 +2479,26 @@ def unUnitted(idexp,database): #返回adict中未赋单元的id列表
return ununittedids return ununittedids
def AutoAssignTagNotoLaTeX(newlist,allsamelist,allrelatedlist): def AutoAssignTagNotoLaTeX(newlist,allsamelist,allrelatedlist,db):
output = "\\begin{enumerate}\n\n" output = "\\begin{enumerate}\n\n"
tagrecord = "" tagrecord = ""
print("正在生成简化题目的字典...") print("正在生成简化题目的字典...")
treateddict = treat_dict() treateddict = treat_dict(db)
print("简化题目字典生成完毕.") print("简化题目字典生成完毕.")
for id in tqdm.tqdm(newlist): for id in tqdm.tqdm(newlist):
samelist = findsru(id,allsamelist) samelist = findsru(id,allsamelist)
relatedlist = findsru(id,allrelatedlist) relatedlist = findsru(id,allrelatedlist)
if not samelist == []: if not samelist == []:
unittags = get_unit_tags(samelist[0]) unittags = get_unit_tags(samelist[0],db)
elif not relatedlist == []: elif not relatedlist == []:
unittags = get_unit_tags(relatedlist[0]) unittags = get_unit_tags(relatedlist[0],db)
else: else:
simgroup = stringmaxsim(treateddict[id],treateddict,10) simgroup = stringmaxsim(treateddict[id],treateddict,10)
unittags_raw = {} unittags_raw = {}
for g in simgroup: for g in simgroup:
rid,sim = g rid,sim = g
if not rid == id and sim > 0.75: if not rid == id and sim > 0.75:
for t in get_unit_tags(rid): for t in get_unit_tags(rid,db):
if t in unittags_raw: if t in unittags_raw:
unittags_raw[t] += 1 unittags_raw[t] += 1
else: else:
@ -2510,7 +2510,7 @@ def AutoAssignTagNotoLaTeX(newlist,allsamelist,allrelatedlist):
tagnumbers = "" tagnumbers = ""
for u in unittags: for u in unittags:
tagnumbers += str(getUnitNumber(u)) tagnumbers += str(getUnitNumber(u))
output += f"\\item ({id})[{tagnumbers}] {get_problem_content(id)}\n\n" output += f"\\item ({id})[{tagnumbers}] {get_problem_content(id,db)}\n\n"
tagrecord += f"{id}\t{tagnumbers}\n" tagrecord += f"{id}\t{tagnumbers}\n"
output += "\\end{enumerate}\n\n" output += "\\end{enumerate}\n\n"
return (output,tagrecord) return (output,tagrecord)

View File

@ -18,6 +18,7 @@ from 下载小闲答题数据 import MyWindow_xxxz
from 新增基础知识梳理 import MyWindow_tjjc from 新增基础知识梳理 import MyWindow_tjjc
from 共享使用记录 import MyWindow_gxsy from 共享使用记录 import MyWindow_gxsy
from 文件或文本框提取答案 import MyWindow_tqda from 文件或文本框提取答案 import MyWindow_tqda
from 单元挂钩 import MyWindow_dygg
from database_tools_2 import * from database_tools_2 import *
class MyWindow(QMainWindow,Ui_MainWindow): class MyWindow(QMainWindow,Ui_MainWindow):
@ -45,6 +46,10 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.tjgl = MyWindow_tjgl(self.database) self.tjgl = MyWindow_tjgl(self.database)
self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab
self.layout_dygg = QVBoxLayout(self.tab_dygg)
self.dygg = MyWindow_dygg(self.database)
self.layout_dygg.addWidget(self.dygg) #以上三行为初始化“单元挂钩”tab
self.layout_tqda = QVBoxLayout(self.tab_tqda) self.layout_tqda = QVBoxLayout(self.tab_tqda)
self.tqda = MyWindow_tqda() self.tqda = MyWindow_tqda()
self.layout_tqda.addWidget(self.tqda) #以上三行为初始化“提取答案”tab self.layout_tqda.addWidget(self.tqda) #以上三行为初始化“提取答案”tab
@ -113,7 +118,8 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.tjgl.setdbname, self.tjgl.setdbname,
self.bdsl.setdbname, self.bdsl.setdbname,
self.tjjc.setdbname, self.tjjc.setdbname,
self.gxsy.setdbname self.gxsy.setdbname,
self.dygg.setdbname
]: #在列表中的tab里传送数据库名的连接 ]: #在列表中的tab里传送数据库名的连接
self.sendDBname.connect(func) self.sendDBname.connect(func)
def sendValue(self): def sendValue(self):

55
工具v4/单元挂钩.py Normal file
View File

@ -0,0 +1,55 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_单元挂钩 import Ui_Form
from database_tools_2 import *
class MyWindow_dygg(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.radioButton_phase1.setChecked(True)
self.pushButton_exec.clicked.connect(self.exec)
def exec(self):
# pro_dict = load_dict("../题库0.3/Problems.json")
allids = getAllIDsExp(self.database_name)
all_same_list = generate_same_list(self.database_name)
all_related_list = generate_related_list(self.database_name)
if self.radioButton_phase1.isChecked():
idexp = self.lineEdit_ids.text()
if idexp.strip() == "":
idlist = unUnitted(allids,self.database_name)
else:
idlist = generate_number_set(idexp)
latex_body,tagrec = AutoAssignTagNotoLaTeX(idlist,all_same_list,all_related_list,self.database_name)
latex_raw = ReadTextFile("模板文件/讲义模板.txt")
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("待检查单元",latex_body))
SaveTextFile(tagrec,"临时文件/单元对应.txt")
SaveTextFile(latex_data,"临时文件/待检查单元.tex")
if XeLaTeXCompile("临时文件","待检查单元.tex") == True:
print("处理成功.")
os.system("code 临时文件/单元对应.txt 临时文件/待检查单元.pdf")
else:
print("处理失败.")
elif self.radioButton_phase2.isChecked():
output = UnitRectoMetadataText(ReadTextFile("临时文件/单元对应.txt"))
SaveTextFile(output,"文本文件/metadata.txt")
os.system("code 文本文件/metadata.txt")
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow_dygg()
windows.show()
app.exec()

89
工具v4/单元挂钩.ui Normal file
View File

@ -0,0 +1,89 @@
<?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>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>200</x>
<y>190</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>题号</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_phase2">
<property name="geometry">
<rect>
<x>200</x>
<y>240</y>
<width>191</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>收录单元信息至metadata阶段</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_ids">
<property name="geometry">
<rect>
<x>200</x>
<y>210</y>
<width>271</width>
<height>20</height>
</rect>
</property>
<property name="placeholderText">
<string>输入题号, 留空表示针对所有没有对应单元的题目</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>490</x>
<y>160</y>
<width>71</width>
<height>111</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>运行</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_phase1">
<property name="geometry">
<rect>
<x>200</x>
<y>170</y>
<width>141</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>自适应赋予单元信息</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>