This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v2/收集使用记录.py

139 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""工程中"""
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: