答题纸对应 适配 讲义上传至mariadb的情形

This commit is contained in:
wangweiye7840 2024-06-17 10:37:33 +08:00
parent f9fa43bb77
commit 62b7c75d4d
1 changed files with 28 additions and 12 deletions

View File

@ -35,17 +35,20 @@ class MyWindow_dtlr(QWidget,Ui_Form):
# print(self.database_name) # print(self.database_name)
def setindex(self): def setindex(self):
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
mycursor = mydb.cursor()
self.comboBox_index.clear() self.comboBox_index.clear()
self.structure = self.lineEdit_structure.text().upper() self.structure = self.lineEdit_structure.text().upper()
self.grade = self.comboBox_grade.currentText() self.grade = self.comboBox_grade.currentText()
self.semester = self.comboBox_semester.currentText() self.semester = self.comboBox_semester.currentText()
self.initialstring = f"{self.structure}{self.grade}{self.semester}" self.initialstring = f"{self.structure}{self.grade}{self.semester}"
self.indices = getindices(self.initialstring) self.indices = getindices(self.initialstring,mycursor)
self.comboBox_index.addItems(self.indices) self.comboBox_index.addItems(self.indices)
if self.indices == []: if self.indices == []:
self.pushButton_exec.setDisabled(True) self.pushButton_exec.setDisabled(True)
else: else:
self.pushButton_exec.setEnabled(True) self.pushButton_exec.setEnabled(True)
mydb.close()
def activateexec(self): def activateexec(self):
self.pushButton_exec.setEnabled(True) self.pushButton_exec.setEnabled(True)
def unvisible(self): def unvisible(self):
@ -61,20 +64,22 @@ class MyWindow_dtlr(QWidget,Ui_Form):
answersheet_dict = load_answersheets_dict_from_mariadb(mycursor) answersheet_dict = load_answersheets_dict_from_mariadb(mycursor)
notes_dict = load_notes_dict_from_mariadb(mycursor) notes_dict = load_notes_dict_from_mariadb(mycursor)
structure_dict = load_structures_dict_from_mariadb(mycursor)
new_dict = {} new_dict = {}
if not nid in notes_dict["notes"]: if not nid in notes_dict:
print("讲义编号有误.") print("讲义编号有误.")
else: else:
self.label_next.setVisible(True) self.label_next.setVisible(True)
self.repaint() self.repaint()
new_dict["nid"] = nid new_dict["nid"] = nid
corresponding_method = input("用何种方式对应? 题号(I)/章节标题(P):") corresponding_method = input("用何种方式对应? 题号(I)/章节标题(P):")
if corresponding_method[0].upper() == "I": if corresponding_method.strip() != "" and corresponding_method[0].upper() == "I":
new_dict["idlist"] = [] new_dict["idlist"] = []
count = 1 count = 1
id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):")
id = RefinePunctuations(id)
while len(re.findall(r"[Ss\d,:]",id)) == len(id): while len(re.findall(r"[Ss\d,:]",id)) == len(id):
if "S" in id.upper(): if "S" in id.upper():
new_dict["idlist"].append("999999") new_dict["idlist"].append("999999")
@ -84,10 +89,11 @@ class MyWindow_dtlr(QWidget,Ui_Form):
new_dict["idlist"] += [i.zfill(6) for i in new_id_list] new_dict["idlist"] += [i.zfill(6) for i in new_id_list]
count += len(new_id_list) count += len(new_id_list)
id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):")
id = RefinePunctuations(id)
elif corresponding_method[0].upper() == "P": elif corresponding_method.strip() != "" and corresponding_method[0].upper() == "P":
structure = notes_dict["structures"][nid[0]]["structure"] structure = structure_dict[nid[0:5]]["structure"]
count = 1 count = 1
partslist = [] partslist = []
for key in structure: for key in structure:
@ -95,30 +101,40 @@ class MyWindow_dtlr(QWidget,Ui_Form):
count += 1 count += 1
partslist.append(key) partslist.append(key)
parts_selected_string = input("使用哪些部分(输入数字编号, 用';'分隔):") parts_selected_string = input("使用哪些部分(输入数字编号, 用';'分隔):")
parts_selected_string = RefinePunctuations(parts_selected_string).replace(",",";").replace(" ","")
parts_selected_index = parts_selected_string.strip().split(";") parts_selected_index = parts_selected_string.strip().split(";")
parts_selected = [] parts_selected = []
for i in parts_selected_index: for i in parts_selected_index:
parts_selected.append(partslist[int(i)-1]) parts_selected.append(partslist[int(i)-1])
new_dict["parts"] = parts_selected.copy() new_dict["parts"] = parts_selected.copy()
if marks_list == []: if marks_list == []:
marksflag = input("是否为每个结果赋分(Y/N):") marksflag = input("是否为每个结果赋分(Y/[N]):")
if marksflag[0].upper() == "Y": if marksflag.strip() != "" and marksflag[0].upper() == "Y":
new_dict["marks"] = [] new_dict["marks"] = []
count = 1 count = 1
mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):").strip()
while len(re.findall(r"\d",mark)) == len(mark): while len(re.findall(r"\d",mark)) == len(mark):
new_dict["marks"].append(int(mark)) new_dict["marks"].append(int(mark))
count += 1 count += 1
mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):").strip()
else: else:
new_dict["marks"] = marks_list.copy() new_dict["marks"] = marks_list.copy()
sql = "INSERT INTO answersheets (pid,nid,parts,idlist,marks) VALUES (%s,%s,%s,%s,%s);"
parts = None if not "parts" in new_dict else json.dumps(new_dict["parts"],ensure_ascii=False)
idlist = None if not "idlist" in new_dict else json.dumps(new_dict["idlist"],ensure_ascii=False)
marks = None if not "marks" in new_dict else json.dumps(new_dict["marks"],ensure_ascii=False)
val = (self.lineEdit_xiaoxianid.text(),nid,parts,idlist,marks)
mycursor.execute(sql,val)
sql = "INSERT INTO logs (DATE,TIME,username,action,db_content) VALUE (%s,%s,%s,%s,%s);"
val = (GetDate(),GetTime(),get_git_username(),"答题纸挂钩",self.lineEdit_xiaoxianid.text())
mydb.commit()
answersheet_dict[self.lineEdit_xiaoxianid.text()] = new_dict.copy() # answersheet_dict[self.lineEdit_xiaoxianid.text()] = new_dict.copy()
save_dict(answersheet_dict,answersheetjson) # save_dict(answersheet_dict,answersheetjson)
self.label_next.setVisible(False) self.label_next.setVisible(False)
print("设置完成") print("设置完成")
mydb.close()