97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_统考数据导入 import Ui_Form
|
|
import os
|
|
from database_tools_2 import *
|
|
|
|
|
|
class MyWindow_tkdr(QWidget,Ui_Form):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.bind()
|
|
|
|
def bind(self):
|
|
self.pushButton_paper.clicked.connect(self.selectpaper)
|
|
self.pushButton_excel.clicked.connect(self.selectexcel)
|
|
self.pushButton_exec.clicked.connect(self.exec)
|
|
|
|
def selectpaper(self):
|
|
self.texfile = QFileDialog.getOpenFileName(self,"选择试卷文件",os.getcwd(),"试卷文件(*.tex *.pdf);;所有文件(*)")[0]
|
|
self.lineEdit_paperfile.setText(self.texfile)
|
|
def selectexcel(self):
|
|
self.excelfile = QFileDialog.getOpenFileName(self,"选择统计文件",os.getcwd(),"Excel文件(*.xlsx);;所有文件(*)")[0]
|
|
self.lineEdit_excelfile.setText(self.excelfile)
|
|
def exec(self):
|
|
sheetname = "难度统计" # excel中难度数据所在的工作表名
|
|
date = self.lineEdit_date.text().strip() # 考试日期
|
|
grade = self.lineEdit_grade.text().strip() # 考试年级
|
|
max_classnum = int(self.lineEdit_classnum.text().strip()) # 年级参加考试的最大班级班号
|
|
outputfilepath = r"./临时文件/metadata.txt" # 输出的用于导入的metadata.txt文件位置
|
|
checkingfilepath = r"临时文件/手动统计结果.txt" # 用于检查结构的文件所在位置
|
|
|
|
|
|
|
|
df = pd.read_excel(self.excelfile,sheet_name = sheetname)
|
|
problems_list = generate_number_set(extractIDs(self.texfile))
|
|
|
|
#生成题号(1~n)与题库id对应
|
|
id_dict = {}
|
|
for i in range(len(problems_list)):
|
|
id_dict[i+1] = problems_list[i]
|
|
|
|
output = "usages\n\n"
|
|
checkoutput = ""
|
|
#生成题号(1~n)与表格中数据列的对应
|
|
idcol_dict = {}
|
|
for i in id_dict:
|
|
idcol_dict[i] = []
|
|
mincol = -1
|
|
for col_index in range(mincol+1,len(df.columns)):
|
|
col = df.columns[col_index]
|
|
if str(col).startswith(str(i)):
|
|
idcol_dict[i].append(col_index)
|
|
mincol = col_index
|
|
if str(i) == str(col):
|
|
break
|
|
|
|
#生成行号与班级的对应列表
|
|
classrows_dict = {}
|
|
for row in df.iloc[:,0]:
|
|
if type(row) == int or type(row) == float:
|
|
if 1<=row<=max_classnum:
|
|
row = int(row)
|
|
classrows_dict[list(df.iloc[:,0]).index(row)] = str(row).zfill(2) + "班"
|
|
|
|
#生成手动统计列表
|
|
for cl in classrows_dict:
|
|
classname = grade + classrows_dict[cl]
|
|
checkoutput += "[BEGIN]\n"
|
|
checkoutput += "## "+date+"\n"
|
|
checkoutput += "** "+classname+"\n"
|
|
for i in range(len(problems_list)):
|
|
id = id_dict[i+1]
|
|
results_cols = idcol_dict[i+1]
|
|
results = []
|
|
for col in results_cols:
|
|
results.append("%.3f"%df.iloc[cl,col])
|
|
checkoutput += id+"\t"+"\t".join(results) + "\n"
|
|
output += id + "\n" + "\t".join([date,classname]+results) + "\n\n"
|
|
checkoutput += "[END]\n\n\n"
|
|
|
|
SaveTextFile(output,outputfilepath)
|
|
print("可以在 %s 文件中检查结构"%(SaveTextFile(checkoutput,checkingfilepath)))
|
|
os.system("code %s"%checkingfilepath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow_tkdr()
|
|
windows.show()
|
|
app.exec()
|
|
|