迁移 统考数据导入

This commit is contained in:
weiye.wang 2024-04-25 23:04:44 +08:00
parent 31a4ccfbc1
commit fdf7887d1f
4 changed files with 551 additions and 0 deletions

View File

@ -0,0 +1,176 @@
# -*- 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,
QPlainTextEdit, QPushButton, QSizePolicy, QVBoxLayout,
QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(760, 490)
self.layoutWidget = QWidget(Form)
self.layoutWidget.setObjectName(u"layoutWidget")
self.layoutWidget.setGeometry(QRect(120, 170, 381, 54))
self.verticalLayout_2 = QVBoxLayout(self.layoutWidget)
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.label_2 = QLabel(self.layoutWidget)
self.label_2.setObjectName(u"label_2")
self.label_2.setMinimumSize(QSize(180, 0))
self.label_2.setMaximumSize(QSize(180, 16777215))
self.horizontalLayout_2.addWidget(self.label_2)
self.pushButton_excel = QPushButton(self.layoutWidget)
self.pushButton_excel.setObjectName(u"pushButton_excel")
self.pushButton_excel.setMinimumSize(QSize(60, 0))
self.horizontalLayout_2.addWidget(self.pushButton_excel)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.lineEdit_excelfile = QLineEdit(self.layoutWidget)
self.lineEdit_excelfile.setObjectName(u"lineEdit_excelfile")
self.lineEdit_excelfile.setReadOnly(True)
self.verticalLayout_2.addWidget(self.lineEdit_excelfile)
self.layoutWidget_2 = QWidget(Form)
self.layoutWidget_2.setObjectName(u"layoutWidget_2")
self.layoutWidget_2.setGeometry(QRect(120, 260, 194, 22))
self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_2)
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.label_4 = QLabel(self.layoutWidget_2)
self.label_4.setObjectName(u"label_4")
self.label_4.setMinimumSize(QSize(100, 0))
self.horizontalLayout_4.addWidget(self.label_4)
self.lineEdit_grade = QLineEdit(self.layoutWidget_2)
self.lineEdit_grade.setObjectName(u"lineEdit_grade")
self.horizontalLayout_4.addWidget(self.lineEdit_grade)
self.layoutWidget_3 = QWidget(Form)
self.layoutWidget_3.setObjectName(u"layoutWidget_3")
self.layoutWidget_3.setGeometry(QRect(120, 290, 194, 22))
self.horizontalLayout_5 = QHBoxLayout(self.layoutWidget_3)
self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.label_5 = QLabel(self.layoutWidget_3)
self.label_5.setObjectName(u"label_5")
self.label_5.setMinimumSize(QSize(100, 0))
self.horizontalLayout_5.addWidget(self.label_5)
self.lineEdit_classnum = QLineEdit(self.layoutWidget_3)
self.lineEdit_classnum.setObjectName(u"lineEdit_classnum")
self.horizontalLayout_5.addWidget(self.lineEdit_classnum)
self.plainTextEdit = QPlainTextEdit(Form)
self.plainTextEdit.setObjectName(u"plainTextEdit")
self.plainTextEdit.setGeometry(QRect(510, 110, 141, 201))
self.plainTextEdit.setReadOnly(True)
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(320, 230, 181, 81))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.layoutWidget1 = QWidget(Form)
self.layoutWidget1.setObjectName(u"layoutWidget1")
self.layoutWidget1.setGeometry(QRect(120, 110, 381, 54))
self.verticalLayout = QVBoxLayout(self.layoutWidget1)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.label = QLabel(self.layoutWidget1)
self.label.setObjectName(u"label")
self.label.setMinimumSize(QSize(180, 0))
self.label.setMaximumSize(QSize(180, 16777215))
self.horizontalLayout.addWidget(self.label)
self.pushButton_paper = QPushButton(self.layoutWidget1)
self.pushButton_paper.setObjectName(u"pushButton_paper")
self.pushButton_paper.setMinimumSize(QSize(60, 0))
self.horizontalLayout.addWidget(self.pushButton_paper)
self.verticalLayout.addLayout(self.horizontalLayout)
self.lineEdit_paperfile = QLineEdit(self.layoutWidget1)
self.lineEdit_paperfile.setObjectName(u"lineEdit_paperfile")
self.lineEdit_paperfile.setReadOnly(True)
self.verticalLayout.addWidget(self.lineEdit_paperfile)
self.layoutWidget2 = QWidget(Form)
self.layoutWidget2.setObjectName(u"layoutWidget2")
self.layoutWidget2.setGeometry(QRect(120, 230, 194, 22))
self.horizontalLayout_3 = QHBoxLayout(self.layoutWidget2)
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.label_3 = QLabel(self.layoutWidget2)
self.label_3.setObjectName(u"label_3")
self.label_3.setMinimumSize(QSize(100, 0))
self.horizontalLayout_3.addWidget(self.label_3)
self.lineEdit_date = QLineEdit(self.layoutWidget2)
self.lineEdit_date.setObjectName(u"lineEdit_date")
self.lineEdit_date.setMaximumSize(QSize(100, 16777215))
self.horizontalLayout_3.addWidget(self.lineEdit_date)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u7edf\u8003\u6570\u636e\u5bfc\u5165", None))
self.label_2.setText(QCoreApplication.translate("Form", u"\u7edf\u8ba1\u6587\u4ef6(.xlsx)", None))
self.pushButton_excel.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u9009\u62e9", None))
self.label_4.setText(QCoreApplication.translate("Form", u"\u5e74\u7ea7", None))
self.lineEdit_grade.setPlaceholderText(QCoreApplication.translate("Form", u"\u5982 2026\u5c4a\u9ad8\u4e00", None))
self.label_5.setText(QCoreApplication.translate("Form", u"\u73ed\u7ea7\u6570", None))
self.lineEdit_classnum.setPlaceholderText(QCoreApplication.translate("Form", u"\u5982 12", None))
self.plainTextEdit.setDocumentTitle("")
self.plainTextEdit.setPlainText(QCoreApplication.translate("Form", u"\u8bf4\u660e:\n"
".xlsx\u6587\u4ef6\u9700\u8981\u6709\u4e00\u4e2a\u540d\u4e3a\"\u96be\u5ea6\u7edf\u8ba1\"\u7684\u6570\u636e\u8868.\n"
"\u7b2c\u4e00\u5217\u4ece\u7b2c\u4e8c\u884c\u8d77\u4e3a\u73ed\u7ea7\u53f7, \u7b2c\u4e00\u884c\u4ece\u7b2c\u4e8c\u5217\u8d77\u4e3a\u9898\u53f7.\n"
"\u4f8b\u5982: 1,2,3,4,5,61,62,71,72,73,8,9,101,102,...\n"
"", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u7edf\u8003\u6570\u636e\u5bfc\u5165\n"
"metadata.txt", None))
self.label.setText(QCoreApplication.translate("Form", u"\u8bd5\u5377\u6587\u4ef6(.tex\u6216.pdf)", None))
self.pushButton_paper.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u9009\u62e9", None))
self.label_3.setText(QCoreApplication.translate("Form", u"\u65e5\u671f(yyyymmdd)", None))
self.lineEdit_date.setPlaceholderText(QCoreApplication.translate("Form", u"\u5982 20240101", None))
# retranslateUi

