(self, leet, file, slug, out_name)
| 31 | self.add_finish_icon(path) |
| 32 | |
| 33 | def generate_leetcode(self, leet, file, slug, out_name): |
| 34 | c = util.get_file_content(util.get_map(file)) |
| 35 | m = datamap.DataMap(c) |
| 36 | self.m = m |
| 37 | g = Digraph('stones', encoding='utf-8') |
| 38 | |
| 39 | for n in m.nodes: |
| 40 | if n.is_root: |
| 41 | count = self.get_module_problem_count(m) |
| 42 | label = "%s(%s)" % (n.name, str(count)) |
| 43 | # 根节点 |
| 44 | g.node(name=n.name, label=label, style='filled', target="_parent", href="https://leetcode-cn.com/tag/"+slug, |
| 45 | fontsize='14', |
| 46 | fillcolor="orangered", color='lightgrey', fontcolor="white", fontname="Microsoft YaHei", shape='box') |
| 47 | else: |
| 48 | # 普通模块节点 |
| 49 | label = "%s(%s)" % (n.name, str(len(n.problems))) |
| 50 | g.node(name=n.name, label=label, style='filled', fillcolor="lightslategray", color='lightgrey', |
| 51 | fontsize='12', |
| 52 | fontcolor="white", fontname="Microsoft YaHei", shape='box') |
| 53 | g.edge(n.parent, n.name, color=theme.color_arrow) |
| 54 | |
| 55 | # add problem |
| 56 | last = "" |
| 57 | for p in n.problems: |
| 58 | title = leet.get_title(p.id) |
| 59 | level = leet.get_level(p.id) |
| 60 | problem = leet.get_problem(p.id) |
| 61 | idstr = str(p.id) |
| 62 | if title == None: |
| 63 | continue |
| 64 | title = idstr+". "+title |
| 65 | color = "lightgrey" |
| 66 | |
| 67 | if level == "Easy": |
| 68 | color = "greenyellow" |
| 69 | elif level == "Medium": |
| 70 | color = "orange" |
| 71 | elif level == "Hard": |
| 72 | color = "red" |
| 73 | else: |
| 74 | print("unknown level:", level) |
| 75 | continue |
| 76 | slug = problem['data']['question']['questionTitleSlug'] |
| 77 | |
| 78 | # 题目节点 |
| 79 | g.node(name=idstr, label=title, target="_parent", href="https://leetcode-cn.com/problems/"+slug, |
| 80 | color=color, fontname="Microsoft YaHei", fontsize='12', shape='box') |
| 81 | |
| 82 | if len(last) > 0: |
| 83 | g.edge(last, idstr, color=theme.color_arrow) |
| 84 | else: |
| 85 | g.edge(n.name, idstr, color=theme.color_arrow) |
| 86 | last = idstr |
| 87 | |
| 88 | g.format = 'svg' |
| 89 | g.render(filename=util.get_images(out_name)) |
| 90 | os.remove(util.get_images(out_name)) |
no test coverage detected