예제 #1
0
    def tuple2pair(cls, t):
        logger = HenriqueLogger.func_level2logger(cls.tuple2pair, logging.DEBUG)

        def chatuser_uuid2channel_user(chatuser_uuid, alias=None):
            if not chatuser_uuid:
                return None

            row = ChatuserTable.uuid2row(chatuser_uuid)
            if not row:
                logger.debug({"chatuser_uuid":chatuser_uuid})
                return None

            channel_user = ChatuserTable.row2channel_user(row, alias=alias)
            return channel_user

        j_postgres = t[PortTradegoodStateTable.index_json()]
        sender_name = j_postgres.get("sender_name")

        created_at = DatetimeTool.fromisoformat(j_postgres["created_at"])

        port_name_en = PortTradegoodStateTable.tuple2port_name_en(t)
        port = cls.name_en2port(port_name_en)

        tradegood_name_en = PortTradegoodStateTable.tuple2tradegood_name_en(t)
        tradegood = cls.name_en2tradegood(tradegood_name_en)

        rate = PortTradegoodStateTable.tuple2rate(t)
        trend = PortTradegoodStateTable.tuple2trend(t)

        chatuser_uuid = PortTradegoodStateTable.tuple2chatuser_uuid(t)
        channel_user = chatuser_uuid2channel_user(chatuser_uuid, alias=sender_name)
        channel_user_code = ChannelUser.channel_user2codename(channel_user) if channel_user else None

        server_alias = str2lower(jdown(j_postgres, ["server", "name"]))
        # logger.debug({"server_alias":server_alias})

        server = Server.alias_lang2server(server_alias, "ko")
        assert_true(server,server_alias)

        marketprice = {MarketpriceDoc.Field.CREATED_AT: created_at,
                       MarketpriceDoc.Field.PORT: Port.port2codename(port),
                       MarketpriceDoc.Field.TRADEGOOD: Tradegood.tradegood2codename(tradegood),
                       MarketpriceDoc.Field.RATE: rate,
                       MarketpriceDoc.Field.TREND: trend,

                       MarketpriceDoc.Field.CHANNEL_USER: channel_user_code,
                       MarketpriceDoc.Field.SERVER: Server.server2codename(server),

                       }

        return marketprice, channel_user
예제 #2
0
    def lang2matcher(cls, lang):
        tg_list = Tradegood.list_all()
        langs_recognizable = HenriqueLocale.lang2langs_recognizable(lang)

        def tg2aliases(tg):
            for _lang in langs_recognizable:
                yield from Tradegood.tradegood_lang2aliases(tg, _lang)

        h_value2aliases = merge_dicts(
            [{
                Tradegood.tradegood2codename(tg): list(tg2aliases(tg))
            } for tg in tg_list],
            vwrite=vwrite_no_duplicate_key)

        config = {
            GazetteerMatcher.Config.Key.NORMALIZER:
            cls.text2norm,
            GazetteerMatcher.Config.Key.TEXTS2PATTERN:
            HenriqueEntity.texts2pattern_port_tradegood,
        }
        matcher = GazetteerMatcher(h_value2aliases, config)
        return matcher
예제 #3
0
 def dict_codename2tradegood(cls):
     tradegood_list_all = cls.tradegood_list_all()
     h = merge_dicts([{Tradegood.tradegood2codename(tradegood): tradegood} for tradegood in tradegood_list_all],
                     vwrite=DictTool.VWrite.f_vwrite2f_hvwrite(vwrite_no_duplicate_key),
                     )
     return h