20230328 night

This commit is contained in:
weiye.wang 2023-03-28 22:59:54 +08:00
parent d5b7d1956c
commit b69b2e839d
9 changed files with 346 additions and 19 deletions

View File

@ -13,9 +13,8 @@ except:
pass
def testcall():
LabelTool.config(text = "测试")
LabelOutputDir.insert(0,"1")
print("按钮")
LabelTool.config(text = commandname.get())
print(commandname.get())
def SetOutputDir():
try:
@ -24,14 +23,38 @@ def SetOutputDir():
pass
print("输出目录设为",LabelOutputDir.get())
def run_command():
selectedtool = commandname.get()
if selectedtool == "题号选题pdf生成":
call(["python","题号选题pdf生成.py"])
elif selectedtool == "寻找空闲题号":
call(["python","寻找空闲题号.py"])
elif selectedtool == "批量收录题目":
call(["python","批量收录题目.py"])
elif selectedtool == "添加关联题目STEP1":
call(["python","添加关联题目.py"])
elif selectedtool == "添加关联题目STEP2":
call(["python","导入关联题目.py"])
elif selectedtool == "修改题目STEP1":
call(["python","修改题目数据库.py"])
elif selectedtool == "修改题目STEP2":
call(["python","修改结果汇入.py"])
root = Tk()
outputdirectory = StringVar()
outputdirectory.set(rawoutputdirectory)
commandname = StringVar()
commandname.set("none")
print(commandname.get())
root.geometry("800x600")
LabelTool = Label(root, text = "工具选择待定", height = 1, width = 10)
LabelTool = Label(root, text = "工具选择待定", height = 1, width = 25, anchor=W)
LabelTool.place(x=420,y=50)
# 设置输出目录名
LabelOutputDir = Entry(root,textvariable=outputdirectory)
LabelOutputDir.place(x = 420, y = 120, width = 250)
@ -40,8 +63,45 @@ LabelOutputDir.place(x = 420, y = 120, width = 250)
ButtonDir = Button(root,text = "输出目录确定", command = SetOutputDir)
ButtonDir.place(x=700, y=120)
# 题目导入标签
LabelAPPEND = Label(root, text = "题目导入")
LabelAPPEND.place(x=20,y=0)
# 寻找空闲题号按钮
ButtonKXTH = Button(root, text = "寻找空闲题号", command = lambda: (commandname.set("寻找空闲题号"),LabelTool.config(text = "寻找空闲题号")))
ButtonKXTH.place(x=20,y=20)
# 批量收录题目按钮
ButtonSLTM = Button(root, text = "批量收录题目", command = lambda: (commandname.set("批量收录题目"),LabelTool.config(text = "批量收录题目")))
ButtonSLTM.place(x=20,y=50)
# 添加关联题目STEP1按钮
ButtonTJGL = Button(root, text = "添加关联题目STEP1", command = lambda: (commandname.set("添加关联题目STEP1"),LabelTool.config(text = "添加关联题目STEP1")))
ButtonTJGL.place(x=20,y=80)
# 添加关联题目STEP2按钮
ButtonTJGL2 = Button(root, text = "添加关联题目STEP2", command = lambda: (commandname.set("添加关联题目STEP2"),LabelTool.config(text = "添加关联题目STEP2")))
ButtonTJGL2.place(x=140,y=80)
# 题库维护标签
LabelMAINTAINENCE = Label(root, text = "题库维护")
LabelMAINTAINENCE.place(x=20,y=200)
# 修改题目STEP1按钮
ButtonTJGL = Button(root, text = "修改题目STEP1", command = lambda: (commandname.set("修改题目STEP1"),LabelTool.config(text = "修改题目STEP1")))
ButtonTJGL.place(x=20,y=220)
# 修改题目STEP2按钮
ButtonTJGL2 = Button(root, text = "修改题目STEP2", command = lambda: (commandname.set("修改题目STEP2"),LabelTool.config(text = "修改题目STEP2")))
ButtonTJGL2.place(x=120,y=220)
# 题库使用标签
LabelUSE = Label(root, text = "题库使用")
LabelUSE.place(x=20,y=400)
# 题号选题pdf生成按钮
ButtonTHXT = Button(root, text = "题号选题pdf生成", command = lambda: (commandname.set("题号选题pdf生成"),LabelTool.config(text = "题号选题pdf生成")))
ButtonTHXT.place(x=20,y=420)
# 运行按钮
ButtonGo = Button(root, text ="运行", height = 1, width = 5, command = testcall)
ButtonGo = Button(root, text ="运行", height = 1, width = 5, command = run_command)
ButtonGo.place(x=600, y= 550)
# 编译

