Beispiel #1
0
    def port_tradegood_iter2price_dict(cls, server_codename, port_tradegood_iter):
        port_tradegood_set = set(port_tradegood_iter)

        port_codenames = smap(ig(0), port_tradegood_set)
        tradegood_codenames = smap(ig(1), port_tradegood_set)

        prices_latest = MarketpriceDoc.ports_tradegoods2price_list_latest(server_codename, port_codenames, tradegood_codenames)
        # raise Exception({"prices_latest":prices_latest})

        price_dict = cls.prices2price_dict(prices_latest)
        return price_dict
Beispiel #2
0
    def entity_lang2response_block(cls, entity, lang):
        entity_type = FoxylibEntity.entity2type(entity)
        codename = FoxylibEntity.entity2value(entity)

        from henrique.main.skill.tradegood.tradegood_port.tradegood_port_response import TradegoodPortResponse
        from henrique.main.skill.tradegood.tradegood_tradegood.tradegood_tradegood_response import TradegoodTradegoodResponse
        from henrique.main.skill.tradegood.tradegood_culture.tradegood_culture_response import TradegoodCultureResponse

        h_type2func = {
            PortEntity.entity_type():
            partial(TradegoodPortResponse.codename_lang2text, lang=lang),
            TradegoodEntity.entity_type():
            partial(TradegoodTradegoodResponse.codename_lang2text, lang=lang),
            CultureEntity.entity_type():
            partial(TradegoodCultureResponse.codename_lang2text, lang=lang),
        }

        assert_equals(
            set(h_type2func.keys()),
            smap(lambda c: c.entity_type(), cls.target_entity_classes()))

        codename2response = h_type2func.get(entity_type)
        if not codename2response:
            raise NotImplementedError(
                "Invalid entity_type: {}".format(entity_type))

        text_out = codename2response(codename)
        return Rowsblock.text2norm(text_out)
Beispiel #3
0
    def test_01(self):
        ports = Port.tradegood2ports("Dashima")

        hyp = smap(Port.port2codename, ports)
        ref = {'Hanyang', 'Busan', 'Pohang'}

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Beispiel #4
0
    def test_03(self):
        hyp = smap(str, ClassTool.class2child_classes(A))
        ref = {
            "<class 'foxylib.tools.native.clazz.tests.test_class_tool.A.B'>",
            "<class 'foxylib.tools.native.clazz.tests.test_class_tool.A.B.C'>"
        }

        # pprint(hyp)
        self.assertEqual(hyp, ref)
Beispiel #5
0
        def subtest(loop):
            self.assertFalse(loop.is_closed())

            coros = [cls.countdown_async("A", 3),
                     cls.countdown_async("B", 2),
                     ]
            # tasks_done, tasks_pending = loop.run_until_complete(asyncio.wait(coros))
            tasks_done, tasks_pending = loop.run_until_complete(asyncio.wait(coros, loop=loop))
            print((tasks_done, tasks_pending), file=sys.stderr)
            self.assertEqual(smap(lambda task:task.result(), tasks_done), {"A","B"}) # order not guaranteed
Beispiel #6
0
        def port2is_resistant(port):
            if not tgt:
                return False

            products = Product.port2products(Port.port2codename(port))
            tgt_codenames_port = smap(Product.product2tradegoodtype, products)

            logger.debug({
                "tgt": tgt,
                "tgt_codenames_port": tgt_codenames_port
            })
            return Tradegoodtype.tradegoodtype2codename(
                tgt) in tgt_codenames_port
Beispiel #7
0
    def _json2escaped(cls, j):
        if not j:
            return j

        if isinstance(j, (list, )):
            return lmap(cls._json2escaped, j)

        if isinstance(j, (tuple, )):
            return tmap(cls._json2escaped, j)

        if isinstance(j, (set, )):
            return smap(cls._json2escaped, j)

        if isinstance(j, (dict, )):
            return {k: cls._json2escaped(v) for k, v in j.items()}

        if isinstance(j, (str, )):
            return escape(j)

        return j
Beispiel #8
0
    def entity2response_block(
        cls,
        packet,
        entity,
    ):
        chatroom = Chatroom.codename2chatroom(
            KhalaPacket.packet2chatroom(packet))
        locale = Chatroom.chatroom2locale(chatroom)
        lang = LocaleTool.locale2lang(locale)

        entity_type = FoxylibEntity.entity2type(entity)

        h_type2func = {
            PortEntity.entity_type():
            partial(PortSkill.entity_lang2response_block, lang=lang),
            TradegoodEntity.entity_type():
            partial(TradegoodSkill.entity_lang2response_block, lang=lang),
            CultureEntity.entity_type():
            partial(CultureSkill.entity_lang2response_block, lang=lang),
            ChatroomuserEntity.entity_type():
            partial(
                WhoSkill.entity2response_block,
                packet=packet,
            ),
        }

        assert_equals(
            set(h_type2func.keys()),
            smap(lambda c: c.entity_type(), cls.target_entity_classes()))

        entity2response = h_type2func.get(entity_type)
        if not entity2response:
            raise NotImplementedError(
                "Invalid entity_type: {}".format(entity_type))

        return entity2response(entity)
Beispiel #9
0
    def str2startindexes_endindexes(cls, str_in):
        span_list = cls.str2token_span_list(str_in)
        startindexes = smap(ig(0), span_list)
        endindexes = smap(ig(1), span_list)

        return startindexes, endindexes