From 736356a46cb04557c4ddb50b34b5f14a9877bb10 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 16 Jun 2024 22:19:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=B0=8F=E9=97=B2=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E4=BD=BF=E7=94=A8=E6=95=B0=E6=8D=AE=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E9=80=82=E9=85=8D=E7=AD=94=E9=A2=98=E7=BA=B8=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=94=BE=E5=9C=A8mariadb=E7=9A=84=E6=83=85=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/database_tools_2.py | 83 +++++++++++++++++++++++----------- 工具v4/tool_panel.py | 5 +- 工具v4/获取小闲平台使用数据.py | 17 +++++-- 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index cf285914..9e22c699 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -29,6 +29,11 @@ db_pwd = "Kjmathds_2024" db_port = "13306" db_host = "wwylss.synology.me" +currentsemester = "2023" + +def getgrade(currentsemester,gradeindex): + gradelist = {1: "高三", 2:"高二", 3:"高一"} + return gradelist[int(gradeindex)-int(currentsemester)] def get_git_username(): command = "git config --global user.name" @@ -2653,36 +2658,62 @@ def FindFile(dir,filename): #在指定目录及子目录下寻找特定文件名 pathlist.append(path) return pathlist -def FindPaper(xiaoxianpid, answersheetpath): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False - answersheetpathlist = FindFile(answersheetpath,"答题纸对应.json") +def FindPaper(xiaoxianpid, mycursor): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False foundpid = False - for dir in answersheetpathlist: - filepath = os.path.join(dir,"答题纸对应.json") - anssheetjson = load_dict(filepath) - if xiaoxianpid in anssheetjson: - foundpid = True - grade = "20"+re.findall(r"\d{2}届",dir)[0] - nid = anssheetjson[xiaoxianpid]["nid"] - notesjson = load_dict(os.path.join(dir,"校本材料.json")) - if not "idlist" in anssheetjson[xiaoxianpid]: - idlist = [] - for part in anssheetjson[xiaoxianpid]["parts"]: - idlist += notesjson["notes"][nid][part].copy() - else: - idlist = anssheetjson[xiaoxianpid]["idlist"] - if "marks" in anssheetjson[xiaoxianpid]: - marks = anssheetjson[xiaoxianpid]["marks"] - else: - marks = [] - if "exclude" in anssheetjson[xiaoxianpid]: - excludejson = anssheetjson[xiaoxianpid]["exclude"] - else: - excludejson = {} - break + sql = "SELECT nid,parts,idlist,marks,exclude FROM answersheets WHERE not obsolete AND pid = %s;" + val = (xiaoxianpid,) + mycursor.execute(sql,val) + ret = mycursor.fetchall() + if len(ret) == 1: + foundpid = True + nid,parts,idlist,marksraw,excluderaw = ret[0] + if not parts is None: + idlist = [] + sql = "SELECT structure FROM notes WHERE nid = %s AND not obsolete;" + val = (nid,) + mycursor.execute(sql,val) + structure = mycursor.fetchall()[0][0] + for key in json.loads(parts): + idlist += json.loads(structure)[key].copy() + else: + idlist = json.loads(idlist) + marks = [] if marksraw is None else json.loads(marksraw) + exclude = {} if excluderaw is None else json.loads(excluderaw) + grade = nid[1:5]+"届" + # grade = getgrade(currentsemester,gradeindex) if foundpid: - return(nid,grade,idlist,marks,excludejson) + return(nid,grade,idlist,marks,exclude) else: return False + # answersheetpathlist = FindFile(answersheetpath,"答题纸对应.json") + # foundpid = False + # for dir in answersheetpathlist: + # filepath = os.path.join(dir,"答题纸对应.json") + # anssheetjson = load_dict(filepath) + # if xiaoxianpid in anssheetjson: + # foundpid = True + # grade = "20"+re.findall(r"\d{2}届",dir)[0] + # nid = anssheetjson[xiaoxianpid]["nid"] + # notesjson = load_dict(os.path.join(dir,"校本材料.json")) + # if not "idlist" in anssheetjson[xiaoxianpid]: + # idlist = [] + # for part in anssheetjson[xiaoxianpid]["parts"]: + # idlist += notesjson["notes"][nid][part].copy() + # else: + # idlist = anssheetjson[xiaoxianpid]["idlist"] + # if "marks" in anssheetjson[xiaoxianpid]: + # marks = anssheetjson[xiaoxianpid]["marks"] + # else: + # marks = [] + # if "exclude" in anssheetjson[xiaoxianpid]: + # excludejson = anssheetjson[xiaoxianpid]["exclude"] + # else: + # excludejson = {} + # break + # if foundpid: + # return(nid,grade,idlist,marks,excludejson) + # else: + # return False def CheckPaperType(filepath,filename): #根据filepath(通常是小闲的zip解压出的目录)和filename(通常是"小题分_按学号(数学).xlsx")检测试卷类型, 未找到该文件则返回False, 找到文件且是日常试卷返回"日常卷", 找到文件且不是日常试卷返回"考试卷" statsfilepathlist = FindFile(filepath,filename) diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 0ed94460..105681af 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -68,7 +68,7 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.layout_bjtm.addWidget(self.bjtm) #以上三行为初始化“编辑题目”tab self.layout_xxdr = QVBoxLayout(self.tab_xxdr) - self.xxdr = MyWindow_xxdr() + self.xxdr = MyWindow_xxdr(self.database) self.layout_xxdr.addWidget(self.xxdr) #以上三行为初始化“小闲统计数据导入”tab @@ -195,7 +195,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.xzgx.setdbname, self.sjlb.setdbname, self.fnsc.setdbname, - self.pxnd.setdbname + self.pxnd.setdbname, + self.xxdr.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/获取小闲平台使用数据.py b/工具v4/获取小闲平台使用数据.py index da37e028..79fb9a6c 100644 --- a/工具v4/获取小闲平台使用数据.py +++ b/工具v4/获取小闲平台使用数据.py @@ -20,14 +20,15 @@ class MyWindow_xxdr(QWidget,Ui_Form): - def __init__(self): + def __init__(self,database_name): super().__init__() self.setupUi(self) + self.database_name = database_name self.bind() def bind(self): self.tempdir = "临时文件/zips" self.statsfilename = "小题分_按学号(数学).xlsx" - self.answersheetseekingpath = "../备课组" + # self.answersheetseekingpath = "../备课组" self.lineEdit_threshold.setText("0.75") self.tableWidget.setColumnWidth(0,200) self.tableWidget.setColumnWidth(1,280) @@ -51,7 +52,9 @@ class MyWindow_xxdr(QWidget,Ui_Form): - + def setdbname(self,string): + self.database_name = string + print(self.database_name) def getDirPath(self): #选取文件夹中的所有符合答题纸特征的.zip文件并放置在tableWidget中 dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹") @@ -128,9 +131,11 @@ class MyWindow_xxdr(QWidget,Ui_Form): except: pass makedir(self.tempdir) + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() try: xiaoxianpid = ParseZipname(zipfilepath) - paperinfo = FindPaper(xiaoxianpid, self.answersheetseekingpath) + paperinfo = FindPaper(xiaoxianpid, mycursor) gradename = paperinfo[1] idlist = paperinfo[2] excludejson = paperinfo[4] @@ -144,8 +149,10 @@ class MyWindow_xxdr(QWidget,Ui_Form): dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],self.statsfilename)) correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols]) output = CalculateUsages(statsfilepathlist,self.statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date,exclude=RefineExclude(excludejson)) + mydb.close() return output #返回由usages开始的使用记录文本 except: + mydb.close() return 1 #无法生成就返回1 @@ -157,7 +164,7 @@ class MyWindow_xxdr(QWidget,Ui_Form): if __name__ == '__main__': app = QApplication([]) - windows = MyWindow_xxdr() + windows = MyWindow_xxdr("tikutest") windows.show() app.exec()