104 lines
4.2 KiB
Python
104 lines
4.2 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_排序材料内难度 import Ui_Form
|
|
from database_tools_2 import *
|
|
|
|
class MyWindow_pxnd(QWidget,Ui_Form):
|
|
def __init__(self,database_name):
|
|
super().__init__()
|
|
self.database_name = database_name
|
|
self.setupUi(self)
|
|
self.bind()
|
|
|
|
def setdbname(self,string):
|
|
self.database_name = string
|
|
# print(self.database_name)
|
|
|
|
def bind(self):
|
|
self.pushButton_selectfilepath.clicked.connect(self.choosefile)
|
|
self.pushButton_exec.clicked.connect(self.exec)
|
|
self.lineEdit_filepath.setText(r"C:\Users\weiye\Documents\wwy sync\26届\高一第二学期\学案\G20260216余弦定理(2).tex") # to remove
|
|
self.lineEdit_classregex.setText(r"2026届高一1\d班") # to remove
|
|
|
|
|
|
def choosefile(self):
|
|
self.texfile = QFileDialog.getOpenFileName(self,"选择.tex文件",os.getcwd(),".tex文件(*.tex);;所有文件(*)")[0]
|
|
self.lineEdit_filepath.setText(self.texfile)
|
|
|
|
|
|
|
|
|
|
def exec(self):
|
|
# self.latex_data = ReadTextFile(self.lineEdit_filepath.text())
|
|
self.raw_idlist = ExportIDList(self.lineEdit_filepath.text())
|
|
self.raw_parts_and_idlist = ExtractIDList(self.lineEdit_filepath.text())
|
|
self.raw_idparts = {}
|
|
part_ind = 0
|
|
for index,id in self.raw_parts_and_idlist:
|
|
if index == 1:
|
|
part_ind += 1
|
|
self.raw_idparts[f"第{part_ind}部分"] = {}
|
|
self.raw_idparts[f"第{part_ind}部分"][index] = id
|
|
print(self.raw_idparts)
|
|
outputleft = f"原来材料各板块的题号:\n{self.raw_idlist}"
|
|
outputleft += "\n\n---------------\n\n按类型及难度中位数排序后的题号:\n"
|
|
|
|
mydb = connect(hostname = db_host, port = db_port, username = db_user, pwd = db_pwd, db = self.database_name)
|
|
mycursor = mydb.cursor()
|
|
pro_dict,obj_dict,bn_dict,unit_obj_dict = generateDictsfromMariaDB(mycursor)
|
|
mydb.close()
|
|
classregex = self.lineEdit_classregex.text()
|
|
for id in tqdm.tqdm(pro_dict, desc = "筛选有效使用记录中:"):
|
|
pro_dict[id]["usages"] = [u for u in pro_dict[id]["usages"] if re.findall(classregex,u) != []]
|
|
diff_dict = generate_diff_dict(pro_dict)
|
|
outputright = "各题难度中位数(-1表示无记录):\n"
|
|
for part in self.raw_idparts:
|
|
new_idlist = []
|
|
outputright += f" {part}:\n"
|
|
tk_dict = {}
|
|
xz_dict = {}
|
|
jd_dict = {}
|
|
for ind in self.raw_idparts[part]:
|
|
id = self.raw_idparts[part][ind]
|
|
outputright += f" {ind} {id} ({pro_dict[id]['genre']}): {diff_dict[id]['median']:.3f}\n"
|
|
if pro_dict[id]["genre"] == "填空题":
|
|
tk_dict[id] = (ind,diff_dict[id]['median'])
|
|
elif pro_dict[id]["genre"] == "选择题":
|
|
xz_dict[id] = (ind,diff_dict[id]['median'])
|
|
elif pro_dict[id]["genre"] == "解答题":
|
|
jd_dict[id] = (ind,diff_dict[id]['median'])
|
|
# print(tk_list,xz_list,jd_list)
|
|
sorted_tk_dict = dict(sorted(tk_dict.items(), key=lambda x:x[1][1], reverse= True))
|
|
# print(sorted_tk_dict)
|
|
sorted_xz_dict = dict(sorted(xz_dict.items(), key=lambda x:x[1][1], reverse= True))
|
|
sorted_jd_dict = dict(sorted(jd_dict.items(), key=lambda x:x[1][1], reverse= True))
|
|
outputright += "***************\n"
|
|
for currentdict in (sorted_tk_dict,sorted_xz_dict,sorted_jd_dict):
|
|
for id in currentdict:
|
|
new_idlist.append(id)
|
|
ind = currentdict[id][0]
|
|
diff = currentdict[id][1]
|
|
outputright += f" {ind} {id} ({pro_dict[id]['genre']}): {diff:.3f}\n"
|
|
outputright += "\n--------------------\n\n"
|
|
outputleft += f"{','.join(new_idlist)}\n\n"
|
|
self.textBrowser_idexp.setText(outputleft)
|
|
self.textBrowser_result.setText(outputright)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow_pxnd("tikutest")
|
|
windows.show()
|
|
app.exec()
|
|
|