def jqi_list_pair2must_mustnot(cls, jqi_list_must, jqi_list_must_not): l = [ cls.jqi_list2must(jqi_list_must), cls.jqi_list2must_not(jqi_list_must_not), ] return merge_dicts(l, vwrite=f_vwrite2f_hvwrite(vwrite_no_duplicate_key))
def _lang2dict_alias2server(cls, lang): langs_recognizable = HenriqueLocale.lang2langs_recognizable(lang) h = merge_dicts([{alias: server} for server in cls.list_all() for alias in cls.server_langs2aliases(server, langs_recognizable)], vwrite=vwrite_no_duplicate_key) return h
def _dict_chatroom2server(cls): from henrique.main.singleton.config.googlesheets.henrique_config_googlesheets import HenriqueConfigGooglesheets config_list = HenriqueConfigGooglesheets.config_list() h = merge_dicts([{config[cls.Field.CHATROOM]: config[cls.Field.SERVER]} for config in config_list], vwrite=vwrite_no_duplicate_key) return h
def _dict_codename2server(cls): from henrique.main.document.server.googlesheets.server_googlesheets import ServerGooglesheets server_list = ServerGooglesheets.server_list_all() assert_is_not_none(server_list) h_codename2server = merge_dicts([{cls.server2codename(server): server} for server in server_list]) return h_codename2server
def field_values_boost2jqi_terms(cls, field, value_list, boost): l = [ cls.field_values2jqi_terms(field, value_list), cls.boost2jqi_terms(boost), ] return merge_dicts(l, vwrite=f_vwrite2f_hvwrite(vwrite_no_duplicate_key))
def codenames2chatrooms(cls, codenames): logger = KhalaLogger.func_level2logger(cls.codenames2chatrooms, logging.DEBUG) collection = ChatroomCollection.collection() if codenames is not None: cursor = collection.find({cls.Field.CODENAME: {"$in": codenames}}) else: cursor = collection.find() # raise Exception({"collection":collection, "codenames":codenames, # '{cls.Field.CODENAME: {"$in": codenames}}':{cls.Field.CODENAME: {"$in": codenames}} # }) h_codename2doc = merge_dicts([{ Chatroom.chatroom2codename(doc): doc } for doc in map(MongoDBTool.bson2json, cursor)], vwrite=vwrite_no_duplicate_key) doc_list = lmap(h_codename2doc.get, codenames) logger.debug({#"h_codename2doc":h_codename2doc, #"codenames":codenames, "doc_list":doc_list, }) assert_equal(len(codenames), len(doc_list)) return doc_list
def dict_codename2tradegoodtype(cls): data_ll = TradegoodtypeGooglesheets.sheetname2data_ll(cls.NAME) h = merge_dicts([{ row[0]: row[1] } for row in data_ll[1:] if len(row) > 1], vwrite=vwrite_no_duplicate_key) return h
def upserted2json(upserted_in): _id = MongoDBTool.Field._ID upserted_out = merge_dicts( [upserted_in, { _id: str(upserted_in[_id]) }], vwrite=DictTool.VWrite.overwrite) return upserted_out
def dict_codename2comments(cls): data_ll = ChatroomuserGooglesheets.sheetname2data_ll(cls.NAME) h = merge_dicts([{ row[0]: row[1:] } for row in data_ll[1:]], vwrite=vwrite_no_duplicate_key) return h
def _dict_id2codename(cls, ): doc_list = cls.doc_list_all() h = merge_dicts([{ MongoDBTool.doc2id(doc): cls.doc2key(doc) } for doc in doc_list], vwrite=vwrite_no_duplicate_key) return h
def dict_codename2aliases(cls): data_ll = CultureGooglesheets.sheetname2data_ll(cls.NAME) h = merge_dicts([{ row[0]: row[1:] } for row in data_ll[1:]], vwrite=vwrite_no_duplicate_key) return h
def dict_id2codename(cls): with HenriquePostgres.cursor() as cursor: sql = SQL("SELECT id, name FROM {}").format(Identifier(cls.NAME), ) cursor.execute(sql) h = merge_dicts([{id: codename} for id, codename in PostgresTool.fetch_iter(cursor)], vwrite=vwrite_no_duplicate_key) return h
def row2chatroom(row): chatroom = merge_dicts([{col_top: str2strip(row[i])} for i, col_top in enumerate(top_row)], vwrite=vwrite_no_duplicate_key) if not Chatroom.chatroom2codename(chatroom): return None return chatroom
def creds_gdoc_id2metadata(cls, creds, gdoc_id, options=None, ): str_SCOPE = "drive.readonly" service = build('drive', 'v3', http=creds.authorize(Http())) h = merge_dicts([{"fileId": gdoc_id, }, options, ]) b = service.files().get(**h).execute() return b
def dict_codename2chatroomuser(cls): chatroomuser_list_all = cls.chatroomuser_list_all() h = merge_dicts( [{ Chatroomuser.chatroomuser2codename(chatroomuser): chatroomuser } for chatroomuser in chatroomuser_list_all], vwrite=DictTool.VWrite.f_vwrite2f_hvwrite(vwrite_no_duplicate_key), ) return h
def dict_codename2tradegoodtype(cls): tradegoodtype_list_all = cls.tradegoodtype_list_all() h = merge_dicts( [{ Tradegoodtype.tradegoodtype2codename(tgt): tgt } for tgt in tradegoodtype_list_all], vwrite=DictTool.VWrite.f_vwrite2f_hvwrite(vwrite_no_duplicate_key), ) return h
def _dict_uuid2row(cls, ): row_list = list(cls._row_iter()) h = merge_dicts([{ (cls.row2uuid(row)): row } for row in row_list], vwrite=vwrite_no_duplicate_key) return h
def h_char2typable(cls): h = merge_dicts([ {c: "'" for c in cls.string_singlequote()}, {c: '"' for c in cls.string_doublequote()}, ], vwrite=vwrite_no_duplicate_key) return h
def jq_functions2j_function_score(cls, jq, function_list, options): h = merge_dicts([ jq, { "functions": function_list }, options, ]) return {"function_score": h}
def dict_codename2culture(cls): culture_list = cls.culture_list_all() assert_is_not_none(culture_list) h_codename2culture = merge_dicts([{ Culture.culture2codename(culture): culture } for culture in culture_list]) return h_codename2culture
def _entity_1day2multiday(cls, j_entity_1day): v_1day = FoxylibEntity.entity2value(j_entity_1day) j_entity_multiday = merge_dicts( [j_entity_1day, { FoxylibEntity.Field.VALUE: (v_1day, ) }], vwrite=vwrite_overwrite) return j_entity_multiday
def ids2dict_id2doc(cls, collection, ids): query = cls.ids2query(ids) docs = lmap(cls.bson2json, collection.find(query)) h_id2doc = merge_dicts([{ cls.doc2id(doc): doc } for doc in docs], vwrite=vwrite_no_duplicate_key) return h_id2doc
def dict_lang2text(cls, ): from henrique.main.skill.help.help_skill import HelpSkill data_ll = HelpSkill.sheetname2data_ll(HelpSkill.Sheetname.CULTURE) h_lang2text = merge_dicts([{ row[0]: row[1] } for row in data_ll[1:]], vwrite=vwrite_no_duplicate_key) return h_lang2text
def dict_lang2text(cls, ): from henrique.main.skill.help.help_skill import HelpSkill data_ll = HelpSkill.sheetname2data_ll(HelpSkill.Sheetname.PORT) h_lang2text = merge_dicts([{ row[0]: row[1] } for row in data_ll[1:]], vwrite=vwrite_no_duplicate_key) # raise Exception({"h_lang2text":h_lang2text}) return h_lang2text
def name_en_list2j_port_list(name_en_list): norm = str2lower h = merge_dicts([{ norm(PortDoc.doc_lang2name(doc, "en")): doc } for doc in PortDoc.doc_list_all()], vwrite=vwrite_no_duplicate_key) doc_list = [h.get(norm(x)) for x in name_en_list] return doc_list
def _dict_norm2index(self): cls = self.__class__ token_list = self.token_list() h_out = merge_dicts( [{ cls.Token.token2norm(token): cls.Token.token2index(token) } for token in token_list], vwrite=DictTool.VWrite.skip_if_existing) return h_out
def dict_norm2indexes(self): cls = self.__class__ token_list = self.token_list() h = merge_dicts([{ cls.Token.token2norm(token): {cls.Token.token2index(token)} } for token in token_list], vwrite=DictTool.VWrite.f_vresolve2f_vwrite( DictTool.VResolve.union)) return h
def str_ll2h_list(cls, str_ll): assert_greater_equal(len(str_ll), 1) m = iter2singleton(map(len, str_ll)) key_list = str_ll[0] h_list = [ merge_dicts([{ key_list[j]: l[j] } for j in range(m)], vwrite=vwrite_no_duplicate_key) for l in str_ll[1:] ] return h_list
def prices2price_dict(cls, prices): price_list = list(prices) def price2key(price): # raise Exception({"price":price}) port_codename = MarketpriceDoc.price2port(price) tradegood_codename = MarketpriceDoc.price2tradegood(price) return port_codename, tradegood_codename price_dict = merge_dicts([{price2key(price): price} for price in price_list], vwrite=vwrite_no_duplicate_key) return price_dict
def item2doc(item): port_codename = JsonTool.down(item, ["_id", cls.Field.PORT]) tradegood_codename = JsonTool.down(item, ["_id", cls.Field.TRADEGOOD]) price = merge_dicts([DictTool.keys2filtered(item, fields_others, ), {cls.Field.PORT: port_codename, cls.Field.TRADEGOOD: tradegood_codename, }, ], vwrite=vwrite_no_duplicate_key ) return price