def get_evaluate_rank(evaluate_ts, evaluate_value, evaluate_index): result = [] evaluate_index_key = evaluate_index + '_' + str(evaluate_ts) query_body = { 'query': { 'range': { evaluate_index_key: { 'gte': evaluate_value, 'lt': MAX_VALUE } } } } #get index_name, index_type index_infor_item = evaluate_index_dict[evaluate_index] index_name = index_infor_item[0] index_type = index_infor_item[1] evaluate_rank = ES_COPY_USER_PORTRAIT.count(index=index_name, doc_type=index_type, body=query_body) if evaluate_rank['_shards']['successful'] != 0: rank = evaluate_rank['count'] else: rank = '' return rank
def new_get_activeness_trend(uid, time_segment): results = {} try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE,\ id=uid)['_source'] except: activeness_history = {} if activeness_history: results = get_evaluate_trend(activeness_history, 'activeness') else: results = {} #deal results for situation---server power off new_time_list = [] new_count_list = [] new_results = {} now_time_ts = time.time() now_date_ts = datetime2ts(ts2datetime(now_time_ts)) for i in range(time_segment, 0, -1): iter_date_ts = now_date_ts - i * DAY try: date_count = results[iter_date_ts] except: date_count = 0 new_time_list.append(iter_date_ts) new_count_list.append(date_count) new_results = {'timeline': new_time_list, 'evaluate_index': new_count_list} return new_results
def new_get_influence_trend(uid, time_segment): results = {} try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE,\ id=uid)['_source'] print ES_COPY_USER_PORTRAIT, COPY_USER_PORTRAIT_INFLUENCE, COPY_USER_PORTRAIT_INFLUENCE_TYPE, uid print influence_history except: influence_history = {} if influence_history: results = get_evaluate_trend(influence_history, 'bci') else: results = {} print results #deal results for situation---server power off new_time_list = [] new_count_list = [] new_results = {} now_time_ts = time.time() now_date_ts = datetime2ts(ts2datetime(now_time_ts)) if RUN_TYPE == 0: now_date_ts = datetime2ts(RUN_TEST_TIME) for i in range(time_segment, 0, -1): iter_date_ts = now_date_ts - i * DAY try: date_count = results[iter_date_ts] except: date_count = 0 new_time_list.append(iter_date_ts) new_count_list.append(date_count) new_results = {'timeline': new_time_list, 'evaluate_index': new_count_list} return new_results
def new_get_activeness_trend(uid, time_segment): results = {} try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE,\ id=uid)['_source'] except: activeness_history = {} if activeness_history: results = get_evaluate_trend(activeness_history, 'activeness') else: results = {} #deal results for situation---server power off new_time_list = [] new_count_list = [] new_results = {} now_time_ts = time.time() now_date_ts = datetime2ts(ts2datetime(now_time_ts)) for i in range(time_segment, 0, -1): iter_date_ts = now_date_ts - i * DAY try: date_count = results[iter_date_ts] except: date_count = 0 new_time_list.append(iter_date_ts) new_count_list.append(date_count) new_results = {'timeline': new_time_list, 'evaluate_index': new_count_list} return new_results
def new_get_activeness_trend(uid): results = {} try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE,\ id=uid)['_source'] except: activeness_history = {} if activeness_history: results = get_evaluate_trend(activeness_history, 'activeness') else: results = {} return results
def new_get_influence_trend(uid): results = {} try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE,\ id=uid)['_source'] except: influence_history = {} if influence_history: results = get_evaluate_trend(influence_history, 'bci') else: results = {} return results
def new_get_activeness_trend(uid): results = {} try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE,\ id=uid)['_source'] except: activeness_history = {} if activeness_history: results = get_evaluate_trend(activeness_history, 'activeness') else: results = {} return results
def new_get_influence_trend(uid): results = {} try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE,\ id=uid)['_source'] except: influence_history = {} if influence_history: results = get_evaluate_trend(influence_history, 'bci') else: results = {} return results
def get_influence_week_ave_rank(week_ave): evaluate_index_key = 'bci_week_ave' query_body = { 'query':{ 'range':{ evaluate_index_key: { 'gte': week_ave, 'lt': MAX_VALUE } } } } index_name = COPY_USER_PORTRAIT_INFLUENCE index_type = COPY_USER_PORTRAIT_INFLUENCE_TYPE week_ave_rank = ES_COPY_USER_PORTRAIT.count(index=index_name, doc_type=index_type,\ body=query_body) if week_ave_rank['_shards']['successful'] != 0: rank = week_ave_rank['count'] else: rank = '' return rank
def get_influence_week_ave_rank(week_ave): evaluate_index_key = 'bci_week_ave' query_body = { 'query':{ 'range':{ evaluate_index_key: { 'gte': week_ave, 'lt': MAX_VALUE } } } } index_name = COPY_USER_PORTRAIT_INFLUENCE index_type = COPY_USER_PORTRAIT_INFLUENCE_TYPE week_ave_rank = ES_COPY_USER_PORTRAIT.count(index=index_name, doc_type=index_type,\ body=query_body) if week_ave_rank['_shards']['successful'] != 0: rank = week_ave_rank['count'] else: rank = '' return rank
def get_evaluate_rank(evaluate_ts, evaluate_value, evaluate_index): result = [] evaluate_index_key = evaluate_index + '_' + str(evaluate_ts) query_body = { 'query':{ 'range':{ evaluate_index_key:{ 'gte': evaluate_value, 'lt': MAX_VALUE } } } } #get index_name, index_type index_infor_item = evaluate_index_dict[evaluate_index] index_name = index_infor_item[0] index_type = index_infor_item[1] evaluate_rank = ES_COPY_USER_PORTRAIT.count(index=index_name, doc_type=index_type, body=query_body) if evaluate_rank['_shards']['successful'] != 0: rank = evaluate_rank['count'] else: rank = '' return rank
def new_get_user_evaluate(uid): results = {} #get all count in user_portrait query_body = { 'query':{ 'match_all': {} } } all_count_results = es_user_portrait.count(index=portrait_index_name, doc_type=portrait_index_type, body=query_body) if all_count_results['_shards']['successful'] != 0: all_count = all_count_results['count'] else: all_count = '' #get influence from es influence history try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE, \ id = uid)['_source'] except: influence_history = [] #get max value/min value/week ave value if influence_history: week_ave = influence_history['bci_week_ave'] week_ave_rank = get_influence_week_ave_rank(week_ave) influence_item = [week_ave, week_ave_rank] influence_max_min_now_list = get_evaluate_max_min_now(influence_history, 'bci') influence_max_min_now_list.append(all_count) influence_item.extend(influence_max_min_now_list[2:]) results['influence'] = influence_max_min_now_list else: results['influence'] = ['', '', '', '', all_count] #get importance from es importance history try: importance_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_IMPORTANCE, doc_type=COPY_USER_PORTRAIT_IMPORTANCE_TYPE, \ id = uid)['_source'] except: importance_history = [] #get max value/min value/now value if importance_history: importance_max_min_now_list = get_evaluate_max_min_now(importance_history, 'importance') importance_max_min_now_list.append(all_count) results['importance'] = importance_max_min_now_list else: results['importance'] = ['', '', '', '', all_count] #get activeness from es activeness history try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE ,\ id = uid)['_source'] except: activeness_history = [] #get max value/min value/ now value if activeness_history: activeness_max_min_now_list = get_evaluate_max_min_now(activeness_history, 'activeness') activeness_max_min_now_list.append(all_count) results['activeness'] = activeness_max_min_now_list else: results['activeness'] = ['', '', '', '', all_count] #get sensitive from es sensitive history try: sensitive_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE, \ id = uid)['_source'] except: sensitive_history = [] #get max value/min value/ now value if sensitive_history: sensitive_max_min_now_list = get_evaluate_max_min_now(sensitive_history, 'sensitive') sensitive_max_min_now_list.append(all_count) results['sensitive'] = sensitive_max_min_now_list else: results['sensitive'] = ['', '', '', '', all_count] return results
def new_get_user_evaluate(uid): results = {} #get all count in user_portrait query_body = { 'query':{ 'match_all': {} } } all_count_results = es_user_portrait.count(index=portrait_index_name, doc_type=portrait_index_type, body=query_body) if all_count_results['_shards']['successful'] != 0: all_count = all_count_results['count'] else: all_count = '' #get influence from es influence history try: influence_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_INFLUENCE, doc_type=COPY_USER_PORTRAIT_INFLUENCE_TYPE, \ id = uid)['_source'] except: influence_history = [] #get max value/min value/week ave value if influence_history: week_ave = influence_history['bci_week_ave'] week_ave_rank = get_influence_week_ave_rank(week_ave) influence_item = [week_ave, week_ave_rank] influence_max_min_now_list = get_evaluate_max_min_now(influence_history, 'bci') influence_max_min_now_list.append(all_count) influence_item.extend(influence_max_min_now_list[2:]) results['influence'] = influence_max_min_now_list else: results['influence'] = ['', '', '', '', all_count] #get importance from es importance history try: importance_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_IMPORTANCE, doc_type=COPY_USER_PORTRAIT_IMPORTANCE_TYPE, \ id = uid)['_source'] except: importance_history = [] #get max value/min value/now value if importance_history: importance_max_min_now_list = get_evaluate_max_min_now(importance_history, 'importance') importance_max_min_now_list.append(all_count) results['importance'] = importance_max_min_now_list else: results['importance'] = ['', '', '', '', all_count] #get activeness from es activeness history try: activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE ,\ id = uid)['_source'] except: activeness_history = [] #get max value/min value/ now value if activeness_history: activeness_max_min_now_list = get_evaluate_max_min_now(activeness_history, 'activeness') activeness_max_min_now_list.append(all_count) results['activeness'] = activeness_max_min_now_list else: results['activeness'] = ['', '', '', '', all_count] #get sensitive from es sensitive history try: sensitive_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_SENSITIVE, doc_type=COPY_USER_PORTRAIT_SENSITIVE_TYPE, \ id = uid)['_source'] except: sensitive_history = [] #get max value/min value/ now value if sensitive_history: sensitive_max_min_now_list = get_evaluate_max_min_now(sensitive_history, 'sensitive') sensitive_max_min_now_list.append(all_count) results['sensitive'] = sensitive_max_min_now_list else: results['sensitive'] = ['', '', '', '', all_count] return results