158 lines
9.2 KiB
Plaintext
158 lines
9.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"题号: 009876 , 字段: ans 中已修改数据: (1) $27$; (2) $86$; (3) $13$\n",
|
|
"题号: 030075 , 字段: ans 中已修改数据: $\\dfrac{\\sqrt{3}}4R^2$\n",
|
|
"题号: 004596 , 字段: ans 中已修改数据: $-\\dfrac 13$, $\\dfrac{13}6$\n",
|
|
"题号: 004597 , 字段: ans 中已修改数据: (1) $26.5$; (2) 分布列为$\\begin{pmatrix} 0 & 1 & 2 & 3 & 4 \\\\ \\dfrac 1{16} & \\dfrac 4{16} & \\dfrac 6{16} & \\dfrac 4{16} & \\dfrac 1{16}\\end{pmatrix}$, 期望为$2$\n",
|
|
"题号: 004598 , 字段: ans 中已修改数据: (1) 调整前的平均利润为$5000$元每天, 调整后的平均利润为$15000$元每天, 因此调整后的平均利润比调整前更多; (2) 应定价为每张$13$元\n",
|
|
"题号: 004599 , 字段: ans 中已修改数据: (1) $\\begin{pmatrix} 0 & 1 & 2 & 3 & 4 & 5 & 6\\\\ 0.01 & 0.04 & 0.12 & 0.22 & 0.28 & 0.24 & 0.09 \\end{pmatrix}$; (2) 方案一所需费用的期望为$10720$元, 方案二所需费用的期望为$10420$元, 因此选择第二种延保方案更合算\n",
|
|
"题号: 004600 , 字段: ans 中已修改数据: $\\dfrac{5}{9}$, $\\dfrac{5}{36}$\n",
|
|
"题号: 004601 , 字段: ans 中已修改数据: (1) $\\dfrac 35$; (2) 分布列为$\\begin{pmatrix} 0 & 1 & 2 \\\\ \\dfrac 25 & \\dfrac 25 & \\dfrac 15\\end{pmatrix}$, $E[X]=\\dfrac 45$, $D[X]=\\dfrac{14}{25}$\n",
|
|
"题号: 004602 , 字段: ans 中已修改数据: (1) $\\dfrac 5{12}$; (2) 分布列为$\\begin{pmatrix} 0 & 40 & 80 & 120 & 160 \\\\ \\dfrac 1{24} & \\dfrac 14 & \\dfrac 5{12} & \\dfrac 14 & \\dfrac 1{24}\\end{pmatrix}$, $E[X]=80$, $D[X]=\\dfrac{4000}3$\n",
|
|
"题号: 004603 , 字段: ans 中已修改数据: $\\dfrac 2{27}$\n",
|
|
"题号: 004604 , 字段: ans 中已修改数据: $6$\n",
|
|
"题号: 004605 , 字段: ans 中已修改数据: $\\dfrac{20}{243}$\n",
|
|
"题号: 004606 , 字段: ans 中已修改数据: (1) 分布列为$\\begin{pmatrix} 0 & 1 & 2 & 3 \\\\ 0.2p^2-0.4p+0.2 & 0.4p^2-1.2p+0.8 & -1.4p^2+1.6p & 0.8p^2\\end{pmatrix}$, $E[X]=2p+0.8$; (2) $0.96$, $700$棵\n",
|
|
"题号: 004607 , 字段: ans 中已修改数据: (1) $\\begin{pmatrix} 0 & 1 & 2 & 3 \\\\ \\dfrac{729}{1000} & \\dfrac{243}{1000} & \\dfrac{27}{1000} & \\dfrac 1{1000}\\end{pmatrix}$; (2) 一轮游戏获得的分数$Y$的期望$E[Y]=-1.69<0$, 所以许多人的分数没有增加反而减少了\n",
|
|
"题号: 004608 , 字段: ans 中已修改数据: (1) 当$n=5$或$6$时, 有$3$个坑需要补种的概率最大, 最大概率为$\\dfrac 5{16}$; (2) 分布列为$\\begin{pmatrix}0 & 1 & 2 & 3 & 4 \\\\ \\dfrac 1{16} & \\dfrac 14 & \\dfrac 38 & \\dfrac 14 & \\dfrac 1{16}\\end{pmatrix}$, $E[X]=2$\n",
|
|
"题号: 004611 , 字段: ans 中已修改数据: (1) $20p$; (2) $3.2p-1.2$; (3) 当$p\\in (0,\\dfrac 34]$时, 应选择第一个项目(期望更高, 或者期望相同的情况下方差更低), 当$p\\in (\\dfrac 34,1)$时, 应选择第二个项目\n",
|
|
"题号: 004612 , 字段: ans 中已修改数据: $\\dfrac {43}{138}$\n",
|
|
"题号: 004613 , 字段: ans 中已修改数据: $\\dfrac{56}{165}$\n",
|
|
"题号: 004614 , 字段: ans 中已修改数据: $0.042$\n",
|
|
"题号: 004615 , 字段: ans 中已修改数据: (1) $0.191$; (2) $\\dfrac 53$\n",
|
|
"题号: 004616 , 字段: ans 中已修改数据: (1) $48$; (2) 分布列为$\\begin{pmatrix}0 & 1 & 2 \\\\ \\dfrac{12}{19} & \\dfrac{32}{95} & \\dfrac 3{95}\\end{pmatrix}$, $E[X]=\\dfrac 25$; (3) $S=0.012<0.05$, 故本次测试对难度的预估是合理的\n",
|
|
"题号: 004617 , 字段: ans 中已修改数据: (1) $(a,b,c)=(9,6,6)$; (2) $\\begin{pmatrix}0 & 1 & 2 \\\\ \\dfrac 17 & \\dfrac 47 & \\dfrac 27\\end{pmatrix}$\n",
|
|
"题号: 004618 , 字段: ans 中已修改数据: (1) 约$400$名; (2) $0.49$; (3) 分布列为$\\begin{pmatrix}0 & 1 & 2 & 3 \\\\ \\dfrac 1{20} & \\dfrac 9{20} & \\dfrac 9{20} & \\dfrac 1{20}\\end{pmatrix}$, $E[X]=\\dfrac 32$\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.8.15 ('mathdept')",
|
|
"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.15"
|
|
},
|
|
"orig_nbformat": 4,
|
|
"vscode": {
|
|
"interpreter": {
|
|
"hash": "42dd566da87765ddbe9b5c5b483063747fec4aacc5469ad554706e4b742e67b2"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|