From 3e01d7b13708b8088847665035d5bc9449ec84e0 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Sat, 8 Apr 2023 20:40:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E5=B7=A5=E5=85=B7=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E4=B8=8A=E5=A2=9E=E5=8A=A0=E4=BA=86=20=E5=9C=A8LaTeX=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BF=AE=E6=94=B9=E9=A2=98=E7=9B=AE=E5=86=85=E5=AE=B9?= =?UTF-8?q?=20=E7=9A=84=E8=8F=9C=E5=8D=95=E9=A1=B9,=20=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=AE=BE=E7=BD=AE=E7=BC=96=E8=BE=91=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具/latex界面修改题目内容.py | 40 +++++++++++++++++++++++ 工具/导入latex界面修改的题目内容.py | 25 +++++++++++++++ 工具/工具面板.py | 9 ++++-- 工具/模板文件/题目编辑.txt | 50 +++++++++++++++++++++++++++++ 工具/试卷答案生成.py | 4 +-- 5 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 工具/latex界面修改题目内容.py create mode 100644 工具/导入latex界面修改的题目内容.py create mode 100644 工具/模板文件/题目编辑.txt diff --git a/工具/latex界面修改题目内容.py b/工具/latex界面修改题目内容.py new file mode 100644 index 00000000..ad0f6b27 --- /dev/null +++ b/工具/latex界面修改题目内容.py @@ -0,0 +1,40 @@ +import os,re,json +"""这里编辑题号(列表)后将在vscode中打开窗口, 编辑后保存关闭""" +problems = "1:10" +editor = "王伟叶" + +def generate_number_set(string,dict): + string = re.sub(r"[\n\s]","",string) + string_list = string.split(",") + numbers_list = [] + for s in string_list: + if not ":" in s: + numbers_list.append(s.zfill(6)) + else: + start,end = s.split(":") + for ind in range(int(start),int(end)+1): + numbers_list.append(str(ind).zfill(6)) + return numbers_list + +with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f: + database = f.read() +pro_dict = json.loads(database) + +idlist = generate_number_set(problems,pro_dict) + +output = "编辑者: " + editor + "\n\n\\begin{enumerate}\n\n" + +for id in idlist: + output += "\\item (%s) "%str(id).zfill(6) + pro_dict[id]["content"] + "\n\n" + +output += "\\end{enumerate}" + +with open("模板文件/题目编辑.txt","r",encoding="u8") as f: + texdata = f.read() + +newtexdata = texdata.replace("待替换",output) + +with open("临时文件/problems_edit.tex","w",encoding="u8") as f: + f.write(newtexdata) + +os.system(r"code -g 临时文件/problems_edit.tex") diff --git a/工具/导入latex界面修改的题目内容.py b/工具/导入latex界面修改的题目内容.py new file mode 100644 index 00000000..deeff930 --- /dev/null +++ b/工具/导入latex界面修改的题目内容.py @@ -0,0 +1,25 @@ +import json,re,time + + + +with open("临时文件/problems_edit.tex","r",encoding="u8") as f: + data = f.read() +problems_string = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate}",data)[0].replace("\\item","")+"" +problems= re.findall("[\s]*\((\d{6})\)([\s\S]*?)",problems_string) +editor = re.findall(r"编辑者:[\s]*([^\n]*)",data)[0].strip() + +with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f: + database = f.read() +pro_dict = json.loads(database) + +for item in problems: + id = item[0] + content = item[1].strip() + if pro_dict[id]["content"] == content: + print("题号%s内容未改变."%id) + else: + pro_dict[id]["content"] = content + pro_dict[id]["edit"].append("%s%s%s\t%s"%(str(time.localtime().tm_year).zfill(4),str(time.localtime().tm_mon).zfill(2),str(time.localtime().tm_mday).zfill(2),editor)) + +with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f: + f.write(json.dumps(pro_dict,indent = 4, ensure_ascii= False)) diff --git a/工具/工具面板.py b/工具/工具面板.py index 43dc2b52..5711b270 100644 --- a/工具/工具面板.py +++ b/工具/工具面板.py @@ -96,7 +96,9 @@ def run_command1(): elif selectedtool == "局部相似题目检测": call(["python","局部相似题目检测.py"]) elif selectedtool == "相同相似题目标注": - call(["python","相同相似题目标注.py"]) + call(["python","相同相似题目标注.py"]) + elif selectedtool == "latex修改题目": + call(["python","latex界面修改题目内容.py"]) LabelTool.config(text = selectedtool+"STEP1命令执行完毕") button1.place_forget() @@ -108,6 +110,8 @@ def run_command2(): call(["python","导入关联题目.py"]) elif selectedtool == "修改题目数据库": call(["python","修改结果汇入.py"]) + elif selectedtool == "latex修改题目": + call(["python","导入latex界面修改的题目内容.py"]) LabelTool.config(text = selectedtool+ "STEP2命令执行完毕") button2.place_forget() @@ -138,7 +142,8 @@ menubar.add_cascade(label = "维护", menu = MaintainenceMenu) MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("批量添加字段数据",1,["文本文件/metadata.txt","批量添加字段数据.py"])) MaintainenceMenu.add_command(label = "手动统计结果转换", command = lambda: SetButton("手动统计结果转换",1,["文本文件/metadata.txt","文本文件/手动统计结果.txt"])) MaintainenceMenu.add_separator() -MaintainenceMenu.add_command(label = "修改题目", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"])) +MaintainenceMenu.add_command(label = "LaTeX界面修改题目内容", command = lambda: SetButton("latex修改题目",2,["latex界面修改题目内容.py"])) +MaintainenceMenu.add_command(label = "修改题目综合信息", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"])) MaintainenceMenu.add_command(label = "识别题目类型", command = lambda: SetButton("识别题目类型",1,[])) diff --git a/工具/模板文件/题目编辑.txt b/工具/模板文件/题目编辑.txt new file mode 100644 index 00000000..0a2ddf23 --- /dev/null +++ b/工具/模板文件/题目编辑.txt @@ -0,0 +1,50 @@ +\documentclass[10pt,a4paper]{article} +\usepackage[UTF8,fontset = none]{ctex} +\setCJKmainfont[BoldFont=黑体,ItalicFont=楷体]{华文中宋} +\usepackage{amssymb,amsmath,amsfonts,amsthm,mathrsfs,dsfont,graphicx} +\usepackage{ifthen,indentfirst,enumerate,color,titletoc} +\usepackage{tikz} +\usepackage{multicol} +\usepackage{multirow} +\usepackage{makecell} +\usepackage{longtable} +\usepackage{diagbox} +\usetikzlibrary{arrows,calc,intersections,patterns,decorations.pathreplacing,3d,angles,quotes,positioning,shapes.geometric} +\usepackage[bf,small,indentafter,pagestyles]{titlesec} +\usepackage[top=1in, bottom=1in,left=0.8in,right=0.8in]{geometry} +\renewcommand{\baselinestretch}{1.65} +\newtheorem{defi}{定义~} +\newtheorem{eg}{例~} +\newtheorem{ex}{~} +\newtheorem{rem}{注~} +\newtheorem{thm}{定理~} +\newtheorem{coro}{推论~} +\newtheorem{axiom}{公理~} +\newtheorem{prop}{性质~} +\newcommand{\blank}[1]{\underline{\hbox to #1pt{}}} +\newcommand{\bracket}[1]{(\hbox to #1pt{})} +\newcommand{\onech}[4]{\par\begin{tabular}{p{.9\linewidth}} +A.~#1\\ +B.~#2\\ +C.~#3\\ +D.~#4 +\end{tabular}} +\newcommand{\twoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}} +A.~#1& B.~#2\\ +C.~#3& D.~#4 +\end{tabular}} +\newcommand{\vartwoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}} +(1)~#1& (2)~#2\\ +(3)~#3& (4)~#4 +\end{tabular}} +\newcommand{\fourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}} +A.~#1 &B.~#2& C.~#3& D.~#4 +\end{tabular}} +\newcommand{\varfourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}} +(1)~#1 &(2)~#2& (3)~#3& (4)~#4 +\end{tabular}} +\begin{document} + +待替换 + +\end{document} \ No newline at end of file diff --git a/工具/试卷答案生成.py b/工具/试卷答案生成.py index 96c8d9b7..3e69fcaa 100644 --- a/工具/试卷答案生成.py +++ b/工具/试卷答案生成.py @@ -1,6 +1,6 @@ -file_dir = r"C:\Users\weiye\Documents\wwy sync\23届\下学期测验卷" +file_dir = r"C:\Users\weiye\Documents\wwy sync\23届\四月错题重做" filelist = [] #列表为空默认处理所有讲义 -output_gloss_filename = "23届下学期测验卷参考答案" +output_gloss_filename = "错题重做参考答案" import os,re,json