View File

@ -0,0 +1,15 @@
import json
"""编辑完成保存关闭后运行这个代码块"""
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
with open(r"临时文件/problem_edit.json","r",encoding="u8") as f:
datanew = f.read()
new_pro = json.loads(datanew)
for id in new_pro:
pro_dict[id] = new_pro[id].copy()
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(json.dumps(pro_dict,indent = 4,ensure_ascii=False))

View File

@ -0,0 +1,30 @@
import os,re,json
"""这里编辑题号(列表)后将在vscode中打开窗口, 编辑后保存关闭, 随后运行第二个代码块"""
problems = "1"
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_list = {}
for id in idlist:
output_list[id] = pro_dict[id].copy()
with open(r"临时文件/problem_edit.json","w",encoding="u8") as f:
f.write(json.dumps(output_list,indent = 4,ensure_ascii=False))
os.system(r"code -g 临时文件/problem_edit.json")

View File

@ -0,0 +1,16 @@
import json
with open(r"..\题库0.3\Problems.json","r",encoding = "utf8") as f:
database = f.read()
idlist = list(json.loads(database).keys())
freeidlist = {}
for id in idlist:
if not str(int(id)+1).zfill(6) in idlist:
freeidlist[id] = ""
for id in freeidlist:
largeridlist = [usedid for usedid in idlist if usedid > id]
if not largeridlist == []:
freeidlist[id] = str(int(min(largeridlist))-1).zfill(6)
else:
freeidlist[id] = "999999"
for id in freeidlist:
print("首个空闲id:",str(int(id)+1),", 直至",freeidlist[id])

View File

@ -0,0 +1,21 @@
import json
"""编辑完成保存关闭后运行这个代码块"""
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
with open(r"临时文件/problem_edit.json","r",encoding="u8") as f:
datanew = f.read()
new_pro = json.loads(datanew)
for id in new_pro:
pro_dict[id] = new_pro[id].copy()
#按id排序生成字典
sorted_dict_id = sorted(pro_dict)
sorted_dict = {}
for id in sorted_dict_id:
sorted_dict[id] = pro_dict[id]
#将排序后的字典转为json
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(json.dumps(sorted_dict,indent = 4,ensure_ascii=False))

View File

