156 lines
7.2 KiB
Plaintext
156 lines
7.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"题号: 012655 , 字段: ans 中已修改数据: $\\{2\\}$\n",
|
|
"题号: 012656 , 字段: ans 中已修改数据: $(-1,1)$\n",
|
|
"题号: 012657 , 字段: ans 中已修改数据: $\\sqrt{5}$\n",
|
|
"题号: 012658 , 字段: ans 中已修改数据: $5$\n",
|
|
"题号: 012659 , 字段: ans 中已修改数据: $3$\n",
|
|
"题号: 012660 , 字段: ans 中已修改数据: $0.3$\n",
|
|
"题号: 012661 , 字段: ans 中已修改数据: $\\dfrac{\\sqrt{3}}3\\pi$\n",
|
|
"题号: 012662 , 字段: ans 中已修改数据: $2$\n",
|
|
"题号: 012663 , 字段: ans 中已修改数据: $96$\n",
|
|
"题号: 012664 , 字段: ans 中已修改数据: $\\dfrac 53$\n",
|
|
"题号: 012665 , 字段: ans 中已修改数据: $60^\\circ$\n",
|
|
"题号: 012666 , 字段: ans 中已修改数据: $2021$\n",
|
|
"题号: 012667 , 字段: ans 中已修改数据: B\n",
|
|
"题号: 012668 , 字段: ans 中已修改数据: A\n",
|
|
"题号: 012669 , 字段: ans 中已修改数据: C\n",
|
|
"题号: 012670 , 字段: ans 中已修改数据: B\n",
|
|
"题号: 012671 , 字段: ans 中已修改数据: (1) $[k\\pi-\\dfrac{5\\pi}{12},k\\pi+\\dfrac\\pi{12}]$, $k\\in \\mathbf{Z}$; (2) $\\sqrt{13}$或$\\sqrt{61}$\n",
|
|
"题号: 012672 , 字段: ans 中已修改数据: (1) 证明略; (2) $a_n=3^n-2$; (3) $a_1+a_3+a_5+a_7+a_9=22133$\n",
|
|
"题号: 012673 , 字段: ans 中已修改数据: (1) 证明略; (2) $\\arccos \\dfrac{\\sqrt{10}}{10}$; (3) $\\dfrac 13$\n",
|
|
"题号: 012674 , 字段: ans 中已修改数据: (1) $\\dfrac{x^2}{12}+\\dfrac{y^2}4=1$; (2) $3+2\\sqrt{3}$; (3) 存在, $m$的取值范围为$[-\\dfrac{\\sqrt{3}}3,0)$\n",
|
|
"题号: 012675 , 字段: ans 中已修改数据: (1) 当$a=0$时, $f(x)$是偶函数; 当$a\\ne 0$时, $f(x)$既不是奇函数又不是偶函数; (2) $(-1,\\dfrac 5{27})$; (3) $[2\\ln 2-2,1]$\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os,re,json\n",
|
|
"\n",
|
|
"\"\"\"---明确数据文件位置---\"\"\"\n",
|
|
"datafile = \"文本文件/metadata.txt\"\n",
|
|
"# 双回车分隔,记录内单回车分隔列表,首行为字段名\n",
|
|
"\"\"\"---文件位置结束---\"\"\"\n",
|
|
"\n",
|
|
"def trim(string):\n",
|
|
" string = re.sub(r\"^[ \\t\\n]*\",\"\",string)\n",
|
|
" string = re.sub(r\"[ \\t\\n]*$\",\"\",string)\n",
|
|
" return string\n",
|
|
"def FloatToInt(string):\n",
|
|
" f = float(string)\n",
|
|
" if abs(f-round(f))<0.01:\n",
|
|
" f = round(f)\n",
|
|
" return f\n",
|
|
"\n",
|
|
"with open(datafile,\"r\",encoding=\"utf8\") as f:\n",
|
|
" data = f.read()\n",
|
|
"pos = data.index(\"\\n\")\n",
|
|
"field = data[:pos].strip()\n",
|
|
"appending_data = data[pos:]\n",
|
|
"\n",
|
|
"with open(r\"../题库0.3/Problems.json\",\"r\",encoding = \"utf8\") as f:\n",
|
|
" database = f.read()\n",
|
|
"pro_dict = json.loads(database)\n",
|
|
"with open(r\"../题库0.3/LessonObj.json\",\"r\",encoding = \"utf8\") as f:\n",
|
|
" database = f.read()\n",
|
|
"obj_dict = json.loads(database)\n",
|
|
"\n",
|
|
"#该字段列表可能需要更新\n",
|
|
"fields = [\"content\",\"objs\",\"tags\",\"genre\",\"ans\",\"solution\",\"duration\",\"usages\",\"origin\",\"edit\",\"same\",\"related\",\"remark\",\"space\"]\n",
|
|
"\n",
|
|
"if field in fields:\n",
|
|
" field_type = type(pro_dict[\"000001\"][field])\n",
|
|
" datalist = [record.strip() for record in appending_data.split(\"\\n\\n\") if len(trim(record)) > 0]\n",
|
|
" for record in datalist:\n",
|
|
" id = re.findall(r\"^[\\d]{1,}\",record)[0]\n",
|
|
" data = record[len(id):].strip()\n",
|
|
" id = id.zfill(6)\n",
|
|
" if not id in pro_dict:\n",
|
|
" print(\"题号:\",id,\"不在数据库中.\")\n",
|
|
" break\n",
|
|
" \n",
|
|
" #字符串类型字段添加数据\n",
|
|
" elif field_type == str and data in pro_dict[id][field]:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",data)\n",
|
|
" elif field_type == str and not data in pro_dict[id][field] and not field == \"ans\" and not field == \"space\":\n",
|
|
" origin_data = pro_dict[id][field]\n",
|
|
" new_data = trim(origin_data + \"\\n\" + data)\n",
|
|
" pro_dict[id][field] = new_data\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",data)\n",
|
|
" elif field_type == str and not data in pro_dict[id][field] and field == \"ans\" or field == \"space\":\n",
|
|
" pro_dict[id][field] = data\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已修改数据:\",data)\n",
|
|
" \n",
|
|
" #数值类型字段添加数据\n",
|
|
" elif (field_type == int or field_type == float) and abs(float(data) - pro_dict[id][field])<0.01:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",FloatToInt(data))\n",
|
|
" elif (field_type == int or field_type == float) and abs(float(data) - pro_dict[id][field])>=0.01:\n",
|
|
" pro_dict[id][field] = FloatToInt(data)\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已修改数据:\",FloatToInt(data))\n",
|
|
" \n",
|
|
" #列表类型字段添加数据\n",
|
|
" elif field_type == list:\n",
|
|
" cell_data_list = [d.strip() for d in data.split(\"\\n\")]\n",
|
|
" for cell_data in cell_data_list:\n",
|
|
" if cell_data in pro_dict[id][field]:\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已有该数据:\",cell_data)\n",
|
|
" elif not field == \"objs\":\n",
|
|
" pro_dict[id][field].append(cell_data)\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",cell_data)\n",
|
|
" else:\n",
|
|
" if not cell_data in obj_dict and not cell_data.upper() == \"KNONE\":\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"目标编号有误:\",cell_data)\n",
|
|
" else:\n",
|
|
" pro_dict[id][field].append(cell_data.upper())\n",
|
|
" print(\"题号:\",id,\", 字段:\",field,\"中已添加数据:\",cell_data.upper())\n",
|
|
"\n",
|
|
"with open(r\"../题库0.3/Problems.json\",\"w\",encoding = \"utf8\") as f:\n",
|
|
" f.write(json.dumps(pro_dict,indent=4,ensure_ascii=False))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3.9.15 ('pythontest')",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.9.15"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "91219a98e0e9be72efb992f647fe78b593124968b75db0b865552d6787c8db93"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|