def co_search(add_info, update_bci_key, former_bci_key, now_ts): uid_list = add_info.keys() evaluate_history_results = es_user_portrait.mget(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE,body={'ids':uid_list})['docs'] iter_count = 0 bulk_action = [] for uid in uid_list: item = evaluate_history_results[iter_count] if item['found']: user_history_item = item['_source'] #更新新的字段 user_history_item.update(add_info[uid]) user_history_item['bci_day_change'] = user_history_item[update_bci_key] - user_history_item.get(former_bci_key, 0) user_history_item['bci_week_change'] = user_history_item[update_bci_key] - user_history_item.get('bci_week_ave', 0) user_history_item['bci_month_change'] = user_history_item[update_bci_key] - user_history_item.get('bci_month_ave', 0) user_history_item['bci_week_ave'], user_history_item['bci_week_var'], user_history_item['bci_week_sum'] = compute_week(user_history_item, now_ts) user_history_item['bci_month_ave'], user_history_item['bci_month_var'], user_history_item['bci_month_sum'] = compute_month(user_history_item, now_ts) if user_history_item[update_bci_key] < LOW_INFLUENCE_THRESHOULD: user_history_item['low_number'] += 1 else: user_history_item['low_number'] = 0 else: user_history_item = dict() user_history_item.update(add_info[uid]) user_history_item["uid"] = uid user_history_item.update(add_info[uid]) user_history_item['bci_day_change'] = user_history_item[update_bci_key] user_history_item['bci_week_change'] = user_history_item[update_bci_key] user_history_item['bci_month_change'] = user_history_item[update_bci_key] user_history_item['bci_week_ave'], user_history_item['bci_week_var'], user_history_item['bci_week_sum'] = compute_week(user_history_item, now_ts) user_history_item['bci_month_ave'], user_history_item['bci_month_var'], user_history_item['bci_month_sum'] = compute_month(user_history_item, now_ts) if user_history_item[update_bci_key] < LOW_INFLUENCE_THRESHOULD: user_history_item['low_number'] = 1 iter_count += 1 try: user_history_item.pop(del_bci_key) except: pass action = {'index':{'_id': uid}} bulk_action.extend([action, user_history_item]) if bulk_action: es_cluster.bulk(bulk_action, index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE,timeout=600) print iter_count
def get_evaluate_trend(): #get uid list uid_list = get_uid_list() #save influence trend es result f = open('/home/user_portrait_0320/revised_user_portrait/user_portrait/user_portrait/attribute/sensitive_trend.txt', 'w') for uid in uid_list: #try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE, id=uid)['_source'] #except: # influence_history = {} if influence_history: f.write('%s\n' % json.dumps(influence_history)) f.close()
def co_search(add_info, update_bci_key, former_bci_key, now_ts): uid_list = add_info.keys() evaluate_history_results = es_user_portrait.mget(index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE,body={'ids':uid_list})['docs'] iter_count = 0 bulk_action = [] for uid in uid_list: item = evaluate_history_results[iter_count] if item['found']: user_history_item = item['_source'] #更新新的字段 user_history_item.update(add_info[uid]) user_history_item['sensitive_day_change'] = user_history_item[update_bci_key] - user_history_item.get(former_bci_key, 0) user_history_item['sensitive_week_change'] = user_history_item[update_bci_key] - user_history_item.get('sensitive_week_ave', 0) user_history_item['sensitive_month_change'] = user_history_item[update_bci_key] - user_history_item.get('sensitive_month_ave', 0) user_history_item['sensitive_week_ave'], user_history_item['sensitive_week_var'], user_history_item['sensitive_week_sum'] = compute_week(user_history_item, now_ts) user_history_item['sensitive_month_ave'], user_history_item['sensitive_month_var'], user_history_item['sensitive_month_sum'] = compute_month(user_history_item, now_ts) else: user_history_item = dict() user_history_item.update(add_info[uid]) user_history_item["uid"] = uid user_history_item.update(add_info[uid]) user_history_item['sensitive_day_change'] = user_history_item[update_bci_key] user_history_item['sensitive_week_change'] = user_history_item[update_bci_key] user_history_item['sensitive_month_change'] = user_history_item[update_bci_key] user_history_item['sensitive_week_ave'], user_history_item['sensitive_week_var'], user_history_item['sensitive_week_sum'] = compute_week(user_history_item, now_ts) user_history_item['sensitive_month_ave'], user_history_item['sensitive_month_var'], user_history_item['sensitive_month_sum'] = compute_month(user_history_item, now_ts) iter_count += 1 try: user_history_item.pop(del_bci_key) except: pass action = {'index':{'_id': uid}} bulk_action.extend([action, user_history_item]) if bulk_action: es_cluster.bulk(bulk_action, index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE,timeout=600) print iter_count
def get_evaluate_trend(): #get uid list uid_list = get_uid_list() #save influence trend es result f = open( '/home/user_portrait_0320/revised_user_portrait/user_portrait/user_portrait/attribute/sensitive_trend.txt', 'w') for uid in uid_list: #try: influence_history = ES_COPY_USER_PORTRAIT.get( index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE, id=uid)['_source'] #except: # influence_history = {} if influence_history: f.write('%s\n' % json.dumps(influence_history)) f.close()