获取小闲平台使用数据功能新增文件夹统一处理功能

This commit is contained in:
weiye.wang 2024-03-17 12:20:16 +08:00
parent 1fafd8196a
commit d657b56cae
3 changed files with 129 additions and 2 deletions

View File

@ -53,6 +53,18 @@ class Ui_Form(object):
self.lineEdit_threshold = QLineEdit(Form)
self.lineEdit_threshold.setObjectName(u"lineEdit_threshold")
self.lineEdit_threshold.setGeometry(QRect(420, 10, 113, 20))
self.pushButton_selectdirpath = QPushButton(Form)
self.pushButton_selectdirpath.setObjectName(u"pushButton_selectdirpath")
self.pushButton_selectdirpath.setGeometry(QRect(390, 40, 75, 24))
self.label_5 = QLabel(Form)
self.label_5.setObjectName(u"label_5")
self.label_5.setGeometry(QRect(290, 40, 101, 20))
self.label_6 = QLabel(Form)
self.label_6.setObjectName(u"label_6")
self.label_6.setGeometry(QRect(230, 40, 31, 16))
font = QFont()
font.setBold(True)
self.label_6.setFont(font)
self.retranslateUi(Form)
@ -65,9 +77,12 @@ class Ui_Form(object):
self.label.setText(QCoreApplication.translate("Form", u"\u4e0b\u8f7d\u7684.zip\u6587\u4ef6", None))
self.label_2.setText(QCoreApplication.translate("Form", u"\u65e5\u671f", None))
self.label_3.setText(QCoreApplication.translate("Form", u"(yyyymmdd)", None))
self.label_filepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6\u540e, \u8fd9\u91cc\u5c06\u663e\u793a\u6587\u4ef6\u8def\u5f84", None))
self.label_filepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u540e, \u8fd9\u91cc\u5c06\u663e\u793a\u5176\u8def\u5f84", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u8fd0\u884c", None))
self.checkBox_appendflag.setText(QCoreApplication.translate("Form", u"Append\u6a21\u5f0f", None))
self.label_4.setText(QCoreApplication.translate("Form", u"\u63d0\u4ea4\u6bd4\u4f8b\u4e0b\u9650", None))
self.pushButton_selectdirpath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6\u5939", None))
self.label_5.setText(QCoreApplication.translate("Form", u"\u53ea\u542b.zip\u7684\u6587\u4ef6\u5939", None))
self.label_6.setText(QCoreApplication.translate("Form", u"\u6216", None))
# retranslateUi

View File

@ -10,21 +10,89 @@ class MyWindow(QWidget,Ui_Form):
self.bind()
self.zipfilepath = ""
self.lineEdit_threshold.setText("0.75")
self.singlefile = True
def bind(self):
self.pushButton_selectfilepath.clicked.connect(self.getFilePath)
self.pushButton_selectdirpath.clicked.connect(self.getDirPath)
self.pushButton_exec.clicked.connect(self.exec)
def getFilePath(self):
pathlist = QFileDialog.getOpenFileName(self,"选择文件",".","zip文件(*.zip);;所有文件(*)")
self.label_filepath.setText(pathlist[0])
self.zipfilepath = pathlist[0]
self.singlefile = True
date_list = re.findall(r"\((\d{8})\).zip",self.zipfilepath)
if len(date_list)>0:
date = date_list[0]
self.lineEdit_date.setText(date)
def getDirPath(self):
dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹")
self.label_filepath.setText(dirpath)
self.singlefile = False
self.lineEdit_date.setText("自适应")
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:

View File

@ -85,7 +85,7 @@
</rect>
</property>
<property name="text">
<string>选择文件后, 这里将显示文件路径</string>
<string>选择文件或文件夹后, 这里将显示其路径</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
@ -137,6 +137,50 @@
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_selectdirpath">
<property name="geometry">
<rect>
<x>390</x>
<y>40</y>
<width>75</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>选择文件夹</string>
</property>
</widget>
<widget class="QLabel" name="label_5">
<property name="geometry">
<rect>
<x>290</x>
<y>40</y>
<width>101</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>只含.zip的文件夹</string>
</property>
</widget>
<widget class="QLabel" name="label_6">
<property name="geometry">
<rect>
<x>230</x>
<y>40</y>
<width>31</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>或</string>
</property>
</widget>
</widget>
<resources/>
<connections/>