Beispiel #1
0
    def port_tradegood_lists2blocks(cls, port_tradegood_list, price_dict, lang,
                                    groupby_parameter_type):
        logger = HenriqueLogger.func_level2logger(
            cls.port_tradegood_lists2blocks, logging.DEBUG)
        logger.debug({"port_tradegood_list": port_tradegood_list})

        if groupby_parameter_type == PriceSkillParameter.Type.PORTLIKE:
            from henrique.main.skill.price.by_port.price_by_port import PriceByPort

            blocks = [
                PriceByPort.port2text(port_codename, lmap(ig(1), l),
                                      price_dict, lang) for port_codename, l in
                gb_tree_global(port_tradegood_list, [ig(0)])
            ]
            return blocks

        if groupby_parameter_type == PriceSkillParameter.Type.TRADEGOOD:
            from henrique.main.skill.price.by_tradegood.price_by_tradegood import PriceByTradegood

            blocks = [
                PriceByTradegood.tradegood2text(tg_codename, lmap(ig(0), l),
                                                price_dict, lang) for
                tg_codename, l in gb_tree_global(port_tradegood_list, [ig(1)])
            ]
            return blocks

        raise Exception(groupby_parameter_type)
Beispiel #2
0
    def table2beamed(cls, table, i_pivot, beam):
        ij_list = list(cls._str_ll_i2ij_iter(table, i_pivot, beam))
        i2j_list = gb_tree_global(ij_list, [
            ig(0),
        ],
                                  leaf_func=lambda l: lmap(ig(1), l))

        table_filtered = lchain(
            [table[0]],
            [cls._i2j_list2l_out(table[i], j_list) for i, j_list in i2j_list],
        )
        return table_filtered
Beispiel #3
0
    def test_02(self):
        l = [
            "asdf", "ade", "abe", "bde", "bed", "bdgef", "bdwege", "bedfwef",
            "bdasdf", "csdfe", "defdad", "cdsfe"
        ]

        hyp = gb_tree_global(l, [ig(0), ig(1), ig(2)],
                             leaf_func=lambda _l: lmap(lambda s: s[3:], _l))
        ref = [('a', [('s', [('d', ['f'])]), ('d', [('e', [''])]),
                      ('b', [('e', [''])])]),
               ('b', [('d', [('e', ['']), ('g', ['ef']), ('w', ['ege']),
                             ('a', ['sdf'])]), ('e', [('d', ['', 'fwef'])])]),
               ('c', [('s', [('d', ['fe'])]), ('d', [('s', ['fe'])])]),
               ('d', [('e', [('f', ['dad'])])])]

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Beispiel #4
0
    def dict_codename2products(cls):
        data_ll = PortGooglesheets.sheetname2data_ll(cls.NAME)

        port2row_list = gb_tree_global(data_ll[1:], [ig(0)])

        def row2product(row):
            port, tradegood = row[0], row[1]
            price = row[2] if len(row) >= 3 else None
            raw = {Product.Field.PORT: port,
                   Product.Field.TRADEGOOD: tradegood,
                   Product.Field.PRICE: price,
                   }
            product = DictTool.filter(lambda k,v:v, raw)
            return product

        h = {port: lmap(row2product, row_list)
             for port, row_list in port2row_list}

        return h
Beispiel #5
0
    def test_01(self):
        l = [
            "asdf", "ade", "abe", "bde", "bed", "bdgef", "bdwege", "bedfwef",
            "bdasdf", "csdfe", "defdad", "cdsfe"
        ]

        hyp = gb_tree_global(l, [ig(0), ig(1), ig(2)])
        ref = [('a', [
            ('s', [('d', ['asdf'])]),
            ('d', [('e', ['ade'])]),
            ('b', [('e', ['abe'])]),
        ]),
               ('b', [('d', [
                   ('e', ['bde']),
                   ('g', ['bdgef']),
                   ('w', ['bdwege']),
                   ('a', ['bdasdf']),
               ]), ('e', [('d', ['bed', 'bedfwef'])])]),
               ('c', [('s', [('d', ['csdfe'])]), ('d', [('s', ['cdsfe'])])]),
               ('d', [('e', [('f', ['defdad'])])])]

        # pprint(hyp)
        self.assertEqual(hyp, ref)