From e88ebc34139a2183b6c59badea39a5e14d8299bb Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Thu, 25 Apr 2024 23:16:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=20=E5=B0=8F=E9=97=B2?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/Ui_获取小闲平台使用数据.py | 88 ++++++++++++++++ 工具v4/tool_panel.py | 5 + 工具v4/获取小闲平台使用数据.py | 163 ++++++++++++++++++++++++++++++ 工具v4/获取小闲平台使用数据.ui | 147 +++++++++++++++++++++++++++ 4 files changed, 403 insertions(+) create mode 100644 工具v4/Ui_获取小闲平台使用数据.py create mode 100644 工具v4/获取小闲平台使用数据.py create mode 100644 工具v4/获取小闲平台使用数据.ui diff --git a/工具v4/Ui_获取小闲平台使用数据.py b/工具v4/Ui_获取小闲平台使用数据.py new file mode 100644 index 00000000..9525eabe --- /dev/null +++ b/工具v4/Ui_获取小闲平台使用数据.py @@ -0,0 +1,88 @@ +# -*- 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, QHeaderView, QLabel, + QLineEdit, QPushButton, QSizePolicy, QTableWidget, + QTableWidgetItem, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(760, 490) + self.pushButton_file = QPushButton(Form) + self.pushButton_file.setObjectName(u"pushButton_file") + self.pushButton_file.setGeometry(QRect(620, 70, 91, 24)) + self.lineEdit_threshold = QLineEdit(Form) + self.lineEdit_threshold.setObjectName(u"lineEdit_threshold") + self.lineEdit_threshold.setGeometry(QRect(620, 30, 91, 20)) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(623, 10, 61, 20)) + self.pushButton_folder = QPushButton(Form) + self.pushButton_folder.setObjectName(u"pushButton_folder") + self.pushButton_folder.setGeometry(QRect(620, 110, 91, 24)) + self.pushButton_exec = QPushButton(Form) + self.pushButton_exec.setObjectName(u"pushButton_exec") + self.pushButton_exec.setGeometry(QRect(620, 270, 91, 75)) + font = QFont() + font.setBold(True) + self.pushButton_exec.setFont(font) + self.tableWidget = QTableWidget(Form) + if (self.tableWidget.columnCount() < 3): + self.tableWidget.setColumnCount(3) + __qtablewidgetitem = QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(0, __qtablewidgetitem) + __qtablewidgetitem1 = QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(1, __qtablewidgetitem1) + __qtablewidgetitem2 = QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(2, __qtablewidgetitem2) + if (self.tableWidget.rowCount() < 1): + self.tableWidget.setRowCount(1) + self.tableWidget.setObjectName(u"tableWidget") + self.tableWidget.setGeometry(QRect(10, 20, 600, 451)) + self.tableWidget.setRowCount(1) + self.tableWidget.setColumnCount(3) + self.tableWidget.horizontalHeader().setDefaultSectionSize(130) + self.checkBox = QCheckBox(Form) + self.checkBox.setObjectName(u"checkBox") + self.checkBox.setGeometry(QRect(620, 230, 91, 20)) + self.pushButton_validcheck = QPushButton(Form) + self.pushButton_validcheck.setObjectName(u"pushButton_validcheck") + self.pushButton_validcheck.setGeometry(QRect(620, 160, 91, 51)) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"Form", None)) + self.pushButton_file.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u8bbe\u5b9a\u9608\u503c", None)) + self.pushButton_folder.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6\u5939", None)) + self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u5f00\u59cb\u5206\u6790", None)) + ___qtablewidgetitem = self.tableWidget.horizontalHeaderItem(0) + ___qtablewidgetitem.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u540d", None)); + ___qtablewidgetitem1 = self.tableWidget.horizontalHeaderItem(1) + ___qtablewidgetitem1.setText(QCoreApplication.translate("Form", u"\u7b54\u9898\u7eb8\u540d\u79f0", None)); + ___qtablewidgetitem2 = self.tableWidget.horizontalHeaderItem(2) + ___qtablewidgetitem2.setText(QCoreApplication.translate("Form", u"\u4e2d\u4f4d\u626b\u63cf\u65e5\u671f", None)); + self.checkBox.setText(QCoreApplication.translate("Form", u"Append\u6a21\u5f0f", None)) + self.pushButton_validcheck.setText(QCoreApplication.translate("Form", u"\u68c0\u67e5\u6709\u6548\u6027", None)) + # retranslateUi + diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index b0e8c26b..f70df915 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -21,6 +21,7 @@ from 文件或文本框提取答案 import MyWindow_tqda from 单元挂钩 import MyWindow_dygg from 统考数据导入 import MyWindow_tkdr from 手动统计结果导入 import MyWindow_sddr +from 获取小闲平台使用数据 import MyWindow_xxdr from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -48,6 +49,10 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.tjgl = MyWindow_tjgl(self.database) self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab + self.layout_xxdr = QVBoxLayout(self.tab_xxdr) + self.xxdr = MyWindow_xxdr() + self.layout_xxdr.addWidget(self.xxdr) #以上三行为初始化“小闲统计数据导入”tab + self.layout_sddr = QVBoxLayout(self.tab_sddr) self.sddr = MyWindow_sddr() diff --git a/工具v4/获取小闲平台使用数据.py b/工具v4/获取小闲平台使用数据.py new file mode 100644 index 00000000..da37e028 --- /dev/null +++ b/工具v4/获取小闲平台使用数据.py @@ -0,0 +1,163 @@ +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetItem +from PySide6.QtGui import QColor +from Ui_获取小闲平台使用数据 import Ui_Form +from database_tools_2 import * +import shutil,zipfile + + +def getFilename(string): + filename = re.findall(r"\d{21}_([\s\S]*?)_高[一二三]_数学",string)[0] + return filename + +def getDate(string): + date = re.findall(r"\((\d{8})\).zip",string) + if len(date) > 0: + return date[0] + else: + return "" + +class MyWindow_xxdr(QWidget,Ui_Form): + + + + def __init__(self): + super().__init__() + self.setupUi(self) + self.bind() + def bind(self): + self.tempdir = "临时文件/zips" + self.statsfilename = "小题分_按学号(数学).xlsx" + self.answersheetseekingpath = "../备课组" + self.lineEdit_threshold.setText("0.75") + self.tableWidget.setColumnWidth(0,200) + self.tableWidget.setColumnWidth(1,280) + self.tableWidget.setColumnWidth(2,80) + self.pushButton_file.clicked.connect(self.getFilePath) + self.pushButton_folder.clicked.connect(self.getDirPath) + self.pushButton_validcheck.clicked.connect(self.checkpathanddate) + self.pushButton_exec.clicked.connect(self.exec) + self.tablevalid = True + + + def getFilePath(self): #选取文件并放置在tableWidget的第一行 + self.tableWidget.setRowCount(1) + pathlist = QFileDialog.getOpenFileName(self,"选择文件",".","zip文件(*.zip);;所有文件(*)") + self.zipfilepath = pathlist[0] + self.tableWidget.setItem(0,0,QTableWidgetItem(pathlist[0])) + # self.singlefile = True + filename = getFilename(pathlist[0]) + self.tableWidget.setItem(0,1,QTableWidgetItem(filename)) + self.tableWidget.setItem(0,2,QTableWidgetItem(getDate(pathlist[0]))) + + + + + + def getDirPath(self): #选取文件夹中的所有符合答题纸特征的.zip文件并放置在tableWidget中 + dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹") + self.filelist = [os.path.join(dirpath,f) for f in os.listdir(dirpath) if ".zip" in f and re.findall(r"\d{21}",f)!=[]] + # self.singlefile = False + count = 0 + for f in self.filelist: + if count + 1 > self.tableWidget.rowCount(): + self.tableWidget.insertRow(self.tableWidget.rowCount()) + self.tableWidget.setItem(count,0,QTableWidgetItem(f)) + self.tableWidget.setItem(count,1,QTableWidgetItem(getFilename(f))) + self.tableWidget.setItem(count,2,QTableWidgetItem(getDate(f))) + count += 1 + + + def checkpathanddate(self): #检查文件名和日期是否有效, 文件名无效标黄色, 日期无效标红色 + if not float(self.lineEdit_threshold.text()) >= 0 or not float(self.lineEdit_threshold.text()) <= 1: + self.lineEdit_threshold.setStyleSheet("background-color: red;") + self.tablevalid = False + self.using_rows = [] + self.tableWidget.clearSelection() + for t in range(self.tableWidget.rowCount()): + for i in range(3): + self.tableWidget.item(t,i).setBackground(QColor("transparent")) + for t in range(self.tableWidget.rowCount()): + if re.findall(r"\d{21}",self.tableWidget.item(t,0).text()) == [] or not len(self.tableWidget.item(t,2).text().strip()) == 8: + for i in range(3): + self.tableWidget.item(t,i).setBackground(QColor("yellow")) + else: + self.using_rows.append(t) + for row in range(self.tableWidget.rowCount()): + date = self.tableWidget.item(row,2).text() + if not len(date.strip()) == 8: + self.tableWidget.item(row,2).setBackground(QColor("red")) + + + + + + + + + + def exec(self): #执行操作并将使用数据汇入metadata.txt + self.checkpathanddate() + if len(self.using_rows) >= 2: + SaveTextFile("","文本文件/metadata.txt") + for row in self.using_rows: + date = self.tableWidget.item(row,2).text() + threshold = float(self.lineEdit_threshold.text()) + output = self.generateUsingInfo(zipfilepath=self.tableWidget.item(row,0).text(),threshold=threshold,date=date) + if output == 1 or CheckUsagesValidity(output) != 0: + for i in range(3): + self.tableWidget.item(row,i).setBackground(QColor("red")) + if output == 1: + print(f"{self.tableWidget.item(row,1).text()} 有问题, 未能生成使用数据") + else: + print(f"{self.tableWidget.item(row,1).text()} 满分设置有误, 请检查") + else: + for i in range(3): + self.tableWidget.item(row,i).setBackground(QColor("green")) + print(f"{self.tableWidget.item(row,1).text()} 使用数据生成成功") + if not self.checkBox.isChecked() and len(self.using_rows) == 1: + SaveTextFile(output,"文本文件/metadata.txt") + else: + AppendTextFile(output,"文本文件/metadata.txt") + os.system("code 文本文件/metadata.txt") + + + + def generateUsingInfo(self,zipfilepath,threshold,date): #根据zipfilepath文件路径, threshold最低提交比例阈值, date日期产生对应一张答题纸的使用记录 + try: + shutil.rmtree(self.tempdir) + except: + pass + makedir(self.tempdir) + try: + xiaoxianpid = ParseZipname(zipfilepath) + paperinfo = FindPaper(xiaoxianpid, self.answersheetseekingpath) + gradename = paperinfo[1] + idlist = paperinfo[2] + excludejson = paperinfo[4] + print(paperinfo) + # print(paperinfo) + zf = zipfile.ZipFile(zipfilepath) + zf.extractall(self.tempdir) #解压zip文件中的所有内容到tempdir + # # papertype = CheckPaperType(tempdir,statsfilename) + statsfilepathlist = FindFile(self.tempdir,self.statsfilename) + validcols,marks = generateColIndexandMarks(statsfilepathlist,self.statsfilename,paperinfo) + dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],self.statsfilename)) + correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols]) + output = CalculateUsages(statsfilepathlist,self.statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date,exclude=RefineExclude(excludejson)) + return output #返回由usages开始的使用记录文本 + except: + return 1 #无法生成就返回1 + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow_xxdr() + windows.show() + app.exec() + diff --git a/工具v4/获取小闲平台使用数据.ui b/工具v4/获取小闲平台使用数据.ui new file mode 100644 index 00000000..7e6f60b9 --- /dev/null +++ b/工具v4/获取小闲平台使用数据.ui @@ -0,0 +1,147 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + Form + + + + + 620 + 70 + 91 + 24 + + + + 选择文件 + + + + + + 620 + 30 + 91 + 20 + + + + + + + 623 + 10 + 61 + 20 + + + + 设定阈值 + + + + + + 620 + 110 + 91 + 24 + + + + 选择文件夹 + + + + + + 620 + 270 + 91 + 75 + + + + + true + + + + 开始分析 + + + + + + 10 + 20 + 600 + 451 + + + + 1 + + + 3 + + + 130 + + + + + 文件名 + + + + + 答题纸名称 + + + + + 中位扫描日期 + + + + + + + 620 + 230 + 91 + 20 + + + + Append模式 + + + + + + 620 + 160 + 91 + 51 + + + + 检查有效性 + + + + + +