def recommentation_in(input_ts, recomment_type, submit_user): date = ts2datetime(input_ts) recomment_results = [] # read from redis results = [] hash_name = 'recomment_'+str(date) + "_" + recomment_type identify_in_hashname = "identify_in_" + str(date) submit_user_recomment = "recomment_" + submit_user + "_" + str(date) # 用户自推荐名单 results = r.hgetall(hash_name) if not results: return [] # search from user_profile to rich the show information recommend_list = set(r.hkeys(hash_name)) identify_in_list = set(r.hkeys("compute")) submit_user_recomment = set(r.hkeys(submit_user_recomment)) recomment_results = list(recommend_list - identify_in_list) recomment_results = list(set(recomment_results) - submit_user_recomment) if recomment_results: results = get_user_detail(date, recomment_results, 'show_in', recomment_type) else: results = [] #test ''' f = open('/home/user_portrait_0320/revised_user_portrait/user_portrait/user_portrait/recommentation/influence_recommend.csv', 'wb') writer = csv.writer(f) for item_result in results: writer.writerow(item_result) f.close() ''' return results
def show_in_history(date): results = [] hash_name = 'recomment_'+str(date) r_results = r.hgetall(hash_name) if r_results: results = get_user_detail(date, r_results, 'show_in_history') return results
def recommentation_in(input_ts, recomment_type, submit_user): date = ts2datetime(input_ts) recomment_results = [] # read from redis results = [] hash_name = 'recomment_' + str(date) + "_" + recomment_type identify_in_hashname = "identify_in_" + str(date) submit_user_recomment = "recomment_" + submit_user + "_" + str( date) # 用户自推荐名单 results = r.hgetall(hash_name) if not results: return [] # search from user_profile to rich the show information recommend_list = set(r.hkeys(hash_name)) identify_in_list = set(r.hkeys("compute")) submit_user_recomment = set(r.hkeys(submit_user_recomment)) recomment_results = list(recommend_list - identify_in_list) recomment_results = list(set(recomment_results) - submit_user_recomment) if recomment_results: results = get_user_detail(date, recomment_results, 'show_in', recomment_type) else: results = [] return results
def show_in_history(date, user_type): results = [] #hash_name = 'recomment_'+str(date) identify_in_hashname = "identify_in_" + str(date) r_results = r.hgetall(identify_in_hashname) if r_results: results = get_user_detail(date, r_results, 'show_in_history', user_type) return results
def show_in_history(date, user_type): results = [] #hash_name = 'recomment_'+str(date) identify_in_hashname = "identify_in_" + str(date) r_results = r.hgetall(identify_in_hashname) if r_results: results = get_user_detail(date, r_results, 'show_in_history', user_type) return results
def get_attr(date): results = {} overview_result = r.hgetall(hash_name) for item in overview_result: value = overview_result[item] if isinstance(value, str): value = json.loads(value) results[item] = value return results
def identify_compute(data): results = False compute_status = 1 hash_name = 'compute' uid2compute = r.hgetall(hash_name) for item in data: uid = item[1] result = r.hget(hash_name, uid) in_date = json.loads(result)[0] r.hset(hash_name, uid, json.dumps([in_date, compute_status])) return True
def identify_compute(data): results = False compute_status = 1 hash_name = 'compute' uid2compute = r.hgetall(hash_name) for item in data: uid = item[1] result = r.hget(hash_name, uid) in_date = json.loads(result)[0] r.hset(hash_name, uid, json.dumps([in_date, compute_status])) return True
def get_attr(date): results = {} overview_result = r.hgetall(hash_name) #print 'overview_result:', overview_result for item in overview_result: value = overview_result[item] if isinstance(value, str): value = json.loads(value) ''' if item in rank_field: value = value[:5] ''' results[item] = value #print 'overview result:', results return results
def recommentation_in(input_ts): date = ts2datetime(input_ts) recomment_results = [] # read from redis results = [] hash_name = 'recomment_'+str(date) results = r.hgetall(hash_name) if not results: return results # search from user_profile to rich the show information for item in results: status = results[item] if status=='0': recomment_results.append(item) if recomment_results: results = get_user_detail(date, recomment_results, 'show_in') else: results = [] return results
def recommentation_in(input_ts, recomment_type): date = ts2datetime(input_ts) recomment_results = [] # read from redis results = [] hash_name = 'recomment_'+str(date) + "_" + recomment_type identify_in_hashname = "identify_in_" + str(date) results = r.hgetall(hash_name) if not results: return [] # search from user_profile to rich the show information recommend_list = set(r.hkeys(hash_name)) identify_in_list = set(r.hkeys("compute")) recomment_results = list(recommend_list - identify_in_list) if recomment_results: results = get_user_detail(date, recomment_results, 'show_in', recomment_type) else: results = [] return results
def admin_recommentation_in(input_ts): date = ts2datetime(input_ts) recomment_results = [] identify_in_hashname = "identify_in_" + str(date) # read from redis results = [] hashname_submit = "submit_recomment_" + date results = r.hgetall(hashname_submit) if not results: return [] # search from user_profile to rich the show information submit_set = set(r.hkeys(hashname_submit)) idntify_in_set = set(r.hkeys("compute")) # 已入库用户名单 recomment_results = list(submit_set - idntify_in_set) #过滤一下 if recomment_results: results = get_user_detail(date, recomment_results, 'show_in', "sensitive", "admin") sorted_results = sorted(results, key=lambda x:x[-1], reverse=True) results = sorted_results else: results = [] return results
def admin_recommentation_in(input_ts): date = ts2datetime(input_ts) recomment_results = [] identify_in_hashname = "identify_in_" + str(date) # read from redis results = [] hashname_submit = "submit_recomment_" + date results = r.hgetall(hashname_submit) if not results: return [] # search from user_profile to rich the show information submit_set = set(r.hkeys(hashname_submit)) idntify_in_set = set(r.hkeys("compute")) # 已入库用户名单 recomment_results = list(submit_set - idntify_in_set) #过滤一下 if recomment_results: results = get_user_detail(date, recomment_results, 'show_in', "sensitive", "admin") sorted_results = sorted(results, key=lambda x:x[-1], reverse=True) results = sorted_results else: results = [] return results
def show_compute(date): results = [] hash_name = 'compute' r_results = r.hgetall(hash_name) input_data = {} #search user profile to inrich information if r_results and date!='all': for user in r_results: item = r_results[user] in_date = json.loads(item)[0] if in_date == date: input_data[user] = item if input_data: results = get_user_detail(date, input_data, 'show_compute') else: results = [] return results elif r_results and date=='all': results = get_user_detail(date, r_results, 'show_compute') return results else: return results
def show_compute(date): results = [] hash_name = 'compute' r_results = r.hgetall(hash_name) input_data = {} #search user profile to inrich information if r_results and date!='all': for user in r_results: item = r_results[user] in_date = json.loads(item)[0] if in_date == date: input_data[user] = item if input_data: results = get_user_detail(date, input_data, 'show_compute') else: results = [] return results elif r_results and date=='all': results = get_user_detail(date, r_results, 'show_compute') return results else: return results
def get_importance_top(): overview_result = r.hgetall(hash_name) importance_top = json.loads(overview_result['top_importance']) return importance_top
def get_retweeted_top(): overview_result = r.hgetall(hash_name) retweeted_top = json.loads(overview_result['top_retweeted_user']) return retweeted_top
def get_online_pattern(): overview_result = r.hgetall(hash_name) online_pattern = json.loads(overview_result['online_pattern_top']) return online_pattern
def get_importance_top(): overview_result = r.hgetall(hash_name) importance_top = json.loads(overview_result['top_importance']) return importance_top
def get_activeness_top(): overview_result = r.hgetall(hash_name) activeness_top = json.loads(overview_result['top_activeness']) return activeness_top
def get_comment_top(): overview_result = r.hgetall(hash_name) comment_top = json.loads(overview_result['top_comment_user']) return comment_top
def get_retweeted_top(): overview_result = r.hgetall(hash_name) retweeted_top = json.loads(overview_result['top_retweeted_user']) return retweeted_top
def get_hashtag_top(): overview_result = r.hgetall(hash_name) hashtag_top = json.loads(overview_result['hashtag_top']) return hashtag_top
def get_online_pattern(): overview_result = r.hgetall(hash_name) online_pattern = json.loads(overview_result['online_pattern_top']) return online_pattern
def get_geo_top(): overview_result = r.hgetall(hash_name) geo_top = json.loads(overview_result['activity_geo_top']) return geo_top
def get_hashtag_top(): overview_result = r.hgetall(hash_name) hashtag_top = json.loads(overview_result['hashtag_top']) return hashtag_top
def get_geo_top(): overview_result = r.hgetall(hash_name) geo_top = json.loads(overview_result['activity_geo_top']) return geo_top
def get_comment_top(): overview_result = r.hgetall(hash_name) comment_top = json.loads(overview_result['top_comment_user']) return comment_top
def get_activeness_top(): overview_result = r.hgetall(hash_name) activeness_top = json.loads(overview_result['top_activeness']) return activeness_top