예제 #1
0
def save_key_edges_results(hash_tag, weak_link, future_edge):

    pinyin_hash_tag = pinyin.get(hash_tag, format="strip", delimiter="_")

    key_edges_es_mappings()

    index_name = 'key_edges_results'
    id = pinyin_hash_tag
    index_type = "edge"

    item = {}

    item['hash_tag'] = hash_tag
    item['retweet_rank'] = weak_link
    item['negtive_rank'] = future_edge

    try:
        item_exist = key_es.get(index=index_name, doc_type=index_type,
                                id=id)['_source']
        key_es.update(index=index_name,
                      doc_type=index_type,
                      id=id,
                      body={'doc': item})
    except Exception, e:
        # raise e
        key_es.index(index=index_name, doc_type=index_type, id=id, body=item)
예제 #2
0
def save_key_mblogs_results(hash_tag, retweet_rank, negtive_rank):

    pinyin_hash_tag = pinyin.get(hash_tag, format="strip", delimiter="_")

    key_mblogs_es_mappings()

    index_name = 'key_mblogs_results'
    id = pinyin_hash_tag
    index_type = "mblog"

    item = {}

    item['hash_tag'] = hash_tag
    item['retweet_rank'] = json.dumps(retweet_rank)
    item['negtive_rank'] = json.dumps(negtive_rank)

    try:
        item_exist = key_es.get(index=index_name, doc_type=index_type,
                                id=id)['_source']
        key_es.update(index=index_name,
                      doc_type=index_type,
                      id=id,
                      body={'doc': item})
    except Exception, e:
        # raise e
        key_es.index(index=index_name, doc_type=index_type, id=id, body=item)
예제 #3
0
def save_key_nodes_results(hash_tag, fans_rank, negtive_rank, pagerank_rank,
                           sensitive_rank):
    print 'pinyin'
    print 'pinyin:', pinyin.get(hash_tag, format="strip", delimiter="_")
    pinyin_hash_tag = pinyin.get(hash_tag, format="strip", delimiter="_")

    key_nodes_es_mappings()

    index_name = 'key_nodes_results'
    id = pinyin_hash_tag
    index_type = "node"
    item = {}
    #id_time = time.ctime()
    item['hash_tag'] = hash_tag
    item['fans_rank'] = json.dumps(fans_rank)
    item['negtive_rank'] = str(negtive_rank)
    item['pagerank_rank'] = json.dumps(pagerank_rank)
    item['sensitive_rank'] = json.dumps(sensitive_rank)
    try:
        item_exist = key_es.get(index=index_name, doc_type=index_type,
                                id=id)['_source']
        key_es.update(index=index_name,
                      doc_type=index_type,
                      id=id,
                      body={'doc': item})
    except Exception, e:
        # raise e
        key_es.index(index=index_name, doc_type=index_type, id=id, body=item)
예제 #4
0
def save_info_max_results(hash_tag, info_max):

    pinyin_hash_tag = pinyin.get(hash_tag, format="strip", delimiter="_")

    info_max_es_mappings()

    index_name = 'info_max_results'
    id = pinyin_hash_tag
    index_type = "info_max"

    item = {}

    item['hash_tag'] = hash_tag
    item['info_max'] = info_max

    try:
        item_exist = key_es.get(index=index_name, doc_type=index_type,
                                id=id)['_source']
        key_es.update(index=index_name,
                      doc_type=index_type,
                      id=id,
                      body={'doc': item})
    except Exception, e:
        # raise e
        key_es.index(index=index_name, doc_type=index_type, id=id, body=item)
예제 #5
0
def save_dg_pr_results(sorted_uids, es_num, flag):
    index_name = "pagerank_results"
    index_type = "pagerank"
    bulk_action = []
    count = 0
    for uid, rank in sorted_uids:
        if (uid == 'global'):
            continue
        count += 1
        user_results = {}
        user_results['uid'] = uid
        user_results[flag + '_' + str(es_num)] = rank
        user_results['rank_' + flag + '_' + str(es_num)] = count  #rank
        if es_num == 0:
            action = {'index': {'_id': uid}}
            bulk_action.extend([action, user_results])
        else:
            try:
                item_exist = key_es.get(index=index_name,
                                        doc_type=index_type,
                                        id=uid)['_source']
                action = {'update': {'_id': uid}}
                try:
                    pr_last = item_exist[flag + '_' + str(es_num - 1)]
                    rank_last = item_exist['rank_' + flag + '_' +
                                           str(es_num - 1)]
                except:
                    pr_last = 0
                    rank_last = 101
                user_results[flag + '_diff_' + str(es_num)] = rank - pr_last
                user_results['rank_' + flag + '_diff_' +
                             str(es_num)] = abs(count - rank_last)
                bulk_action.extend([action, {'doc': user_results}])
            except:
                action = {'index': {'_id': uid}}
                pr_last = 0
                rank_last = 101
                user_results[flag + '_diff_' + str(es_num)] = rank - pr_last
                user_results['rank_' + flag + '_diff_' +
                             str(es_num)] = abs(count - rank_last)
                bulk_action.extend([action, user_results])

    #print bulk_action
    key_es.bulk(bulk_action, index=index_name, doc_type=index_type)