本文整理汇总了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