From 94ba5fe5ac8a6408715cdaeae8ec839a0b83557f Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Fri, 7 Oct 2022 09:17:10 +0800 Subject: [PATCH] 20221007 morning --- 工具/添加题目到数据库.ipynb | 23 +++++++++++++++-------- 文档/工具基本功能及用法介绍.md | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 文档/工具基本功能及用法介绍.md diff --git a/工具/添加题目到数据库.ipynb b/工具/添加题目到数据库.ipynb index 187edd45..52c21328 100644 --- a/工具/添加题目到数据库.ipynb +++ b/工具/添加题目到数据库.ipynb @@ -2,20 +2,20 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#修改起始id,出处,文件名\n", - "starting_id = 30103\n", + "starting_id = 30105\n", "origin = \"2005年上海秋考理科试题21\"\n", - "filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\临时工作区\\自拟题目.tex\"\n", + "filename = r\"C:\\Users\\weiye\\Documents\\wwy sync\\临时工作区\\自拟题目1.tex\"\n", "editor = \"20221003\\t王伟叶\"" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -55,6 +55,7 @@ " NewProblem[\"edit\"] = [editor]\n", " return NewProblem\n", "\n", + "duplicate_flag = False\n", "\n", "with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n", " database = f.read()\n", @@ -67,6 +68,8 @@ "id = starting_id\n", "for p in problems:\n", " pid = str(id).zfill(6)\n", + " if pid in pro_dict:\n", + " duplicate_flag = True\n", " NewProblem = CreateNewProblem(id = pid, content = p, origin = origin, dict = pro_dict,editor = editor)\n", " pro_dict[pid] = NewProblem\n", " id += 1\n", @@ -77,10 +80,14 @@ "for id in sorted_dict_id:\n", " sorted_dict[id] = pro_dict[id]\n", "#将排序后的字典转为json\n", - "new_database = json.dumps(sorted_dict,indent = 4,ensure_ascii=False)\n", - "#写入json数据库文件\n", - "with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n", - " f.write(new_database)" + "\n", + "if not duplicate_flag:\n", + " new_database = json.dumps(sorted_dict,indent = 4,ensure_ascii=False)\n", + " #写入json数据库文件\n", + " with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n", + " f.write(new_database)\n", + "else:\n", + " print(\"题号有重复, 请检查.\\n\"*5)" ] }, { diff --git a/文档/工具基本功能及用法介绍.md b/文档/工具基本功能及用法介绍.md new file mode 100644 index 00000000..55df3a6c --- /dev/null +++ b/文档/工具基本功能及用法介绍.md @@ -0,0 +1,19 @@ +# 添加新题目到数据库 + +## 工具文件 +``添加题目到数据库.ipynb`` + +## 功能简介 +从一个.tex文件中提取题目内容(用\item开头, 放置在\begin{enumerate}\end{enumerate}环境中), 并从起始id开始将.tex文件中题目逐题添加到数据库中 + +## 用法 + +第一个单元格中需要设置四个位置: + +- ``starting_id``: 整数. 起始id号, 这个号码注意不要和已有的id重复, 可在``Problems.json``中查询空闲id. 处理中如果有重复id的话程序会报重复, 并且不会写入新题目到数据库 + +- ``origin``: 字符串. 题目出处, 同一批题目的出处字符串一致, 尽可能详尽, 对应到``Problems.json``数据库中的``origin``项 + +- ``filename``: 字符串. .tex文件的文件名(含路径) + +- ``editor``: 字符串. 编辑及收录者姓名, 用"\t"分隔日期(yyyymmdd)及姓名, 例如"20221007\t张三" \ No newline at end of file