本文整理匯總了Python中user_portrait.global_utils.R_CLUSTER_FLOW2.hmget方法的典型用法代碼示例。如果您正苦於以下問題:Python R_CLUSTER_FLOW2.hmget方法的具體用法?Python R_CLUSTER_FLOW2.hmget怎麽用?Python R_CLUSTER_FLOW2.hmget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類user_portrait.global_utils.R_CLUSTER_FLOW2
的用法示例。
在下文中一共展示了R_CLUSTER_FLOW2.hmget方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: compare_user_activity
# 需要導入模塊: from user_portrait.global_utils import R_CLUSTER_FLOW2 [as 別名]
# 或者: from user_portrait.global_utils.R_CLUSTER_FLOW2 import hmget [as 別名]
def compare_user_activity(uid_list):
result = {} # output data: {user:[weibo_status]}, {user:[(date,weibo)]}, ts_list
timesegment_result = {}
now_ts = time.time()
date = ts2datetime(now_ts)
#run_type
if RUN_TYPE == 1:
ts = datetime2ts(date)
else:
ts = datetime2ts(RUN_TEST_TIME)
for i in range(1,8):
ts = ts - DAY
hash_name = 'activity_' + str(ts)
r_result = r_cluster.hmget(hash_name, uid_list)
if r_result:
count = 0
for r_item in r_result:
if r_item:
r_item = json.loads(r_item)
if uid_list[count] not in result:
result[uid_list[count]] = {}
if uid_list[count] not in timesegment_result:
timesegment_result[uid_list[count]] = {}
count += 1
if r_item:
time_result = dict()
for segment in r_item:
try:
result[uid_list[count-1]][int(segment)/16*15*60*16+ts] += r_item[segment]
except:
result[uid_list[count-1]][int(segment)/16*15*60*16+ts] = r_item[segment]
try:
timesegment_result[uid_list[count-1]][int(segment)/16*15*60*16] += r_item[segment]
except:
timesegment_result[uid_list[count-1]][int(segment)/16*15*60*16] = r_item[segment]
user_list = {}
user_timesegment_list = {}
ts_list = []
for user in result:
timesegment_dict = timesegment_result[user]
sort_segment = sorted(timesegment_dict.items(), key=lambda x:x[1], reverse=True)
segment_top = sort_segment[:3]
user_timesegment_list[user] = segment_top
user_dict = result[user]
for i in range(0, 42):
timestamp = ts + 15*60*16*i
if len(ts_list)<42:
ts_list.append(timestamp)
try:
count = user_dict[timestamp]
except:
count = 0
try:
user_list[user].append(count)
except:
user_list[user] = [count]
return user_list, user_timesegment_list, ts_list