获取小闲平台使用数据的脚本已用Qt改写
This commit is contained in:
parent
acc663be1a
commit
c642c6f3c2
|
|
@ -0,0 +1,73 @@
|
||||||
|
# -*- 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, QLabel, QLineEdit,
|
||||||
|
QPushButton, QSizePolicy, QWidget)
|
||||||
|
|
||||||
|
class Ui_Form(object):
|
||||||
|
def setupUi(self, Form):
|
||||||
|
if not Form.objectName():
|
||||||
|
Form.setObjectName(u"Form")
|
||||||
|
Form.resize(700, 140)
|
||||||
|
self.pushButton_selectfilepath = QPushButton(Form)
|
||||||
|
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
|
||||||
|
self.pushButton_selectfilepath.setGeometry(QRect(100, 40, 75, 24))
|
||||||
|
self.label = QLabel(Form)
|
||||||
|
self.label.setObjectName(u"label")
|
||||||
|
self.label.setGeometry(QRect(10, 40, 91, 16))
|
||||||
|
self.label_2 = QLabel(Form)
|
||||||
|
self.label_2.setObjectName(u"label_2")
|
||||||
|
self.label_2.setGeometry(QRect(10, 10, 54, 16))
|
||||||
|
self.lineEdit_date = QLineEdit(Form)
|
||||||
|
self.lineEdit_date.setObjectName(u"lineEdit_date")
|
||||||
|
self.lineEdit_date.setGeometry(QRect(80, 10, 132, 20))
|
||||||
|
self.label_3 = QLabel(Form)
|
||||||
|
self.label_3.setObjectName(u"label_3")
|
||||||
|
self.label_3.setGeometry(QRect(230, 10, 81, 16))
|
||||||
|
self.label_filepath = QLabel(Form)
|
||||||
|
self.label_filepath.setObjectName(u"label_filepath")
|
||||||
|
self.label_filepath.setGeometry(QRect(10, 70, 681, 16))
|
||||||
|
self.pushButton_exec = QPushButton(Form)
|
||||||
|
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||||
|
self.pushButton_exec.setGeometry(QRect(620, 100, 75, 24))
|
||||||
|
self.checkBox_appendflag = QCheckBox(Form)
|
||||||
|
self.checkBox_appendflag.setObjectName(u"checkBox_appendflag")
|
||||||
|
self.checkBox_appendflag.setGeometry(QRect(520, 100, 91, 20))
|
||||||
|
self.label_4 = QLabel(Form)
|
||||||
|
self.label_4.setObjectName(u"label_4")
|
||||||
|
self.label_4.setGeometry(QRect(330, 10, 81, 16))
|
||||||
|
self.lineEdit_threshold = QLineEdit(Form)
|
||||||
|
self.lineEdit_threshold.setObjectName(u"lineEdit_threshold")
|
||||||
|
self.lineEdit_threshold.setGeometry(QRect(420, 10, 113, 20))
|
||||||
|
|
||||||
|
self.retranslateUi(Form)
|
||||||
|
|
||||||
|
QMetaObject.connectSlotsByName(Form)
|
||||||
|
# setupUi
|
||||||
|
|
||||||
|
def retranslateUi(self, Form):
|
||||||
|
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u83b7\u53d6\u5c0f\u95f2\u5e73\u53f0\u4f7f\u7528\u6570\u636e", None))
|
||||||
|
self.pushButton_selectfilepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6", None))
|
||||||
|
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.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))
|
||||||
|
# retranslateUi
|
||||||
|
|
||||||
|
|
@ -0,0 +1,89 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||||
|
from Ui_获取小闲平台使用数据 import Ui_Form
|
||||||
|
from database_tools import *
|
||||||
|
import shutil,zipfile
|
||||||
|
|
||||||
|
class MyWindow(QWidget,Ui_Form):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
self.zipfilepath = ""
|
||||||
|
|
||||||
|
def bind(self):
|
||||||
|
self.pushButton_selectfilepath.clicked.connect(self.getFilePath)
|
||||||
|
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]
|
||||||
|
|
||||||
|
def exec(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("数据有误, 可能需要检查每一题的满分数据")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# def ShowFilePath(self): # 选择文件
|
||||||
|
# pathlist = QFileDialog.getOpenFileName(self, "选择文件这是标题", ".", "All Files (*);;py文件(*.py *.pyd))")
|
||||||
|
# self.label_FilePath.setText(pathlist[0])
|
||||||
|
# def getDir(self): # 选择文件夹
|
||||||
|
# dir = QFileDialog.getExistingDirectory(None, "选择文件夹")
|
||||||
|
# self.label_FilePath.setText(dir)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
@ -0,0 +1,143 @@
|
||||||
|
<?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>700</width>
|
||||||
|
<height>140</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>获取小闲平台使用数据</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton_selectfilepath">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>100</x>
|
||||||
|
<y>40</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>选择文件</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>40</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>下载的.zip文件</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>54</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>日期</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_date">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>80</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>132</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>230</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>(yyyymmdd)</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_filepath">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>10</x>
|
||||||
|
<y>70</y>
|
||||||
|
<width>681</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>选择文件后, 这里将显示文件路径</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QPushButton" name="pushButton_exec">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>620</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>75</width>
|
||||||
|
<height>24</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>运行</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QCheckBox" name="checkBox_appendflag">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>520</x>
|
||||||
|
<y>100</y>
|
||||||
|
<width>91</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Append模式</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>330</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>81</width>
|
||||||
|
<height>16</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>提交比例下限</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QLineEdit" name="lineEdit_threshold">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>420</x>
|
||||||
|
<y>10</y>
|
||||||
|
<width>113</width>
|
||||||
|
<height>20</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Reference in New Issue