本文整理汇总了Python中user_portrait.global_utils.R_CLUSTER_FLOW2.hget方法的典型用法代码示例。如果您正苦于以下问题:Python R_CLUSTER_FLOW2.hget方法的具体用法?Python R_CLUSTER_FLOW2.hget怎么用?Python R_CLUSTER_FLOW2.hget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user_portrait.global_utils.R_CLUSTER_FLOW2
的用法示例。
在下文中一共展示了R_CLUSTER_FLOW2.hget方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_user_geo
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_geo(uid):
result = []
user_geo_result = {}
user_ip_dict = {}
user_ip_result = dict()
now_ts = time.time()
now_date = ts2datetime(now_ts)
#run_type
if RUN_TYPE == 1:
ts = datetime2ts(now_date)
else:
ts = datetime2ts(RUN_TEST_TIME)
for i in range(1, 8):
ts = ts - 3600*24
results = r_cluster.hget('new_ip_'+str(ts), uid)
if results:
ip_dict = json.loads(results)
for ip in ip_dict:
ip_count = len(ip_dict[ip].split('&'))
try:
user_ip_result[ip] += ip_count
except:
user_ip_result[ip] = ip_count
user_geo_dict = ip2geo(user_ip_result)
user_geo_result = sorted(user_geo_dict.items(), key=lambda x:x[1], reverse=True)
return user_geo_result
示例2: get_geo_track
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_geo_track(uid):
date_results = [] # {'2013-09-01':[(geo1, count1),(geo2, count2)], '2013-09-02'...}
now_ts = time.time()
now_date = ts2datetime(now_ts)
#test
now_date = '2013-09-08'
ts = datetime2ts(now_date)
city_list = []
city_set = set()
for i in range(7, 0, -1):
timestamp = ts - i*24*3600
#print 'timestamp:', ts2datetime(timestamp)
ip_dict = dict()
results = r_cluster.hget('ip_'+str(timestamp), uid)
ip_dict = dict()
date = ts2datetime(timestamp)
date_key = '-'.join(date.split('-')[1:])
if results:
ip_dict = json.loads(results)
geo_dict = ip_dict2geo(ip_dict)
city_list.extend(geo_dict.keys())
sort_geo_dict = sorted(geo_dict.items(), key=lambda x:x[1], reverse=True)
date_results.append([date_key, sort_geo_dict[:2]])
else:
date_results.append([date_key, []])
print 'results:', date_results
city_set = set(city_list)
geo_conclusion = get_geo_conclusion(uid, city_set)
return [date_results, geo_conclusion]
示例3: search_location
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def search_location(now_ts, uid):
date = ts2datetime(now_ts)
#print 'date:', date
ts = datetime2ts(date)
#print 'date-ts:', ts
stat_results = dict()
results = dict()
for i in range(1, 8):
ts = ts - 24 * 3600
#print 'for-ts:', ts
result_string = r_cluster.hget('ip_' + str(ts), str(uid))
if not result_string:
continue
result_dict = json.loads(result_string)
for ip in result_dict:
try:
stat_results[ip] += result_dict[ip]
except:
stat_results[ip] = result_dict[ip]
for ip in stat_results:
city = ip2city(ip)
if city:
try:
results[city][ip] = stat_results[ip]
except:
results[city] = {ip: stat_results[ip]}
description = active_geo_description(results)
results['description'] = description
#print 'location results:', results
return results
示例4: search_mention
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def search_mention(now_ts, uid):
date = ts2datetime(now_ts)
ts = datetime2ts(date)
#print 'at date-ts:', ts
stat_results = dict()
results = dict()
for i in range(1,8):
ts = ts - 24 * 3600
try:
result_string = r_cluster.hget('at_' + str(ts), str(uid))
except:
result_string = ''
if not result_string:
continue
result_dict = json.loads(result_string)
for at_uid in result_dict:
try:
stat_results[at_uid] += result_dict[at_uid]
except:
stat_results[at_uid] = result_dict[at_uid]
for at_uid in stat_results:
# search uid
'''
uname = search_uid2uname(at_uid)
if not uname:
'''
uid = ''
count = stat_results[at_uid]
results[at_uid] = [uid, count]
if results:
sort_results = sorted(results.items(), key=lambda x:x[1][1], reverse=True)
return [sort_results[:20], len(results)]
else:
return [None, 0]
示例5: get_user_geo
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_geo(uid):
result = []
user_geo_result = {}
user_ip_dict = {}
user_ip_result = dict()
now_ts = time.time()
now_date = ts2datetime(now_ts)
ts = datetime2ts(now_date)
#test
ts = datetime2ts('2013-09-08')
for i in range(1, 8):
ts = ts - 3600*24
results = r_cluster.hget('ip_'+str(ts), uid)
if results:
ip_dict = json.loads(results)
for ip in ip_dict:
try:
user_ip_result[ip] += ip_dict[ip]
except:
user_ip_result[ip] = ip_dict[ip]
#print 'user_ip_result:', user_ip_result
user_geo_dict = ip2geo(user_ip_result)
user_geo_result = sorted(user_geo_dict.items(), key=lambda x:x[1], reverse=True)
return user_geo_result
示例6: new_get_user_location
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def new_get_user_location(uid):
results = {}
now_date = ts2datetime(time.time())
now_date_ts = datetime2ts(now_date)
#run type
if RUN_TYPE == 0:
now_date_ts = datetime2ts(RUN_TEST_TIME) - DAY
now_date = ts2datetime(now_date_ts)
#now ip
try:
ip_time_string = r_cluster.hget('new_ip_'+str(now_date_ts), uid)
except Exception, e:
raise e
示例7: search_activity
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def search_activity(now_ts, uid):
date = ts2datetime(now_ts)
print 'date:', date
ts = datetime2ts(date)
timestamp = ts
print 'date-timestamp:', ts
activity_result = dict()
results = dict()
segment_result = dict()
for i in range(1, 8):
ts = timestamp - 24 * 3600*i
#print 'for-ts:', ts
try:
result_string = r_cluster.hget('activity_' + str(ts), str(uid))
except:
result_string = ''
#print 'activity:', result_string
if not result_string:
continue
result_dict = json.loads(result_string)
for time_segment in result_dict:
try:
results[int(time_segment)/16*15*60*16+ts] += result_dict[time_segment]
except:
results[int(time_segment)/16*15*60*16+ts] = result_dict[time_segment]
try:
segment_result[int(time_segment)/16*15*60*16] += result_dict[time_segment]
except:
segment_result[int(time_segment)/16*15*60*16] = result_dict[time_segment]
trend_list = []
for i in range(1,8):
ts = timestamp - i*24*3600
for j in range(0, 6):
time_seg = ts + j*15*60*16
if time_seg in results:
trend_list.append((time_seg, results[time_seg]))
else:
trend_list.append((time_seg, 0))
sort_trend_list = sorted(trend_list, key=lambda x:x[0], reverse=False)
#print 'sort_trend_list:', sort_trend_list
activity_result['activity_trend'] = sort_trend_list
sort_segment_list = sorted(segment_result.items(), key=lambda x:x[1], reverse=True)
activity_result['activity_time'] = sort_segment_list[:2]
#print segment_result
description = active_time_description(segment_result)
activity_result['description'] = description
return activity_result
示例8: get_user_hashtag
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_hashtag(uid):
user_hashtag_result = {}
now_ts = time.time()
now_date = ts2datetime(now_ts)
ts = datetime2ts(now_date)
#test
ts = datetime2ts('2013-09-08')
for i in range(1, 8):
ts = ts - 3600*24
results = r_cluster.hget('hashtag_'+str(ts), uid)
if results:
hashtag_dict = json.loads(results)
for hashtag in hashtag_dict:
try:
user_hashtag_result[hashtag] += hashtag_dict[hashtag]
except:
user_hashtag_result[hashtag] = hashtag_dict[hashtag]
sort_hashtag_dict = sorted(user_hashtag_result.items(), key=lambda x:x[1], reverse=True)
return sort_hashtag_dict
示例9: search_mention
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def search_mention(uid):
now_date_ts = datetime2ts(ts2datetime(time.time()))
#run type
if RUN_TYPE == 0:
now_date_ts = datetime2ts(RUN_TEST_TIME)
day_result_dict_list = []
for i in range(7,0, -1):
iter_ts = now_date_ts - i * DAY
try:
result_string = r_cluster.hget('at_' + str(ts), str(uid))
except:
result_string = ''
if not result_string:
continue
day_result_dict = json.loads(results_string)
day_result_dict_list.append(day_result_dict)
if day_result_dict_list:
week_result_dict = union_dict(day_result_dict_list)
else:
week_result_dict = {}
return week_result_dict
示例10: get_user_hashtag
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_hashtag(uid):
user_hashtag_result = {}
now_ts = time.time()
now_date = ts2datetime(now_ts)
#run_type
if RUN_TYPE == 1:
ts = datetime2ts(now_date)
else:
ts = datetime2ts(RUN_TEST_TIME)
for i in range(1, 8):
ts = ts - 3600*24
results = r_cluster.hget('hashtag_'+str(ts), uid)
if results:
hashtag_dict = json.loads(results)
for hashtag in hashtag_dict:
try:
user_hashtag_result[hashtag] += hashtag_dict[hashtag]
except:
user_hashtag_result[hashtag] = hashtag_dict[hashtag]
sort_hashtag_dict = sorted(user_hashtag_result.items(), key=lambda x:x[1], reverse=True)
return sort_hashtag_dict
示例11: get_user_trend
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_trend(uid):
activity_result = dict()
now_ts = time.time()
date = ts2datetime(now_ts)
#run_type
if RUN_TYPE == 1:
ts = datetime2ts(date)
else:
ts = datetime2ts(RUN_TEST_TIME)
timestamp = ts
results = dict()
for i in range(1, 8):
ts = timestamp - 24*3600*i
try:
result_string = r_cluster.hget('activity_'+str(ts), str(uid))
except:
result_string = ''
if not result_string:
continue
result_dict = json.loads(result_string)
for time_segment in result_dict:
try:
results[int(time_segment)/16*15*60*16+ts] += result_dict[time_segment]
except:
results[int(time_segment)/16*15*60*16+ts] = result_dict[time_segment]
trend_list = []
for i in range(1, 8):
ts = timestamp - i*24*3600
for j in range(0, 6):
time_seg = ts + j*15*60*16
if time_seg in results:
trend_list.append((time_seg, results[time_seg]))
else:
trend_list.append((time_seg, 0))
sort_trend_list = sorted(trend_list, key=lambda x:x[0], reverse=True)
x_axis = [item[0] for item in sort_trend_list]
y_axis = [item[1] for item in sort_trend_list]
return [x_axis, y_axis]
示例12: sorted
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
sort_ip_timestamp = sorted(ip_max_timestamp_list, key=lambda x:int(x[1]), reverse=True)
day_ip_list = [ip_item[0] for ip_item in sort_ip_timestamp]
try:
now_ip = sort_ip_timestamp[0][0]
now_city = ip2city(now_ip)
except:
now_ip = ''
now_city = ''
results['now_ip'] = [now_ip, now_city]
#main ip
day_result = {}
week_result = {}
for i in range(7, 0, -1):
timestamp = now_date_ts - i * DAY
try:
ip_time_string = r_cluster.hget('new_ip_'+str(timestamp), uid)
except:
ip_time_string = {}
if ip_time_string:
ip_time_dict = json.loads(ip_time_string)
else:
ip_time_dict = {}
for ip in ip_time_dict:
ip_time_list = ip_time_dict[ip].split('&')
for ip_timestamp in ip_time_list:
ip_timesegment = (int(ip_timestamp) - timestamp) / IP_TIME_SEGMENT
if ip_timesegment not in day_result:
day_result[ip_timesegment] = {}
try:
day_result[ip_timesegment][ip] += 1
except:
示例13: get_user_detail
# 需要导入模块: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 别名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hget [as 别名]
def get_user_detail(date, input_result, status, user_type="influence", auth=""):
bci_date = ts2datetime(datetime2ts(date) - DAY)
results = []
if status=='show_in':
uid_list = input_result
if status=='show_compute':
uid_list = input_result.keys()
if status=='show_in_history':
uid_list = input_result.keys()
if date!='all':
index_name = 'bci_' + ''.join(bci_date.split('-'))
else:
now_ts = time.time()
now_date = ts2datetime(now_ts)
index_name = 'bci_' + ''.join(now_date.split('-'))
index_type = 'bci'
user_bci_result = es_cluster.mget(index=index_name, doc_type=index_type, body={'ids':uid_list}, _source=True)['docs']
user_profile_result = es_user_profile.mget(index='weibo_user', doc_type='user', body={'ids':uid_list}, _source=True)['docs']
max_evaluate_influ = get_evaluate_max(index_name)
for i in range(0, len(uid_list)):
uid = uid_list[i]
bci_dict = user_bci_result[i]
profile_dict = user_profile_result[i]
try:
bci_source = bci_dict['_source']
except:
bci_source = None
if bci_source:
influence = bci_source['user_index']
influence = math.log(influence/max_evaluate_influ['user_index'] * 9 + 1 ,10)
influence = influence * 100
else:
influence = ''
try:
profile_source = profile_dict['_source']
except:
profile_source = None
if profile_source:
uname = profile_source['nick_name']
location = profile_source['user_location']
fansnum = profile_source['fansnum']
statusnum = profile_source['statusnum']
else:
uname = ''
location = ''
fansnum = ''
statusnum = ''
if status == 'show_in':
if user_type == "sensitive":
tmp_ts = datetime2ts(date) - DAY
tmp_data = r_cluster.hget("sensitive_"+str(tmp_ts), uid)
if tmp_data:
sensitive_dict = json.loads(tmp_data)
sensitive_words = sensitive_dict.keys()
else:
sensitive_words = []
results.append([uid, uname, location, fansnum, statusnum, influence, sensitive_words])
else:
results.append([uid, uname, location, fansnum, statusnum, influence])
if auth:
hashname_submit = "submit_recomment_" + date
tmp_data = json.loads(r.hget(hashname_submit, uid))
recommend_list = (tmp_data['operation']).split('&')
admin_list = []
admin_list.append(tmp_data['system'])
admin_list.append(list(set(recommend_list)))
admin_list.append(len(recommend_list))
results[-1].extend(admin_list)
if status == 'show_compute':
in_date = json.loads(input_result[uid])[0]
compute_status = json.loads(input_result[uid])[1]
if compute_status == '1':
compute_status = '3'
results.append([uid, uname, location, fansnum, statusnum, influence, in_date, compute_status])
if status == 'show_in_history':
in_status = input_result[uid]
if user_type == "sensitive":
tmp_ts = datetime2ts(date) - DAY
tmp_data = r_cluster.hget("sensitive_"+str(tmp_ts), uid)
if tmp_data:
sensitive_dict = json.loads(tmp_data)
sensitive_words = sensitive_dict.keys()
results.append([uid, uname, location, fansnum, statusnum, influence, in_status, sensitive_words])
else:
results.append([uid, uname, location, fansnum, statusnum, influence, in_status])
return results