169 lines
8.5 KiB
Plaintext
169 lines
8.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"题号: 003148 , 字段: ans 中已修改数据: $\\{x|\\dfrac\\pi 2+2k\\pi\\le x\\le \\dfrac{3\\pi}2+2k\\pi, \\ k\\in \\mathbf{Z}\\}$\n",
|
|
"题号: 003155 , 字段: ans 中已修改数据: (1) $\\{x|2k\\pi<x<2k\\pi+\\dfrac\\pi 2\\text{或}2k\\pi+\\dfrac \\pi 2<x<2k\\pi+\\dfrac{2\\pi}3, \\ k\\in \\mathbf{Z}\\}$, (2) $(-4,-\\pi]\\cup [0,\\pi]$\n",
|
|
"题号: 003158 , 字段: ans 中已修改数据: $[-2,1]$\n",
|
|
"题号: 003149 , 字段: ans 中已修改数据: $[-1,2]$\n",
|
|
"题号: 003156 , 字段: ans 中已修改数据: (1) $y_{\\min}=1-\\sqrt{2}$, $y_{\\max}=1+\\sqrt{2}$; (2) $y_{\\min}=-\\dfrac 12$, $y_{\\max}=\\dfrac{\\sqrt{2}}4$; (3) $y_{\\min}=0$, $y_{\\max}=2$.\n",
|
|
"题号: 003163 , 字段: ans 中已修改数据: $-1$\n",
|
|
"题号: 003162 , 字段: ans 中已修改数据: $[4,+\\infty)$\n",
|
|
"题号: 000119 , 字段: ans 中已修改数据: (1) $4\\pi$; (2) $\\dfrac{2\\pi}3$.\n",
|
|
"题号: 003175 , 字段: ans 中已修改数据: (1) 值域为$[-2,2]$, 周期为$\\pi$; (2) $[\\dfrac\\pi{12},\\dfrac\\pi 2]$; (3) $\\dfrac{\\pi}{12}$; (4) $(-\\infty,-2]\\cup [1,+\\infty)$.\n",
|
|
"题号: 008287 , 字段: ans 中已修改数据: \\begin{tikzpicture}[>=latex,scale = 0.5]\n",
|
|
"\\draw [->] (-1,0) -- (15,0) node [below] {$x$};\n",
|
|
"\\draw [->] (0,-3) -- (0,3) node [left] {$y$};\n",
|
|
"\\draw (0,0) node [below left] {$O$};\n",
|
|
"\\draw [domain = 0:720] plot ({\\x/180*pi},{2*sin(\\x/2)});\n",
|
|
"\\draw [dashed] (pi,0) node [below] {$\\pi$} -- (pi,2) -- (0,2) node [left] {$2$};\n",
|
|
"\\draw [dashed] ({3*pi},0) node [above] {$3\\pi$} -- ({3*pi},-2) -- (0,-2) node [left] {$-2$};\n",
|
|
"\\draw ({4*pi},0) node [above] {$4\\pi$} ({2*pi},0) node [below left] {$2\\pi$};\n",
|
|
"\\end{tikzpicture}\n",
|
|
"题号: 003169 , 字段: ans 中已修改数据: $y=\\sin(2x+\\dfrac\\pi 3)$\n",
|
|
"题号: 001554 , 字段: ans 中已修改数据: \\textcircled{1} 横坐标不变, 纵坐标变为原来的$\\dfrac 12$倍, \\textcircled{2} 向上平移$\\dfrac 54$个单位, \\textcircled{3} 向左平移$\\dfrac \\pi 6$个单位, \\textcircled{4} 纵坐标不变, 横坐标变为原来的$\\dfrac 12$倍.\n",
|
|
"题号: 003176 , 字段: ans 中已修改数据: $f(x)=-4\\sin(\\dfrac \\pi 8 x+\\dfrac \\pi 4)$\n",
|
|
"题号: 003178 , 字段: ans 中已修改数据: B\n",
|
|
"题号: 003181 , 字段: ans 中已修改数据: $-\\dfrac{\\sqrt{3}}3$\n",
|
|
"题号: 003167 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003171 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003166 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003168 , 字段: ans 中已有该数据: \n",
|
|
"题号: 008337 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003153 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003160 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003183 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003164 , 字段: ans 中已有该数据: \n",
|
|
"题号: 003182 , 字段: ans 中已有该数据: \n",
|
|
"题号: 000131 , 字段: ans 中已有该数据: \n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import os,re,json\n",
|
|
"\n",
|
|
"\"\"\"---明确数据文件位置---\"\"\"\n",
|
|
"datafile = \"临时文件/answers.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.8.8 ('base')",
|
|
"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.8.8"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "d311ffef239beb3b8f3764271728f3972d7b090c974f8e972fcdeedf230299ac"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|