本文整理汇总了Python中user_portrait.global_utils.R_CLUSTER_FLOW2类的典型用法代码示例。如果您正苦于以下问题:Python R_CLUSTER_FLOW2类的具体用法?Python R_CLUSTER_FLOW2怎么用?Python R_CLUSTER_FLOW2使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了R_CLUSTER_FLOW2类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_geo_track
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]
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:30,代码来源:search.py
示例2: get_user_geo
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
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:27,代码来源:utils.py
示例3: search_location
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
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:32,代码来源:search.py
示例4: search_mention
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]
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:35,代码来源:search.py
示例5: get_user_geo
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
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:25,代码来源:utils.py
示例6: compare_user_activity
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
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:58,代码来源:utils.py
示例7: new_get_user_location
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
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:13,代码来源:new_search.py
示例8: search_activity
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
开发者ID:ztybuaa,项目名称:user_portrait,代码行数:50,代码来源:search.py
示例9: get_user_hashtag
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
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:20,代码来源:utils.py
示例10: search_mention
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
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:21,代码来源:new_search.py
示例11: get_user_hashtag
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
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:22,代码来源:utils.py
示例12: get_user_trend
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]
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:39,代码来源:utils.py
示例13: sorted
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:
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:31,代码来源:new_search.py
示例14: get_user_detail
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
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:87,代码来源:utils.py
注:本文中的user_portrait.global_utils.R_CLUSTER_FLOW2类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论