| 10 | import platform_view |
| 11 | |
| 12 | class LeetcodeView(platform_view.PlatformView): |
| 13 | def __init__(self, leet): |
| 14 | self.leet = leet |
| 15 | self.m = None |
| 16 | self.slug = "leetcode" |
| 17 | |
| 18 | def check_finish(self, title): |
| 19 | return self.leet.check_finish(title) |
| 20 | |
| 21 | def get_problem(self, title): |
| 22 | return self.m.problem_map[title] |
| 23 | |
| 24 | def check_flask(self, title): |
| 25 | return self.leet.check_flask(title) |
| 26 | |
| 27 | def is_valid_title(self, title): |
| 28 | return title.isdigit() |
| 29 | |
| 30 | def post_process(self, path): |
| 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": |