@ -0,0 +1,101 @@
#修改起始id,出处,文件名
starting_id = 40396
raworigin = ""
filename = r"C:\Users\weiye\Documents\wwy sync\临时工作区\自拟题目9.tex"
editor = "20230328\t王伟叶"
indexed = False
import os,re,json
#从enumerate环境的字符串生成题目列表
def GenerateProblemListFromString(data):
try:
data = re.findall(r"\\begin\{document\}([\s\S]*?)\\end\{document\}",problems_string)[0]
except:
pass
data = re.sub(r"\n{2,}","\n",data)
data = re.sub(r"\\item",r"\\enditem\\item",data)
data = re.sub(r"\\end\{enumerate\}",r"\\enditem",data)
ProblemList_raw = [p.strip() for p in re.findall(r"\\item([\s\S]*?)\\enditem",data)]
ProblemsList = []
for p in ProblemList_raw:
startpos = data.index(p)
tempdata = data[:startpos]
suflist = re.findall(r"\n(\%\s{0,1}[\S]+)\n",tempdata)
if len(suflist) > 0:
suffix = suflist[-1].replace("%","").strip()
else:
suffix = ""
p_strip = re.sub(r"\n(\%[\S]+)$","",p).strip()
ProblemsList.append((p_strip,suffix))
return ProblemsList
# 创建新的空题目
def CreateEmptyProblem(problem):
NewProblem = problem.copy()
for field in NewProblem:
if type(NewProblem[field]) == str:
NewProblem[field] = ""
elif type(NewProblem[field]) == list:
NewProblem[field] = []
elif type(NewProblem[field]) == int or type(NewProblem[field]) == float:
NewProblem[field] = -1
return NewProblem
# 创建新题目
def CreateNewProblem(id,content,origin,dict,editor):
NewProblem = CreateEmptyProblem(dict["000001"])
NewProblem["id"] = str(id).zfill(6)
NewProblem["content"] = content
NewProblem["origin"] = origin
NewProblem["edit"] = [editor]
return NewProblem
duplicate_flag = False
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
with open(filename,"r",encoding = "utf8") as f:
problems_string = f.read()
problems = GenerateProblemListFromString(problems_string)
id = starting_id
for p_and_suffix in problems:
p = p_and_suffix[0]
suffix = p_and_suffix[1]
pid = str(id).zfill(6)
if pid in pro_dict:
duplicate_flag = True
if indexed == False:
origin = raworigin + suffix
else:
origin = raworigin + suffix + "试题" + str(id- starting_id+1)
NewProblem = CreateNewProblem(id = pid, content = p, origin = origin, dict = pro_dict,editor = editor)
if "blank" in NewProblem["content"]:
NewProblem["genre"] = "填空题"
elif "bracket" in NewProblem["content"]:
NewProblem["genre"] = "选择题"
else:
NewProblem["genre"] = "解答题"
print("添加题号"+pid+", "+"来源: " + origin)
pro_dict[pid] = NewProblem
id += 1
#按id排序生成字典
sorted_dict_id = sorted(pro_dict)
sorted_dict = {}
for id in sorted_dict_id:
sorted_dict[id] = pro_dict[id]
#将排序后的字典转为json
if not duplicate_flag:
new_database = json.dumps(sorted_dict,indent = 4,ensure_ascii=False)
#写入json数据库文件
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(new_database)
else:
print("题号有重复, 请检查.\n"*5)

View File

@ -2,15 +2,15 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import os,re,json,time\n",
"\n",
"\"\"\"---设置原题目id与新题目id列表, 新id的数目不能小于旧id的数目---\"\"\"\n",
"old_ids = \"603\"\n",
"new_ids = \"31360\"\n",
"old_ids = \"603,604\"\n",
"new_ids = \"50000:60000\"\n",
"\"\"\"---设置完毕---\"\"\"\n",
"\"\"\"---完成编辑后记得运行第二个单元格---\"\"\"\n",
"\n",
@ -52,10 +52,12 @@
"\n",
"\n",
"# 将未修订的题目添加入数据库, 并作好关联\n",
"used_new_id_list = []\n",
"if not occupied_flag and length_new >= length_old:\n",
" for pos in range(length_old):\n",
" old_id = old_id_list[pos]\n",
" new_id = new_id_list[pos]\n",
" used_new_id_list.append(new_id)\n",
" pro_dict[new_id] = {}\n",
" for field in pro_dict[old_id]:\n",
" if not field == \"id\":\n",
@ -72,7 +74,7 @@
" with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n",
" f.write(json.dumps(pro_dict,indent = 4,ensure_ascii= False))\n",
" output_list = {}\n",
" for id in new_id_list:\n",
" for id in used_new_id_list:\n",
" output_list[id] = pro_dict[id].copy()\n",
"\n",
" with open(r\"临时文件/problem_edit.json\",\"w\",encoding=\"u8\") as f:\n",

View File