View File

@ -19,6 +19,7 @@ from 新增基础知识梳理 import MyWindow_tjjc
from 共享使用记录 import MyWindow_gxsy
from 文件或文本框提取答案 import MyWindow_tqda
from 单元挂钩 import MyWindow_dygg
from 统考数据导入 import MyWindow_tkdr
from database_tools_2 import *
class MyWindow(QMainWindow,Ui_MainWindow):
@ -46,6 +47,11 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.tjgl = MyWindow_tjgl(self.database)
self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab
self.layout_tkdr = QVBoxLayout(self.tab_tkdr)
self.tkdr = MyWindow_tkdr()
self.layout_tkdr.addWidget(self.tkdr) #以上三行为初始化“提取答案”tab
self.layout_dygg = QVBoxLayout(self.tab_dygg)
self.dygg = MyWindow_dygg(self.database)
self.layout_dygg.addWidget(self.dygg) #以上三行为初始化“单元挂钩”tab

View File

@ -0,0 +1,96 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_统考数据导入 import Ui_Form
import os
from database_tools_2 import *
class MyWindow_tkdr(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.pushButton_paper.clicked.connect(self.selectpaper)
self.pushButton_excel.clicked.connect(self.selectexcel)
self.pushButton_exec.clicked.connect(self.exec)
def selectpaper(self):
self.texfile = QFileDialog.getOpenFileName(self,"选择试卷文件",os.getcwd(),"试卷文件(*.tex *.pdf);;所有文件(*)")[0]
self.lineEdit_paperfile.setText(self.texfile)
def selectexcel(self):
self.excelfile = QFileDialog.getOpenFileName(self,"选择统计文件",os.getcwd(),"Excel文件(*.xlsx);;所有文件(*)")[0]
self.lineEdit_excelfile.setText(self.excelfile)
def exec(self):
sheetname = "难度统计" # excel中难度数据所在的工作表名
date = self.lineEdit_date.text().strip() # 考试日期
grade = self.lineEdit_grade.text().strip() # 考试年级
max_classnum = int(self.lineEdit_classnum.text().strip()) # 年级参加考试的最大班级班号
outputfilepath = r"文本文件/metadata.txt" # 输出的用于导入的metadata.txt文件位置
checkingfilepath = r"临时文件/手动统计结果.txt" # 用于检查结构的文件所在位置
df = pd.read_excel(self.excelfile,sheet_name = sheetname)
problems_list = generate_number_set(extractIDs(self.texfile))
#生成题号(1~n)与题库id对应
id_dict = {}
for i in range(len(problems_list)):
id_dict[i+1] = problems_list[i]
output = "usages\n\n"
checkoutput = ""
#生成题号(1~n)与表格中数据列的对应
idcol_dict = {}
for i in id_dict:
idcol_dict[i] = []
mincol = -1
for col_index in range(mincol+1,len(df.columns)):
col = df.columns[col_index]
if str(col).startswith(str(i)):
idcol_dict[i].append(col_index)
mincol = col_index
if str(i) == str(col):
break
#生成行号与班级的对应列表
classrows_dict = {}
for row in df.iloc[:,0]:
if type(row) == int or type(row) == float:
if 1<=row<=max_classnum:
row = int(row)
classrows_dict[list(df.iloc[:,0]).index(row)] = str(row).zfill(2) + ""
#生成手动统计列表
for cl in classrows_dict:
classname = grade + classrows_dict[cl]
checkoutput += "[BEGIN]\n"
checkoutput += "## "+date+"\n"
checkoutput += "** "+classname+"\n"
for i in range(len(problems_list)):
id = id_dict[i+1]
results_cols = idcol_dict[i+1]
results = []
for col in results_cols:
results.append("%.3f"%df.iloc[cl,col])
checkoutput += id+"\t"+"\t".join(results) + "\n"
output += id + "\n" + "\t".join([date,classname]+results) + "\n\n"
checkoutput += "[END]\n\n\n"
SaveTextFile(output,outputfilepath)
print("可以在 %s 文件中检查结构"%(SaveTextFile(checkoutput,checkingfilepath)))
os.system("code %s"%checkingfilepath)
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow_tkdr()
windows.show()
app.exec()

View File

@ -0,0 +1,273 @@
<?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="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>120</x>
<y>170</y>
<width>381</width>
<height>54</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>180</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>180</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>统计文件(.xlsx)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_excel">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>文件选择</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_excelfile">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget_2">
<property name="geometry">
<rect>
<x>120</x>
<y>260</y>
<width>194</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>年级</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_grade">
<property name="placeholderText">
<string>如 2026届高一</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget_3">
<property name="geometry">
<rect>
<x>120</x>
<y>290</y>
<width>194</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>班级数</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_classnum">
<property name="placeholderText">
<string>如 12</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit">
<property name="geometry">
<rect>
<x>510</x>
<y>110</y>
<width>141</width>
<height>201</height>
</rect>
</property>
<property name="documentTitle">
<string/>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string>说明:
.xlsx文件需要有一个名为&quot;难度统计&quot;的数据表.
第一列从第二行起为班级号, 第一行从第二列起为题号.
例如: 1,2,3,4,5,61,62,71,72,73,8,9,101,102,...
</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>320</x>
<y>230</y>
<width>181</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>统考数据导入
metadata.txt</string>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>120</x>
<y>110</y>
<width>381</width>
<height>54</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>180</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>180</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>试卷文件(.tex或.pdf)</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_paper">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>文件选择</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_paperfile">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>120</x>
<y>230</y>
<width>194</width>
<height>22</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>日期(yyyymmdd)</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_date">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="placeholderText">
<string>如 20240101</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>