From 640d59234da1c79694d5f3ef227cf0c06c9545ab Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Tue, 16 Apr 2024 11:46:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=80=83=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=20=E8=BF=81=E7=A7=BB=E8=87=B3=20=E5=B7=A5=E5=85=B7v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/Ui_统考数据导入.py | 176 ++++++++++++++++++++++++ 工具v3/统考数据导入.py | 97 ++++++++++++++ 工具v3/统考数据导入.ui | 273 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 546 insertions(+) create mode 100644 工具v3/Ui_统考数据导入.py create mode 100644 工具v3/统考数据导入.py create mode 100644 工具v3/统考数据导入.ui diff --git a/工具v3/Ui_统考数据导入.py b/工具v3/Ui_统考数据导入.py new file mode 100644 index 00000000..c024a5ac --- /dev/null +++ b/工具v3/Ui_统考数据导入.py @@ -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(552, 220) + self.layoutWidget = QWidget(Form) + self.layoutWidget.setObjectName(u"layoutWidget") + self.layoutWidget.setGeometry(QRect(10, 70, 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(10, 160, 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(10, 190, 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(400, 10, 141, 201)) + self.plainTextEdit.setReadOnly(True) + self.pushButton_exec = QPushButton(Form) + self.pushButton_exec.setObjectName(u"pushButton_exec") + self.pushButton_exec.setGeometry(QRect(210, 130, 181, 81)) + font = QFont() + font.setBold(True) + self.pushButton_exec.setFont(font) + self.widget = QWidget(Form) + self.widget.setObjectName(u"widget") + self.widget.setGeometry(QRect(10, 10, 381, 54)) + 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(180, 0)) + self.label.setMaximumSize(QSize(180, 16777215)) + + self.horizontalLayout.addWidget(self.label) + + self.pushButton_paper = QPushButton(self.widget) + 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.widget) + self.lineEdit_paperfile.setObjectName(u"lineEdit_paperfile") + self.lineEdit_paperfile.setReadOnly(True) + + self.verticalLayout.addWidget(self.lineEdit_paperfile) + + self.widget1 = QWidget(Form) + self.widget1.setObjectName(u"widget1") + self.widget1.setGeometry(QRect(10, 130, 194, 22)) + self.horizontalLayout_3 = QHBoxLayout(self.widget1) + self.horizontalLayout_3.setObjectName(u"horizontalLayout_3") + self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0) + self.label_3 = QLabel(self.widget1) + 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.widget1) + 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 + diff --git a/工具v3/统考数据导入.py b/工具v3/统考数据导入.py new file mode 100644 index 00000000..6e892924 --- /dev/null +++ b/工具v3/统考数据导入.py @@ -0,0 +1,97 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog +from Ui_统考数据导入 import Ui_Form +import os +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_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 -w %s"%checkingfilepath) + self.close() + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow() + windows.show() + app.exec() + diff --git a/工具v3/统考数据导入.ui b/工具v3/统考数据导入.ui new file mode 100644 index 00000000..4f696c90 --- /dev/null +++ b/工具v3/统考数据导入.ui @@ -0,0 +1,273 @@ + + + Form + + + + 0 + 0 + 552 + 220 + + + + 统考数据导入 + + + + + 10 + 70 + 381 + 54 + + + + + + + + + + 180 + 0 + + + + + 180 + 16777215 + + + + 统计文件(.xlsx) + + + + + + + + 60 + 0 + + + + 文件选择 + + + + + + + + + true + + + + + + + + + 10 + 160 + 194 + 22 + + + + + + + + 100 + 0 + + + + 年级 + + + + + + + 如 2026届高一 + + + + + + + + + 10 + 190 + 194 + 22 + + + + + + + + 100 + 0 + + + + 班级数 + + + + + + + 如 12 + + + + + + + + + 400 + 10 + 141 + 201 + + + + + + + true + + + 说明: +.xlsx文件需要有一个名为"难度统计"的数据表. +第一列从第二行起为班级号, 第一行从第二列起为题号. +例如: 1,2,3,4,5,61,62,71,72,73,8,9,101,102,... + + + + + + + 210 + 130 + 181 + 81 + + + + + true + + + + 统考数据导入 +metadata.txt + + + + + + 10 + 10 + 381 + 54 + + + + + + + + + + 180 + 0 + + + + + 180 + 16777215 + + + + 试卷文件(.tex或.pdf) + + + + + + + + 60 + 0 + + + + 文件选择 + + + + + + + + + true + + + + + + + + + 10 + 130 + 194 + 22 + + + + + + + + 100 + 0 + + + + 日期(yyyymmdd) + + + + + + + + 100 + 16777215 + + + + 如 20240101 + + + + + + + + +