@ -0,0 +1,76 @@
import os,re,json,time
"""---设置原题目id与新题目id列表, 新id的数目不能小于旧id的数目---"""
old_ids = "603,604"
new_ids = "50000:60000"
"""---设置完毕---"""
"""---完成编辑后记得运行第二个单元格---"""
# 题号转换
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)
old_id_list = generate_number_set(old_ids,pro_dict)
new_id_list = generate_number_set(new_ids,pro_dict)
#判断是否有已占用的题号
occupied_flag = False
for new_id in new_id_list:
if new_id in pro_dict:
print("ID",new_id,"已被使用.")
occupied_flag = True
length_old = len(old_id_list)
length_new = len(new_id_list)
if length_old > length_new:
print("新ID的个数不够")
# 将未修订的题目添加入数据库, 并作好关联
used_new_id_list = []
if not occupied_flag and length_new >= length_old:
for pos in range(length_old):
old_id = old_id_list[pos]
new_id = new_id_list[pos]
used_new_id_list.append(new_id)
pro_dict[new_id] = {}
for field in pro_dict[old_id]:
if not field == "id":
pro_dict[new_id][field] = pro_dict[old_id][field] if not type(pro_dict[old_id][field]) == list else pro_dict[old_id][field].copy()
else:
pro_dict[new_id][field] = new_id
pro_dict[new_id]["related"].append(old_id)
pro_dict[new_id]["same"] = []
pro_dict[new_id]["objs"] = pro_dict[old_id]["objs"].copy()
pro_dict[new_id]["usages"] = []
pro_dict[new_id]["edit"].append(str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2) + "\t")
pro_dict[old_id]["related"].append(new_id)
pro_dict[new_id]["origin"] += "-" + str(time.localtime().tm_year)+str(time.localtime().tm_mon).zfill(2)+str(time.localtime().tm_mday).zfill(2) + "修改"
with open(r"../题库0.3/Problems.json","w",encoding = "utf8") as f:
f.write(json.dumps(pro_dict,indent = 4,ensure_ascii= False))
output_list = {}
for id in used_new_id_list:
output_list[id] = pro_dict[id].copy()
with open(r"临时文件/problem_edit.json","w",encoding="u8") as f:
f.write(json.dumps(output_list,indent = 4,ensure_ascii=False))
os.system(r"code -g 临时文件/problem_edit.json")

View File

@ -7,7 +7,7 @@
"outputs": [],
"source": [
"#修改起始id,出处,文件名\n",
"starting_id = 40387\n",
"starting_id = 40396\n",
"raworigin = \"\"\n",
"filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\临时工作区\\自拟题目9.tex\"\n",
"editor = \"20230328\\t王伟叶\"\n",
@ -23,15 +23,15 @@
"name": "stdout",
"output_type": "stream",
"text": [
"添加题号040387, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040388, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040389, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040390, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040391, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040392, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040393, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040394, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号040395, 来源: 2025届高一下学期周末卷02小测\n"
"添加题号050000, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050001, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050002, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050003, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050004, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050005, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050006, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050007, 来源: 2025届高一下学期周末卷02小测\n",
"添加题号050008, 来源: 2025届高一下学期周末卷02小测\n"
]
}
],
@ -106,6 +106,12 @@
" else:\n",
" origin = raworigin + suffix + \"试题\" + str(id- starting_id+1)\n",
" NewProblem = CreateNewProblem(id = pid, content = p, origin = origin, dict = pro_dict,editor = editor)\n",
" if \"blank\" in NewProblem[\"content\"]:\n",
" NewProblem[\"genre\"] = \"填空题\"\n",
" elif \"bracket\" in NewProblem[\"content\"]:\n",
" NewProblem[\"genre\"] = \"选择题\"\n",
" else:\n",
" NewProblem[\"genre\"] = \"解答题\"\n",
" print(\"添加题号\"+pid+\", \"+\"来源: \" + origin)\n",
" pro_dict[pid] = NewProblem\n",
" id += 1\n",