示例#1
0
文件: app.py 项目: orotau/pangakupu
    def board(self, koru):

        children = pk.get_children(koru, koru[8])
        groups = difficulty_level.group_children(children)        
        pai_count = len(groups[0])
        tino_pai_count = len(groups[0]) + len(groups[1])
        tino_pai_rawa_atu_count = len(groups[0]) + len(groups[1]) + len(groups[2])

        # allow template to hide border between digraphs
        digraph_starts = []
        # top row (these 2 are mutually exclusive)
        if koru[0] + koru[1] in pū.digraphs:
            digraph_starts.append(0)
        if koru[1] + koru[2] in pū.digraphs:
            digraph_starts.append(1)

        # bottom row (these 2 are mutually exclusive)
        if koru[6] + koru[5] in pū.digraphs:
            digraph_starts.append(6)
        if koru[5] + koru[4] in pū.digraphs:
            digraph_starts.append(5)

        template_id = 'board'
        template = self.env.get_template(template_id + '.html')
        return template.render({"template_id": template_id,
                                "pai_count": pai_count,
                                "tino_pai_count": tino_pai_count,
                                "tino_pai_rawa_atu_count": tino_pai_rawa_atu_count,
                                "koru": koru,
                                "koru0": koru[0],
                                "koru1": koru[1],
                                "koru2": koru[2],
                                "koru3": koru[3],
                                "koru4": koru[4],
                                "koru5": koru[5],
                                "koru6": koru[6],
                                "koru7": koru[7],
                                "koru8": koru[8],
                                "digraph_starts": digraph_starts})
示例#2
0
文件: app.py 项目: orotau/pangakupu
    def boardchildren(self, koru):

        children = pk.get_children(koru, koru[8])
        groups = difficulty_level.group_children(children)        
        pai_count = len(groups[0])
        tino_pai_count = len(groups[0]) + len(groups[1])
        tino_pai_rawa_atu_count = len(groups[0]) + len(groups[1]) + len(groups[2])

        #for use with existing code
        children_count = tino_pai_rawa_atu_count

        # Sort
        children = sorted(children, key=mw.get_list_sort_key)

        # Group the children for display
        grouped_children = []
        if children_count <= 20:
            # one group
            grouped_children.append(children)
        elif children_count <= 60:
            # two groups
            if divmod(children_count, 2)[1] == 0:
                # even number
                group1_count = divmod(children_count, 2)[0]
                group2_count = group1_count
            elif divmod(children_count, 2)[1] == 1:
                # odd number
                group1_count = divmod(children_count, 2)[0] + 1
                group2_count = group1_count - 1
            grouped_children.append(children[:group1_count])
            grouped_children.append(children[-group2_count:])
        else:
            # three groups
            if divmod(children_count, 3)[1] == 0:
                # multiple of 3
                group1_count = divmod(children_count, 3)[0]
                group2_count = group1_count
                group3_count = group1_count
            elif divmod(children_count, 3)[1] == 1:
                # 1 left over (e.g. 61)
                group1_count = divmod(children_count, 3)[0] + 1
                group2_count = group1_count
                group3_count = group1_count - 2
            elif divmod(children_count, 3)[1] == 2:
                # 2 left over (e.g. 62)
                group1_count = divmod(children_count, 3)[0] + 1
                group2_count = group1_count
                group3_count = group1_count - 1
            grouped_children.append(children[:group1_count])
            grouped_children.append(children[group1_count:
                                             group1_count + group2_count])
            grouped_children.append(children[-group3_count:])

        # allow template to hide border between digraphs
        digraph_starts = []
        # top row (these 2 are mutually exclusive)
        if koru[0] + koru[1] in pū.digraphs:
            digraph_starts.append(0)
        if koru[1] + koru[2] in pū.digraphs:
            digraph_starts.append(1)

        # bottom row (these 2 are mutually exclusive)
        if koru[6] + koru[5] in pū.digraphs:
            digraph_starts.append(6)
        if koru[5] + koru[4] in pū.digraphs:
            digraph_starts.append(5)

        template_id = 'boardchildren'
        template = self.env.get_template(template_id + '.html')
        return template.render({"template_id": template_id,
                                "pai_count": pai_count,
                                "tino_pai_count": tino_pai_count,
                                "tino_pai_rawa_atu_count": tino_pai_rawa_atu_count,
                                "grouped_children": grouped_children,
                                "pai_words": [x[0] for x in groups[0]],
                                "koru": koru,
                                "koru0": koru[0],
                                "koru1": koru[1],
                                "koru2": koru[2],
                                "koru3": koru[3],
                                "koru4": koru[4],
                                "koru5": koru[5],
                                "koru6": koru[6],
                                "koru7": koru[7],
                                "koru8": koru[8],
                                "digraph_starts": digraph_starts})