From 4c38b4cca4a632ea553e6e06d9dc4966abf8b4fa Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sun, 14 Apr 2024 19:26:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E9=A2=98=E6=AF=94=E5=AF=B9=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v3/database_tools_2.py | 4 +-- 工具v3/新题比对.py | 63 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 工具v3/新题比对.py diff --git a/工具v3/database_tools_2.py b/工具v3/database_tools_2.py index 531a1b91..4d99c1d8 100644 --- a/工具v3/database_tools_2.py +++ b/工具v3/database_tools_2.py @@ -114,8 +114,8 @@ def stringmaxsim(string,adict,listlength): maxsimlist = [] string = pre_treating(string) for id in adict: - if not "OBSOLETE" in adict[id]["content"]: - simrate = Levenshtein.jaro(adict[id]["content"],string) + if not "OBS" in adict[id]: + simrate = Levenshtein.jaro(adict[id],string) # if simrate > maxsim: # maxsim = simrate # argmaxsim = id diff --git a/工具v3/新题比对.py b/工具v3/新题比对.py new file mode 100644 index 00000000..86cb65d5 --- /dev/null +++ b/工具v3/新题比对.py @@ -0,0 +1,63 @@ +outputpath = "临时文件/新题比对.tex" + + + +from database_tools_2 import * +colors = ["green","orange","blue"] +templatepath = "./模板文件/讲义模板.txt" + +mydb = connect(hostname = "wwylss.synology.me", username="root", pwd="Wwy@0018705", port = "13306", db = "tikutest") #连接数据库 +mycursor = mydb.cursor() + +mycursor.execute("SELECT ID,content FROM problems;") +ret_list = mycursor.fetchall() +pro_dict = {i:j for i,j in ret_list} +treated_dict = {i:pre_treating(pro_dict[i]) for i in pro_dict.keys()} +mydb.close() + +data_raw = getCopy() +if data_raw.strip().startswith("\\item"): + data_raw = "\\begin{enumerate}\n"+data_raw +if data_raw.count("\\begin{enumerate}") == data_raw.count("\\end{enumerate}") + 1: + data_raw = data_raw + "\n\\end{enumerate}" +problems_raw = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate\}",data_raw) +data = "\n".join([item.strip() for item in problems_raw]) +problems = [(d.strip()) for d in data.split("\\item") if not d.strip() == ""] +output = "使用说明:\\\\\n rep??????表示使用已有题号??????,\\\\\n s??????表示和??????相同,\\\\\n r??????表示和??????相关\n\n\\begin{enumerate}\n\n" + + +for p in problems: + p_treated = pre_treating(p) + t = stringmaxsim(p_treated,treated_dict,5) + psrstring = "" + for id,simrate in t: + if simrate == 1: + psrstring = "rep"+id+"," + else: + psrstring += id + "," + if psrstring[-1] == ",": + psrstring = psrstring[:-1] + output += f"\\item [{psrstring}] {p}\n\n" + count = 0 + for id,simrate in t: + if simrate > 0.5: + colors = get_color(simrate*2-1) + output += "\n\\definecolor{mycolor}{rgb}"+colors + output += "\n\\begin{tcolorbox}"+f"[colback = mycolor, opacityback = 0.25, colframe = orange!10!white, breakable]\n" + output += f"{simrate:.3f} \\ {id}\n\n" + content = pro_dict[id] + output += f"{content}\n" + output += "\\end{tcolorbox}\n" + count += 1 + output += "\n\n" +output += "\n\\end{enumerate}\n\n" + +texraw = ReadTextFile(templatepath) +texdata = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",texraw,("新题比对"+f"{GetDate()}",output)) + + +texfilepath = os.path.join(os.getcwd(),outputpath) +SaveTextFile(texdata,texfilepath) +os.system(f"code {texfilepath}") +# dir,filename = os.path.split(texfilepath) +# XeLaTeXCompile(dir,filename) \ No newline at end of file