获取小闲平台使用数据 功能适配答题纸信息放在mariadb的情形
This commit is contained in:
parent
732e3a3fe6
commit
736356a46c
|
|
@ -29,6 +29,11 @@ db_pwd = "Kjmathds_2024"
|
||||||
db_port = "13306"
|
db_port = "13306"
|
||||||
db_host = "wwylss.synology.me"
|
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():
|
def get_git_username():
|
||||||
command = "git config --global user.name"
|
command = "git config --global user.name"
|
||||||
|
|
@ -2653,36 +2658,62 @@ def FindFile(dir,filename): #在指定目录及子目录下寻找特定文件名
|
||||||
pathlist.append(path)
|
pathlist.append(path)
|
||||||
return pathlist
|
return pathlist
|
||||||
|
|
||||||
def FindPaper(xiaoxianpid, answersheetpath): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False
|
def FindPaper(xiaoxianpid, mycursor): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回False
|
||||||
answersheetpathlist = FindFile(answersheetpath,"答题纸对应.json")
|
|
||||||
foundpid = False
|
foundpid = False
|
||||||
for dir in answersheetpathlist:
|
sql = "SELECT nid,parts,idlist,marks,exclude FROM answersheets WHERE not obsolete AND pid = %s;"
|
||||||
filepath = os.path.join(dir,"答题纸对应.json")
|
val = (xiaoxianpid,)
|
||||||
anssheetjson = load_dict(filepath)
|
mycursor.execute(sql,val)
|
||||||
if xiaoxianpid in anssheetjson:
|
ret = mycursor.fetchall()
|
||||||
foundpid = True
|
if len(ret) == 1:
|
||||||
grade = "20"+re.findall(r"\d{2}届",dir)[0]
|
foundpid = True
|
||||||
nid = anssheetjson[xiaoxianpid]["nid"]
|
nid,parts,idlist,marksraw,excluderaw = ret[0]
|
||||||
notesjson = load_dict(os.path.join(dir,"校本材料.json"))
|
if not parts is None:
|
||||||
if not "idlist" in anssheetjson[xiaoxianpid]:
|
idlist = []
|
||||||
idlist = []
|
sql = "SELECT structure FROM notes WHERE nid = %s AND not obsolete;"
|
||||||
for part in anssheetjson[xiaoxianpid]["parts"]:
|
val = (nid,)
|
||||||
idlist += notesjson["notes"][nid][part].copy()
|
mycursor.execute(sql,val)
|
||||||
else:
|
structure = mycursor.fetchall()[0][0]
|
||||||
idlist = anssheetjson[xiaoxianpid]["idlist"]
|
for key in json.loads(parts):
|
||||||
if "marks" in anssheetjson[xiaoxianpid]:
|
idlist += json.loads(structure)[key].copy()
|
||||||
marks = anssheetjson[xiaoxianpid]["marks"]
|
else:
|
||||||
else:
|
idlist = json.loads(idlist)
|
||||||
marks = []
|
marks = [] if marksraw is None else json.loads(marksraw)
|
||||||
if "exclude" in anssheetjson[xiaoxianpid]:
|
exclude = {} if excluderaw is None else json.loads(excluderaw)
|
||||||
excludejson = anssheetjson[xiaoxianpid]["exclude"]
|
grade = nid[1:5]+"届"
|
||||||
else:
|
# grade = getgrade(currentsemester,gradeindex)
|
||||||
excludejson = {}
|
|
||||||
break
|
|
||||||
if foundpid:
|
if foundpid:
|
||||||
return(nid,grade,idlist,marks,excludejson)
|
return(nid,grade,idlist,marks,exclude)
|
||||||
else:
|
else:
|
||||||
return False
|
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, 找到文件且是日常试卷返回"日常卷", 找到文件且不是日常试卷返回"考试卷"
|
def CheckPaperType(filepath,filename): #根据filepath(通常是小闲的zip解压出的目录)和filename(通常是"小题分_按学号(数学).xlsx")检测试卷类型, 未找到该文件则返回False, 找到文件且是日常试卷返回"日常卷", 找到文件且不是日常试卷返回"考试卷"
|
||||||
statsfilepathlist = FindFile(filepath,filename)
|
statsfilepathlist = FindFile(filepath,filename)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.layout_bjtm.addWidget(self.bjtm) #以上三行为初始化“编辑题目”tab
|
self.layout_bjtm.addWidget(self.bjtm) #以上三行为初始化“编辑题目”tab
|
||||||
|
|
||||||
self.layout_xxdr = QVBoxLayout(self.tab_xxdr)
|
self.layout_xxdr = QVBoxLayout(self.tab_xxdr)
|
||||||
self.xxdr = MyWindow_xxdr()
|
self.xxdr = MyWindow_xxdr(self.database)
|
||||||
self.layout_xxdr.addWidget(self.xxdr) #以上三行为初始化“小闲统计数据导入”tab
|
self.layout_xxdr.addWidget(self.xxdr) #以上三行为初始化“小闲统计数据导入”tab
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -195,7 +195,8 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.xzgx.setdbname,
|
self.xzgx.setdbname,
|
||||||
self.sjlb.setdbname,
|
self.sjlb.setdbname,
|
||||||
self.fnsc.setdbname,
|
self.fnsc.setdbname,
|
||||||
self.pxnd.setdbname
|
self.pxnd.setdbname,
|
||||||
|
self.xxdr.setdbname
|
||||||
]: #在列表中的tab里传送数据库名的连接
|
]: #在列表中的tab里传送数据库名的连接
|
||||||
self.sendDBname.connect(func)
|
self.sendDBname.connect(func)
|
||||||
def sendValue(self):
|
def sendValue(self):
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,15 @@ class MyWindow_xxdr(QWidget,Ui_Form):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self,database_name):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.database_name = database_name
|
||||||
self.bind()
|
self.bind()
|
||||||
def bind(self):
|
def bind(self):
|
||||||
self.tempdir = "临时文件/zips"
|
self.tempdir = "临时文件/zips"
|
||||||
self.statsfilename = "小题分_按学号(数学).xlsx"
|
self.statsfilename = "小题分_按学号(数学).xlsx"
|
||||||
self.answersheetseekingpath = "../备课组"
|
# self.answersheetseekingpath = "../备课组"
|
||||||
self.lineEdit_threshold.setText("0.75")
|
self.lineEdit_threshold.setText("0.75")
|
||||||
self.tableWidget.setColumnWidth(0,200)
|
self.tableWidget.setColumnWidth(0,200)
|
||||||
self.tableWidget.setColumnWidth(1,280)
|
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中
|
def getDirPath(self): #选取文件夹中的所有符合答题纸特征的.zip文件并放置在tableWidget中
|
||||||
dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹")
|
dirpath = QFileDialog.getExistingDirectory(self,"选择文件夹")
|
||||||
|
|
@ -128,9 +131,11 @@ class MyWindow_xxdr(QWidget,Ui_Form):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
makedir(self.tempdir)
|
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:
|
try:
|
||||||
xiaoxianpid = ParseZipname(zipfilepath)
|
xiaoxianpid = ParseZipname(zipfilepath)
|
||||||
paperinfo = FindPaper(xiaoxianpid, self.answersheetseekingpath)
|
paperinfo = FindPaper(xiaoxianpid, mycursor)
|
||||||
gradename = paperinfo[1]
|
gradename = paperinfo[1]
|
||||||
idlist = paperinfo[2]
|
idlist = paperinfo[2]
|
||||||
excludejson = paperinfo[4]
|
excludejson = paperinfo[4]
|
||||||
|
|
@ -144,8 +149,10 @@ class MyWindow_xxdr(QWidget,Ui_Form):
|
||||||
dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],self.statsfilename))
|
dfcurrent = pd.read_excel(os.path.join(statsfilepathlist[0],self.statsfilename))
|
||||||
correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols])
|
correspondence_dict = generateIDtoUsageCorrespondence(idlist,validcols,dfcurrent.iloc[1,validcols])
|
||||||
output = CalculateUsages(statsfilepathlist,self.statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date,exclude=RefineExclude(excludejson))
|
output = CalculateUsages(statsfilepathlist,self.statsfilename,gradename,threshold,marks,correspondence_dict,validcols,date,exclude=RefineExclude(excludejson))
|
||||||
|
mydb.close()
|
||||||
return output #返回由usages开始的使用记录文本
|
return output #返回由usages开始的使用记录文本
|
||||||
except:
|
except:
|
||||||
|
mydb.close()
|
||||||
return 1 #无法生成就返回1
|
return 1 #无法生成就返回1
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -157,7 +164,7 @@ class MyWindow_xxdr(QWidget,Ui_Form):
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
windows = MyWindow_xxdr()
|
windows = MyWindow_xxdr("tikutest")
|
||||||
windows.show()
|
windows.show()
|
||||||
app.exec()
|
app.exec()
|
||||||
|
|
||||||
|
|
|
||||||
Reference in New Issue