“b44b915bda4b22203f8fc8bd3598583ac4548bac”上不存在“doc/fluid/howto/git@gitcode.net:RobotFutures/Paddle.git”
提交 83428604 编写于 作者: M Mars Liu

fxied bug in tree.py

上级 2318de26
{
"type": "code_options",
"author": "幻灰龙",
"source": "standard.md"
"type": "code_options",
"author": "幻灰龙",
"source": "standard.md",
"exercise_id": "8150ef23aad248f78110f33e34754311"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "compiler.md"
"type": "code_options",
"author": "幻灰龙",
"source": "compiler.md",
"exercise_id": "b812499b338541d2955575e56c116da9"
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"vla.json"
]
"export": []
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"pointers_2_func.json"
]
"export": []
}
\ No newline at end of file
......@@ -7,7 +7,5 @@
"C语言"
],
"children": [],
"export": [
"linked_list.json"
]
"export": []
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "bin_to_hex.md"
"type": "code_options",
"author": "幻灰龙",
"source": "bin_to_hex.md",
"exercise_id": "bfae271b73284a6fa5f48bcde4a7f3e0"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "bit_op.md"
"type": "code_options",
"author": "幻灰龙",
"source": "bit_op.md",
"exercise_id": "0952044cc5e54770b7418ed868d201a2"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "pack01.md"
"type": "code_options",
"author": "幻灰龙",
"source": "pack01.md",
"exercise_id": "4aa8ae84487d433e943a5a9ef6293dbd"
}
\ No newline at end of file
{
"type": "code_options",
"author": "幻灰龙",
"source": "pack02.md"
"type": "code_options",
"author": "幻灰龙",
"source": "pack02.md",
"exercise_id": "03f964d865b54fe9947e728585a27486"
}
\ No newline at end of file
......@@ -6,7 +6,5 @@
"C语言"
],
"children": [],
"export": [
"enum.json"
]
"export": []
}
\ No newline at end of file
......@@ -5,7 +5,5 @@
"C语言"
],
"children": [],
"export": [
"inline01.json"
]
"export": []
}
\ No newline at end of file
......@@ -6,7 +6,5 @@
"C语言"
],
"children": [],
"export": [
"file_hash.json"
]
"export": []
}
\ No newline at end of file
此差异已折叠。
......@@ -37,6 +37,19 @@ def parse_no_name(d):
return no, dir_name
def check_export(base, cfg):
flag = False
exports = []
for export in cfg.get('export', []):
ecfg_path = os.path.join(base, export)
if os.path.exists(ecfg_path):
exports.append(export)
else:
flag = True
if flag:
cfg["export"] = exports
return flag
def gen_tree(data_path):
root = {}
......@@ -54,18 +67,21 @@ def gen_tree(data_path):
yield no_dir, no_name
def ensure_id_helper(node):
flag = False
if (node.get('node_id') is None) or node.get('node_id') in id_set:
node['node_id'] = gen_node_id()
flag = True
id_set.add(node['node_id'])
if 'children' in node:
for c in node["children"]:
ensure_id_helper(list(c.values())[0])
flag = flag or ensure_id_helper(list(c.values())[0])
def ensure_node_id(cfg_path, cfg):
ensure_id_helper(cfg)
dump_json(cfg_path, cfg, exist_ok=True, override=True)
return flag
def ensure_node_id(cfg):
return ensure_id_helper(cfg)
def make_node(name, node_id, keywords, children=None):
node = {}
......@@ -80,7 +96,8 @@ def gen_tree(data_path):
# 根节点
cfg_path = os.path.join(data_path, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
if ensure_node_id(cfg):
dump_json(cfg_path, cfg)
tree_node = {
"node_id": cfg['node_id'],
"keywords": cfg['keywords'],
......@@ -92,48 +109,52 @@ def gen_tree(data_path):
for level_no_dir, level_no_name in list_dir(data_path):
print(level_no_dir)
no, level_name = parse_no_name(level_no_name)
cfg_path = os.path.join(level_no_dir, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
level_path = os.path.join(level_no_dir, 'config.json')
level_cfg = load_json(level_path)
if ensure_node_id(level_cfg) or check_export(level_no_dir, level_cfg):
dump_json(level_path, level_cfg, exist_ok=True, override=True)
level_node, level_node_children = make_node(
level_name, cfg['node_id'], cfg['keywords'])
tree_node['children'].append(level_node)
# 章节点
for chapter_no_dir, chapter_no_name in list_dir(level_no_dir):
no, chapter_name = parse_no_name(chapter_no_name)
cfg_path = os.path.join(chapter_no_dir, 'config.json')
ensure_node_id(cfg_path, cfg)
cfg = load_json(cfg_path)
chapter_path = os.path.join(chapter_no_dir, 'config.json')
chapter_cfg = load_json(chapter_path)
if ensure_node_id(chapter_cfg) or check_export(chapter_no_dir, chapter_cfg):
dump_json(chapter_path, chapter_cfg, exist_ok=True, override=True)
chapter_node, chapter_node_children = make_node(
chapter_name, cfg['node_id'], cfg['keywords'])
chapter_name, chapter_cfg['node_id'], chapter_cfg['keywords'])
level_node_children.append(chapter_node)
# 知识点
for section_no_dir, section_no_name in list_dir(chapter_no_dir):
no, section_name = parse_no_name(section_no_name)
cfg_path = os.path.join(section_no_dir, 'config.json')
cfg = load_json(cfg_path)
ensure_node_id(cfg_path, cfg)
sec_path = os.path.join(section_no_dir, 'config.json')
sec_cfg = load_json(sec_path)
flag = ensure_node_id(sec_cfg) or check_export(section_no_dir, sec_cfg)
section_node, section_node_children = make_node(
section_name, cfg['node_id'], cfg['keywords'], cfg['children'])
section_name, sec_cfg['node_id'], sec_cfg['keywords'], sec_cfg['children'])
chapter_node_children.append(section_node)
# 确保习题分配了习题ID
for export in cfg['export']:
for export in sec_cfg["export"]:
ecfg_path = os.path.join(section_no_dir, export)
ecfg = load_json(ecfg_path)
if (ecfg.get('exercise_id') is None) or (ecfg.get('exercise_id') in id_set):
ecfg['exercise_id'] = uuid.uuid4().hex
ecfg['exercise_id'] = uuid.uuid4().hex
dump_json(ecfg_path, ecfg, exist_ok=True, override=True)
id_set.add(ecfg['exercise_id'])
dump_json(cfg_path, cfg, exist_ok=True, override=True)
if flag:
dump_json(cfg_path, cfg, exist_ok=True, override=True)
# 保存技能树骨架
tree_path = os.path.join(data_path, 'tree.json')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册