用QtableWidget尝试重写获取小闲平台使用数据的功能, 进行中, execsingle/multifile待修改
This commit is contained in:
parent
cefbfac13e
commit
cd51a50f99
|
|
@ -0,0 +1,84 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
## Form generated from reading UI file '获取小闲平台使用数据new.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(727, 604)
|
||||||
|
self.pushButton_file = QPushButton(Form)
|
||||||
|
self.pushButton_file.setObjectName(u"pushButton_file")
|
||||||
|
self.pushButton_file.setGeometry(QRect(624, 70, 81, 24))
|
||||||
|
self.lineEdit_threshold = QLineEdit(Form)
|
||||||
|
self.lineEdit_threshold.setObjectName(u"lineEdit_threshold")
|
||||||
|
self.lineEdit_threshold.setGeometry(QRect(620, 30, 81, 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(624, 110, 81, 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, 10, 600, 581))
|
||||||
|
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.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))
|
||||||
|
# retranslateUi
|
||||||
|
|
||||||
|
|
@ -0,0 +1,173 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetItem
|
||||||
|
from Ui_获取小闲平台使用数据new import Ui_Form
|
||||||
|
from database_tools import *
|
||||||
|
|
||||||
|
|
||||||
|
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(QWidget,Ui_Form):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
def bind(self):
|
||||||
|
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_exec.clicked.connect(self.exec)
|
||||||
|
self.singlefile = 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 exec(self):
|
||||||
|
if self.singlefile:
|
||||||
|
self.execsinglefile()
|
||||||
|
else:
|
||||||
|
self.execmultifile()
|
||||||
|
|
||||||
|
def execmultifile(self): #待修改
|
||||||
|
directory = self.label_filepath.text()
|
||||||
|
files = [f for f in os.listdir(directory) if ".zip" in f]
|
||||||
|
datedfiles = []
|
||||||
|
tempdir = "临时文件/zips"
|
||||||
|
statsfilename = "小题分_按学号(数学).xlsx"
|
||||||
|
answersheetseekingpath = "../备课组"
|
||||||
|
glossoutput = ""
|
||||||
|
threshold = float(self.lineEdit_threshold.text())
|
||||||
|
for f in files:
|
||||||
|
fpath = os.path.join(directory,f)
|
||||||
|
if len(re.findall(r"\(\d{8}\)",f)) == 0:
|
||||||
|
print(f"文件 {f} 未标注日期.")
|
||||||
|
else:
|
||||||
|
datedfiles.append(fpath)
|
||||||
|
for zipfpath in datedfiles:
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
shutil.rmtree(tempdir)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
makedir(tempdir)
|
||||||
|
date = re.findall(r"\((\d{8})\)",zipfpath)[0]
|
||||||
|
xiaoxianpid = ParseZipname(zipfpath)
|
||||||
|
paperinfo = FindPaper(xiaoxianpid, answersheetseekingpath)
|
||||||
|
gradename = paperinfo[1]
|
||||||
|
idlist = paperinfo[2]
|
||||||
|
zf = zipfile.ZipFile(zipfpath)
|
||||||
|
zf.extractall(tempdir) #解压zip文件中的所有内容到tempdir
|
||||||
|
statsfilepathlist = FindFile(tempdir,statsfilename)
|
||||||
|
validcols,marks = generateColIndexandMarks(statsfilepathlist,statsfilename,paperinfo)
|
||||||
|
dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],statsfilename))
|
||||||
|
correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols])
|
||||||
|
output = CalculateUsages(statsfilepathlist,statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date)
|
||||||
|
if CheckUsagesValidity(output) == 0:
|
||||||
|
glossoutput += output
|
||||||
|
else:
|
||||||
|
print(f"{zipfpath} 数据有误, 可能需要检查每一题的满分数据")
|
||||||
|
self.label_filepath.setText(f"{zipfpath} 数据有误, 可能需要检查每一题的满分数据")
|
||||||
|
print(f"文件 {zipfpath} 处理完成")
|
||||||
|
except:
|
||||||
|
print(f"{zipfpath} 操作中有错误, 需要检查源数据")
|
||||||
|
self.label_filepath.setText(f"{zipfpath} 操作中有错误, 需要检查源数据")
|
||||||
|
SaveTextFile(glossoutput,"文本文件/metadata.txt")
|
||||||
|
os.system("code 文本文件/metadata.txt")
|
||||||
|
# print(datedfiles)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execsinglefile(self): #待修改
|
||||||
|
date = self.lineEdit_date.text()
|
||||||
|
threshold = float(self.lineEdit_threshold.text())
|
||||||
|
if not len(date.strip()) == 8:
|
||||||
|
self.lineEdit_date.setText("日期格式有误")
|
||||||
|
elif not threshold >= 0 or not threshold <= 1:
|
||||||
|
self.lineEdit_threshold.setText("阈值有误")
|
||||||
|
else:
|
||||||
|
tempdir = "临时文件/zips"
|
||||||
|
statsfilename = "小题分_按学号(数学).xlsx"
|
||||||
|
answersheetseekingpath = "../备课组"
|
||||||
|
try:
|
||||||
|
shutil.rmtree(tempdir)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
makedir(tempdir)
|
||||||
|
xiaoxianpid = ParseZipname(self.zipfilepath)
|
||||||
|
paperinfo = FindPaper(xiaoxianpid, answersheetseekingpath)
|
||||||
|
gradename = paperinfo[1]
|
||||||
|
idlist = paperinfo[2]
|
||||||
|
|
||||||
|
zf = zipfile.ZipFile(self.zipfilepath)
|
||||||
|
zf.extractall(tempdir) #解压zip文件中的所有内容到tempdir
|
||||||
|
|
||||||
|
# papertype = CheckPaperType(tempdir,statsfilename)
|
||||||
|
statsfilepathlist = FindFile(tempdir,statsfilename)
|
||||||
|
validcols,marks = generateColIndexandMarks(statsfilepathlist,statsfilename,paperinfo)
|
||||||
|
dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],statsfilename))
|
||||||
|
correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols])
|
||||||
|
output = CalculateUsages(statsfilepathlist,statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date)
|
||||||
|
if CheckUsagesValidity(output) == 0:
|
||||||
|
if not self.checkBox_appendflag.isChecked():
|
||||||
|
SaveTextFile(output,"文本文件/metadata.txt")
|
||||||
|
print("数据文件已输出至metadata.txt")
|
||||||
|
self.label_filepath.setText("数据文件已输出至metadata.txt")
|
||||||
|
os.system("code 文本文件/metadata.txt")
|
||||||
|
else:
|
||||||
|
AppendTextFile("\n\n"+output,"文本文件/metadata.txt")
|
||||||
|
print("数据文件已添加至metadata.txt")
|
||||||
|
self.label_filepath.setText("数据文件已添加至metadata.txt")
|
||||||
|
os.system("code 文本文件/metadata.txt")
|
||||||
|
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("数据有误, 可能需要检查每一题的满分数据")
|
||||||
|
self.label_filepath.setText("数据有误, 可能需要检查每一题的满分数据")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,134 @@
|
||||||
|
<?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>727</width>
|
||||||
|
<height>604</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Form</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton_file">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>624</x>
|
||||||
|
<y>70</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>选择文件</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_threshold">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>620</x>
|
||||||
|
<y>30</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>623</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>61</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>设定阈值</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="pushButton_folder">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>624</x>
|
||||||
|
<y>110</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>选择文件夹</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="pushButton_exec">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>620</x>
|
||||||
|
<y>270</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>75</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>开始分析</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QTableWidget" name="tableWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>600</width>
|
||||||
|
<height>581</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="rowCount">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="columnCount">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||||
|
<number>130</number>
|
||||||
|
</attribute>
|
||||||
|
<row/>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>文件名</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>答题纸名称</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>中位扫描日期</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
<widget class="QCheckBox" name="checkBox">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>620</x>
|
||||||
|
<y>230</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Append模式</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue