From 3cd434c5e666fe2ecf7a3a5af666aea31dfcc50d Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sat, 27 Jan 2024 13:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E7=BC=96=E5=86=99=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E7=9A=84=E6=94=B6=E9=9B=86=E4=BD=BF=E7=94=A8=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=9A=84=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/收集使用记录.py | 139 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 工具v2/收集使用记录.py diff --git a/工具v2/收集使用记录.py b/工具v2/收集使用记录.py new file mode 100644 index 00000000..4a61fd69 --- /dev/null +++ b/工具v2/收集使用记录.py @@ -0,0 +1,139 @@ +"""工程中""" + +from database_tools import * +import zipfile,shutil + + +zipfilepath = r"D:\temp\222817032234165544977_G20260160选择性必修第四章数列复习_高一_数学.zip" +# zipfilepath = r"D:\temp\222817041862672707412_控江中学2023学年第一学期高一数学期末考试_高一_数学.zip" +tempdir = "临时文件/zips" +statsfilename = "小题分_按学号(数学).xlsx" +threshold = 0.96 #设置最低提交人数 +answersheetseekingpath = "../备课组" + +def ParseZipname(zipfilename): #小闲平台的zip文件中获得试卷编号, 返回试卷编号字符串 + xiaoxianpid = re.findall(r"^(\d*?)_",os.path.split(zipfilename)[1]) + return xiaoxianpid[0] + +def FindFile(dir,filename): #在指定目录及子目录下寻找特定文件名的文件, 返回文件所在的路径列表 + pathlist = [] + for path,m,filenames in os.walk(dir): + if filename in filenames: + pathlist.append(path) + return pathlist + +def FindPaper(xiaoxianpid, answersheetpath): #根据小闲的试卷编号和答题纸对应json的根目录寻找题库的试卷编号,届别,题号, 返回(题库试卷编号,届别,题号列表), 如果未找到则返回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] + pid = anssheetjson[xiaoxianpid]["id"] + notesjson = load_dict(os.path.join(dir,"校本材料.json")) + idlist = [] + for part in anssheetjson[xiaoxianpid]["parts"]: + idlist += notesjson["notes"][pid][part].copy() + if "marks" in anssheetjson[xiaoxianpid]: + marks = anssheetjson[xiaoxianpid]["marks"] + else: + marks = [] + break + if foundpid: + return(pid,grade,idlist,marks) + else: + return False + +def CheckPaperType(filepath,filename): #根据filepath(通常是小闲的zip解压出的目录)和filename(通常是"小题分_按学号(数学).xlsx")检测试卷类型, 未找到该文件则返回False, 找到文件且是日常试卷返回"日常卷", 找到文件且不是日常试卷返回"考试卷" + statsfilepathlist = FindFile(filepath,filename) + if statsfilepathlist == []: + return False + else: + dir = statsfilepathlist[0] + dfcurrent = pd.read_excel(os.path.join(dir,filename)) + if re.findall(r"第\d*步",str(dfcurrent.loc[1,:])) == []: + return "日常卷" + else: + return "考试卷" + +def generateColIndexandMarks(filepath,paperinfo): #根据filepath(是一个有statsfilename的文件夹列表)中第一个路径中的数据文件及paperinfo(FindPaper返回的结果)寻找excel文件中有效的列的位置和相应的满分分数 + dir = filepath[0] + dfcurrent = pd.read_excel(os.path.join(dir,statsfilename)) + validcols = [] + if papertype == "日常卷": + for i in range(len(dfcurrent.columns)): + colname = str(dfcurrent.iloc[1,i]) + if ("单选" in colname or "填空" in colname or "主观" in colname) and re.findall("[ABCD]",colname) == []: + validcols.append(i) + marks = [1] * len(validcols) + elif papertype == "考试卷": + for i in range(len(dfcurrent.columns)): + colname = str(dfcurrent.iloc[1,i]) + if ("单选" in colname or "填空" in colname or "主观" in colname or "步" in colname) and re.findall("[ABCD]",colname) == []: + validcols.append(i) + for col in range(len(validcols)-1,-1,-1): + colname = str(dfcurrent.iloc[1,validcols[col]]) + if "主观" in colname: + colname_main = re.findall(r"^([\d\.]*)[\($]",colname[2:])[0] + t = [dfcurrent.iloc[1,c] for c in validcols[col+1:]] + t = str(t) + if colname_main in t: + validcols.pop(col) + if paperinfo[3] == []: + marks = [1] * len(validcols) + else: + marks = paperinfo[3] + if len(marks) == len(validcols): + return (validcols,marks) + else: + return False + + + + + +try: + shutil.rmtree(tempdir) + os.mkdir(tempdir) +except: + pass + +xiaoxianpid = ParseZipname(zipfilepath) +paperinfo = FindPaper(xiaoxianpid, answersheetseekingpath) + + + +zf = zipfile.ZipFile(zipfilepath) +zf.extractall(tempdir) #解压zip文件中的所有内容到tempdir + +papertype = CheckPaperType(tempdir,statsfilename) +statsfilepathlist = FindFile(tempdir,statsfilename) + +validcols,marks = generateColIndexandMarks(statsfilepathlist,paperinfo) + + + + + + + + + +pass + + +# print(ParseZipname(zipfilepath)) + +# df = pd.read_excel(os.path.join(os.path.split(dir)[0],"学科总体分析.xlsx")) +# totalstudents = df.loc[2,df.columns[1]] +# validstudents = df.loc[2,df.columns[2]] +# classname = re.findall(r"高[一二三]\d*?班",dir)[0] +# classvalidflag = False +# if threshold * totalstudents < validstudents: +# print(f"{classname} 有效, 共 {totalstudents} 人, 提交 {validstudents} 人") +# classvalidflag = True +# else: +# print(f"!!! {classname} 无效, 共 {totalstudents} 人, 提交 {validstudents} 人") +# if classvalidflag: \ No newline at end of file