获取小闲平台使用数据new基本可以使用

This commit is contained in:
wangweiye7840 2024-03-21 12:44:26 +08:00
parent de4fabb00e
commit 21c0ed75ef
3 changed files with 109 additions and 106 deletions

View File

@ -26,16 +26,16 @@ class Ui_Form(object):
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.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, 81, 20))
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(624, 110, 81, 24))
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))
@ -61,6 +61,9 @@ class Ui_Form(object):
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)
@ -80,5 +83,6 @@ class Ui_Form(object):
___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

View File

@ -2,6 +2,7 @@ from PySide6.QtWidgets import QWidget, QApplication, QFileDialog, QTableWidgetIt
from PySide6.QtGui import QColor
from Ui_获取小闲平台使用数据new import Ui_Form
from database_tools import *
import shutil,zipfile
def getFilename(string):
@ -16,19 +17,26 @@ def getDate(string):
return ""
class MyWindow(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.singlefile = True
self.tablevalid = True
def getFilePath(self): #选取文件并放置在tableWidget的第一行
@ -36,7 +44,7 @@ class MyWindow(QWidget,Ui_Form):
pathlist = QFileDialog.getOpenFileName(self,"选择文件",".","zip文件(*.zip);;所有文件(*)")
self.zipfilepath = pathlist[0]
self.tableWidget.setItem(0,0,QTableWidgetItem(pathlist[0]))
self.singlefile = True
# self.singlefile = True
filename = getFilename(pathlist[0])
self.tableWidget.setItem(0,1,QTableWidgetItem(filename))
self.tableWidget.setItem(0,2,QTableWidgetItem(getDate(pathlist[0])))
@ -48,7 +56,7 @@ class MyWindow(QWidget,Ui_Form):
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
# self.singlefile = False
count = 0
for f in self.filelist:
if count + 1 > self.tableWidget.rowCount():
@ -57,110 +65,88 @@ class MyWindow(QWidget,Ui_Form):
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): #待修改
files = self.filelist
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} 未标注日期.")
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:
datedfiles.append(fpath)
for zipfpath in datedfiles:
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(0,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:
try:
shutil.rmtree(tempdir)
shutil.rmtree(self.tempdir)
except:
pass
makedir(tempdir)
date = re.findall(r"\((\d{8})\)",zipfpath)[0]
xiaoxianpid = ParseZipname(zipfpath)
paperinfo = FindPaper(xiaoxianpid, answersheetseekingpath)
makedir(self.tempdir)
try:
xiaoxianpid = ParseZipname(zipfilepath)
paperinfo = FindPaper(xiaoxianpid, self.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): #待修改
self.tableWidget.clearSelection()
self.tableWidget.item(0,2).setBackground(QColor("transparent"))
date = self.tableWidget.item(0,2).text()
threshold = float(self.lineEdit_threshold.text())
if not len(date.strip()) == 8:
self.tableWidget.item(0,2).setBackground(QColor("red"))
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
# print(paperinfo)
zf = zipfile.ZipFile(zipfilepath)
zf.extractall(self.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")
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)
return output #返回由usages开始的使用记录文本
except:
return 1 #无法生成就返回1
# else:
# print("数据有误, 可能需要检查每一题的满分数据")
# self.label_filepath.setText("数据有误, 可能需要检查每一题的满分数据")

View File

@ -16,9 +16,9 @@
<widget class="QPushButton" name="pushButton_file">
<property name="geometry">
<rect>
<x>624</x>
<x>620</x>
<y>70</y>
<width>81</width>
<width>91</width>
<height>24</height>
</rect>
</property>
@ -31,7 +31,7 @@
<rect>
<x>620</x>
<y>30</y>
<width>81</width>
<width>91</width>
<height>20</height>
</rect>
</property>
@ -52,9 +52,9 @@
<widget class="QPushButton" name="pushButton_folder">
<property name="geometry">
<rect>
<x>624</x>
<x>620</x>
<y>110</y>
<width>81</width>
<width>91</width>
<height>24</height>
</rect>
</property>
@ -128,6 +128,19 @@
<string>Append模式</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_validcheck">
<property name="geometry">
<rect>
<x>620</x>
<y>160</y>
<width>91</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>检查有效性</string>
</property>
</widget>
</widget>
<resources/>
<connections/>