本文整理汇总了Python中time_utils.ts2datetime函数的典型用法代码示例。如果您正苦于以下问题:Python ts2datetime函数的具体用法?Python ts2datetime怎么用?Python ts2datetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ts2datetime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
RUN_TYPE = 0
if RUN_TYPE == 1:
now_ts = time.time()
else:
now_ts = datetime2ts(RUN_TEST_TIME)
now_ts = datetime2ts('2013-09-02')
date = ts2datetime(now_ts - DAY)
# auto recommendation: step 1:4
#step1: read from top es_daily_rank
top_user_set, user_dict = search_from_es(date)
#step2: filter black_uid
black_user_set = read_black_user()
subtract_user_set = top_user_set - black_user_set
#step3: filter users have been in
subtract_user_set = list(subtract_user_set)
candidate_results = filter_in(subtract_user_set)
#step4: filter rules about ip count& reposts/bereposts count&activity count
results = filter_rules(candidate_results)
#step5: get sensitive user
sensitive_user = list(get_sensitive_user(date))
results = results - set(sensitive_user) # influence user - sensitive user
new_date = ts2datetime(now_ts)
hashname_influence = "recomment_" + new_date + "_influence"
if results:
for uid in results:
#print uid
r.hset(hashname_influence, uid, "0")
hashname_sensitive = "recomment_" + new_date + "_sensitive"
if sensitive_user:
for uid in sensitive_user:
#print "sensitive"
r.hset(hashname_sensitive, uid, "0")
"""
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:35,代码来源:recommentation_in.py
示例2: get_activity_time
def get_activity_time(uid_list):
results = {}
now_ts = time.time()
now_date = ts2datetime(now_ts)
#run_type
if RUN_TYPE == 1:
timestamp = datetime2ts(now_date)
else:
timestamp = datetime2ts("2013-09-08")
activity_list_dict = {} # {uid:[activity_list], uid:[]}
for i in range(1,WEEK+1):
ts = timestamp - DAY*i
if WORK_TYPE != 0:
r_result = redis_activity.hmget('activity_'+str(ts), uid_list)
else:
r_result = []
index_name = "activity_" + str(ts2datetime(ts))
exist_bool = es_cluster.indices.exists(index=index_name)
if exist_bool:
es_results = es_cluster.mget(index=index_name, doc_type="activity", body={"ids":uid_list})["docs"]
for item in es_results:
if item['found']:
r_result.append(item['_source']['activity_dict'])
else:
r_result.append(json.dumps({}))
else:
r_result = [json.dumps(dict())]*len(uid_list)
if r_result:
for j in range(0, len(uid_list)):
uid = uid_list[j]
if uid not in activity_list_dict:
activity_list_dict[uid] = [0 for i in range(0, 96)]
user_r_result = r_result[j]
if user_r_result:
user_activity_dict = json.loads(user_r_result)
for i in range(0, 96):
try:
count = user_activity_dict[str(i)]
except:
count = 0
activity_list_dict[uid].append(count)
for uid in uid_list:
activity_list = activity_list_dict[uid]
statusnum = sum(activity_list)
signal = np.array(activity_list)
fftResult = np.abs(np.fft.fft(signal))**2
n = signal.size
freq = np.fft.fftfreq(n, d=1)
i = 0
max_val = 0
max_freq = 0
for val in fftResult:
if val>max_val and freq[i]>0:
max_val = val
max_freq = freq[i]
i += 1
results[uid] = {'statusnum': statusnum, 'activity_time': math.log(max_freq + 1)}
return results
开发者ID:yuwendong,项目名称:sensitive_user_portrait,代码行数:60,代码来源:evaluate_index.py
示例3: query_hot_weibo
def query_hot_weibo(ts, origin_mid_list, time_segment):
query_all_body = {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{"range": {
"timestamp":{
"gte": ts - time_segment,
"lt": ts
}
}},
{"terms":{"root_mid":origin_mid_list}}
]
}
}
}
},
"aggs":{
"all_mid":{
"terms":{"field": "root_mid", "size":400},
"aggs":{
"message_type":{
"terms":{
"field":"message_type"
}
}
}
}
}
}
return_results = dict()
datetime_1 = ts2datetime(ts)
datetime_2 = ts2datetime(ts-24*3600)
index_name_1 = flow_text_index_name_pre + datetime_1
index_name_2 = flow_text_index_name_pre + datetime_2
index_list = []
exist_es_1 = es_text.indices.exists(index_name_1)
exist_es_2 = es_text.indices.exists(index_name_2)
if exist_es_1:
index_list.append(index_name_1)
if exist_es_2:
index_list.append(index_name_2)
if index_list:
results = es_text.search(index=index_list, doc_type=flow_text_index_type,body=query_all_body)['aggregations']['all_mid']['buckets']
if results:
for item in results:
temp_dict = dict()
temp_dict[item['key']] = item['doc_count']
detail = item['message_type']['buckets']
detail_dict = dict()
for iter_item in detail:
detail_dict[iter_item['key']] = iter_item['doc_count']
temp_dict['retweeted'] = detail_dict.get(3, 0)
temp_dict['comment'] = detail_dict.get(2, 0)
return_results[item['key']] = temp_dict
return return_results
开发者ID:huxiaoqian,项目名称:user_portrait_ending2,代码行数:60,代码来源:sensing_v5.py
示例4: key_words_search
def key_words_search( search_type , pre , during , start_time , keyword , search_key = '' , sort_norm = '', sort_scope = '' ,time = 1 , isall = False):
keywords = keyword.split(",")
should = []
for key in keywords:
if search_type == "hashtag":
should.append({"prefix":{"text.text": "#" + key + "#"}})
else:
should.append({"prefix":{"text.text":key}})
date = start_time
index_name = pre + start_time
while not es_9206.indices.exists(index= index_name) :
new_time = datetime2ts(date) + DAY
date = ts2datetime(new_time)
index_name = pre + date
during -= 1
uid_set = set()
for i in range(during):
print index_name
query = {"query":{"bool":{"must":[],"must_not":[],"should":should}},"size":MAX_ITEMS,"sort":[],"facets":{},"fields":['uid']}
try :
temp = es_9206.search(index = index_name , doc_type = 'text' , body = query)
result = temp['hits']['hits']
print "Fetch " + str(len(result))
for item in result :
uid_set.add(item['fields']['uid'][0].encode("utf-8") )
except Exception,e:
print e
raise Exception('user_list failed!')
new_time = datetime2ts(date) + DAY
date = ts2datetime(new_time)
index_name = pre + date
i += 1
开发者ID:huxiaoqian,项目名称:user_portrait_0324,代码行数:34,代码来源:Keyword_task.py
示例5: get_attr_geo_track
def get_attr_geo_track(uid_list):
date_results = [] # results = {'2013-09-01':[(geo1, count1), (geo2, track2)], '2013-09-02'...} 7day
now_ts = time.time()
now_date = ts2datetime(now_ts)
#test
now_date = '2013-09-08'
ts = datetime2ts(now_date)
for i in range(7, 0, -1):
timestamp = ts - i*24*3600
#print 'timestamp:', ts2datetime(timestamp)
ip_dict = dict()
results = r_cluster.hmget('ip_'+str(timestamp), uid_list)
#print 'results:',results
for item in results:
if item:
item_dict = json.loads(item)
#print 'item_dict:', item_dict
for ip_item in item_dict:
try:
ip_dict[ip_item] += item_dict[ip_item]
except:
ip_dict[ip_item] = item_dict[ip_item]
geo_dict = ip2geo(ip_dict)
sort_geo_dict = sorted(geo_dict.items(), key=lambda x:x[1], reverse=True)
date_key = ts2datetime(timestamp)
date_results.append([date_key, sort_geo_dict[:2]])
#print 'results:', date_results
return {'geo_track': json.dumps(date_results)}
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:28,代码来源:cron_group.py
示例6: filter_activity
def filter_activity(user_set):
results = []
#run_type
if RUN_TYPE == 1:
now_date = ts2datetime(time.time())
else:
now_date = RUN_TEST_TIME
ts = datetime2ts(now_date) - DAY
date = ts2datetime(ts)
timestamp = datetime2ts(date)
for user in user_set:
over_count = 0
for i in range(0,7):
ts = timestamp - DAY*i
result = redis_activity.hget('activity_'+str(ts), str(user))
if result:
items_dict = json.loads(result)
for item in items_dict:
weibo_count = items_dict[item]
if weibo_count > activity_threshold:
over_count += 1
if over_count == 0:
results.append(user)
else:
writer.writerow([user, 'activity'])
return results
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:27,代码来源:filter_rules.py
示例7: filter_activity
def filter_activity(user_set):
results = []
now_date = ts2datetime(time.time())
# test
now_date = '2013-09-08'
ts = datetime2ts(now_date) - 24*3600
date = ts2datetime(ts)
#print 'date:', date
timestamp = datetime2ts(date)
for user in user_set:
over_count = 0
for i in range(0,7):
ts = timestamp - 3600*24*i
result = r_cluster.hget('activity_'+str(ts), str(user))
if result:
items_dict = json.loads(result)
for item in items_dict:
weibo_count = items_dict[item]
if weibo_count > activity_threshold:
over_count += 1
if over_count == 0:
results.append(user)
else:
writer.writerow([user, 'activity'])
print 'after filter activity:', len(results)
return results
开发者ID:taozhiiq,项目名称:user_portrait,代码行数:27,代码来源:filter_rules.py
示例8: filter_activity
def filter_activity(user_set):
results = []
now_date = ts2datetime(time.time())
now_date = '2013-09-08'
ts = datetime2ts(now_date) - 24*3600
date = ts2datetime(ts)
timestamp = datetime2ts(date)
ts = ts.replace('-','')
for user in user_set:
over_count = 0
for i in range(0,7):
ts = timestamp - 3600*24*i
result = r_cluster.hget('activity_'+str(ts), str(user))
if result:
item_dict = json.loads(result)
sorted_dict = sorted(item_dict.iteritems(), key=lambda asd:asd[1], reverse=True)
if sorted_dict[0][1] > activity_threshold:
over_count = 1
if over_count == 0:
results.append(user)
else:
writer.writerow([user, 'activity'])
print 'after filter activity: ', len(results)
return results
开发者ID:huxiaoqian,项目名称:sensitive_user_portrait,代码行数:25,代码来源:filter_rules.py
示例9: key_words_search
def key_words_search( pre , time , start_time , keyword , type = 'in' ):
date = start_time
index_name = pre + start_time
while not es.indices.exists(index= index_name) :
time = datetime2ts(date) + DAY
date = ts2datetime(time)
index_name = pre + date
time -= 1
uid_set = set()
for i in range(time):
print index_name
query = {"query":{"bool":{"must":[{"prefix":{"text.text":keyword}}],"must_not":[],"should":[]}},"size":MAX_ITEMS,"sort":[],"facets":{},"fields":['uid']}
try :
temp = es.search(index = index_name , doc_type = 'text' , body = query)
result = temp['hits']['hits']
print "Fetch " + str(len(result))
for item in result :
uid_set.add(item['fields']['uid'][0].encode("utf-8") )
except Exception,e:
print e
raise Exception('user_list failed!')
time = datetime2ts(date) + DAY
date = ts2datetime(time)
index_name = pre + date
i += 1
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:26,代码来源:Key_words_search.py
示例10: search_weibo_task
def search_weibo_task(user_name):
c_result = {}
query = {"query":{"bool":{"must":[{"term":{"user_rank_task.submit_user":user_name}}]}},"size":MAX_ITEMS,"sort":[{"create_time":{"order":"desc"}}],"fields":["status","search_type","keyword","submit_user","sort_scope","sort_norm","start_time","user_ts","end_time", "create_time", 'number']}
if 1:
return_list = []
result = es.search(index=WEIBO_RANK_KEYWORD_TASK_INDEX , doc_type=WEIBO_RANK_KEYWORD_TASK_TYPE , body=query)['hits']
c_result['flag'] = True
for item in result['hits']:
result_temp = {}
result_temp['submit_user'] = item['fields']['submit_user'][0]
result_temp['search_type'] = item['fields']['search_type'][0]
result_temp['keyword'] = json.loads(item['fields']['keyword'][0])
result_temp['sort_scope'] = item['fields']['sort_scope'][0]
result_temp['sort_norm'] = item['fields']['sort_norm'][0]
result_temp['start_time'] = ts2datetime(item['fields']['start_time'][0])
result_temp['end_time'] = ts2datetime(item['fields']['end_time'][0])
result_temp['status'] = item['fields']['status'][0]
result_temp['create_time'] = ts2date(item['fields']['create_time'][0])
result_temp['search_id'] = item['fields']['user_ts'][0]
tmp = item['fields'].get('number', 0)
if tmp:
result_temp['number'] = int(tmp[0])
else:
result_temp['number'] = 100
return_list.append(result_temp)
c_result['data'] = return_list
return c_result
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:27,代码来源:Offline_task.py
示例11: get_interval_count
def get_interval_count(topic, start_ts, end_ts):
results = [0]
ts_list = []
#unit = 900
#during = Day
during = interval_count_during
start_ts = datetime2ts(ts2datetime(start_ts))
ts_list.append(start_ts)
#end_ts = datetime2ts(ts2datetime(end_ts))
# deal with the time is not the whole day
print 'before deal end_ts:', ts2date(end_ts)
if end_ts - datetime2ts(ts2datetime(end_ts))!= 0:
end_ts = datetime2ts(ts2datetime(end_ts)) + 3600 * 24
print 'get_interval_count start_ts:', ts2date(start_ts)
print 'get_interval_count end_ts:', ts2date(end_ts)
windowsize = (end_ts - start_ts) / Day
interval = (end_ts - start_ts) / During
for i in range(interval, 0, -1):
begin_ts = end_ts - during * i
over_ts = begin_ts + during
ts_list.append(over_ts)
items = db.session.query(PropagateCountNews).filter(PropagateCountNews.topic==topic ,\
PropagateCountNews.end<=over_ts ,\
PropagateCountNews.end>begin_ts ,\
PropagateCountNews.range==unit).all()
if items:
result = Merge_propagate(items)
else:
result = 0
results.append(float(result))
return ts_list, results
开发者ID:huxiaoqian,项目名称:case,代码行数:34,代码来源:trend_user_news.py
示例12: main
def main():
scan_cursor = 0
count = 0
bulk_action = []
number = r.scard('user_set')
print number
if RUN_TYPE:
ts = time.time() - DAY
date = ts2datetime(ts)
start_time = str(ts2datetime(time.time()))
print "/cron/push_mid2redis.py&start&%s" %start_time
else:
date = '2013-09-05'
index_name = flow_text_index_name_pre+date
print index_name
ts = time.time()
while 1:
re_scan = r.sscan("user_set", scan_cursor, count=3000)
scan_cursor = re_scan[0]
uid_list = re_scan[1] #具体数据
if len(uid_list):
for uid in uid_list:
detail_dict = r.hgetall(uid)
for k,v in detail_dict.iteritems():
update_dict = dict()
if "_origin_weibo_retweeted" in k and v:
mid = k.split('_')[0]
update_dict["retweeted"] = int(v)
elif "_origin_weibo_comment" in k and v:
mid = k.split('_')[0]
update_dict["comment"] = int(v)
elif '_retweeted_weibo_comment' in k and v:
mid = k.split('_')[0]
update_dict["comment"] = int(v)
elif '_retweeted_weibo_retweeted' in k and v:
mid = k.split('_')[0]
update_dict["retweeted"] = int(v)
else:
pass
if update_dict:
action = {"update": {"_id": mid}}
xdata = {"doc": update_dict}
bulk_action.extend([action, xdata])
count += 1
if count % 400 == 0:
r_flow.lpush('update_mid_list', json.dumps(bulk_action))
bulk_action = []
tp = time.time()
#print "%s cost %s" %(count, tp-ts)
ts = tp
if int(scan_cursor) == 0:
break
if bulk_action:
r_flow.lpush('update_mid_list', json.dumps(bulk_action))
print count
开发者ID:lcwy220,项目名称:revised_user_portrait,代码行数:59,代码来源:push_mid2redis.py
示例13: read_flow_text
def read_flow_text(uid_list):
'''
读取用户微博(返回结果没有微博情绪标签):
输入数据:uid_list(字符串型列表)
输出数据:word_dict(用户分词结果字典),weibo_list(用户微博列表)
word_dict示例:{uid1:{'w1':f1,'w2':f2...}...}
weibo_list示例:[[uid1,text1,ts1],[uid2,text2,ts2],...](每一条记录对应三个值:uid、text、timestamp)
'''
word_dict = dict()#词频字典
weibo_list = []#微博列表
online_pattern_dict = {} # {uid:[online_pattern1, ..],...}
now_ts = time.time()
#run_type
if RUN_TYPE == 1:
now_date_ts = datetime2ts(ts2datetime(now_ts))
else:
now_date_ts = datetime2ts(RUN_TEST_TIME)
start_date_ts = now_date_ts - DAY * WEEK
for i in range(0,WEEK):
iter_date_ts = start_date_ts + DAY * i
flow_text_index_date = ts2datetime(iter_date_ts)
flow_text_index_name = flow_text_index_name_pre + flow_text_index_date
print flow_text_index_name
try:
flow_text_exist = es_flow_text.search(index=flow_text_index_name, doc_type=flow_text_index_type,\
body={'query':{'filtered':{'filter':{'terms':{'uid': uid_list}}}}, 'size': MAX_VALUE}, _source=False, fields=['text','uid','keywords_dict','timestamp'])['hits']['hits']
except:
flow_text_exist = []
for flow_text_item in flow_text_exist:
uid = flow_text_item['fields']['uid'][0].encode('utf-8')
text = flow_text_item['fields']['text'][0].encode('utf-8')
ts = flow_text_item['fields']['timestamp'][0]
keywords_dict = json.loads(flow_text_item['fields']['keywords_dict'][0])
keywords_dict = json.dumps(keywords_dict, encoding="UTF-8", ensure_ascii=False)
keywords_dict = eval(keywords_dict)
if word_dict.has_key(uid):
item_dict = Counter(word_dict[uid])
keywords_dict = Counter(keywords_dict)
item_dict = dict(item_dict + keywords_dict)
word_dict[uid] = item_dict
else:
word_dict[uid] = keywords_dict
weibo_list.append([uid,text,ts])
#test online pattern
online_pattern = u'weibo.com'
try:
user_online_pattern_dict = online_pattern_dict[uid]
except:
online_pattern_dict[uid] = {}
try:
online_pattern_dict[uid][online_pattern] += 1
except:
online_pattern_dict[uid][online_pattern] = 1
return word_dict,weibo_list, online_pattern_dict, start_date_ts
开发者ID:lcwy220,项目名称:deployed_user_portrait,代码行数:59,代码来源:weibo_api_v2.py
示例14: aggregation_sentiment_related_weibo
def aggregation_sentiment_related_weibo(ts, origin_mid_list, time_segment, message_type=1, uid_list=[]):
if message_type == 1:
query_all_body = {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{"range": {"timestamp": {"gte": ts - time_segment, "lt": ts}}},
{"terms": {"root_mid": origin_mid_list}},
]
}
}
}
},
"aggs": {"all_sentiments": {"terms": {"field": "sentiment"}}},
}
else:
query_all_body = {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{"range": {"timestamp": {"gte": ts - time_segment, "lt": ts}}},
{"terms": {"root_mid": origin_mid_list}},
{"terms": {"directed_uid": uid_list}},
]
}
}
}
},
"aggs": {"all_sentiments": {"terms": {"field": "sentiment"}}},
}
results = {"0": 0, "1": 0, "2": 0, "3": 0, "4": 0, "5": 0, "6": 0}
datetime_1 = ts2datetime(ts)
datetime_2 = ts2datetime(ts - 24 * 3600)
index_name_1 = flow_text_index_name_pre + datetime_1
index_name_2 = flow_text_index_name_pre + datetime_2
index_list = []
exist_es_1 = es_text.indices.exists(index_name_1)
exist_es_2 = es_text.indices.exists(index_name_2)
if exist_es_1:
index_list.append(index_name_1)
if exist_es_2:
index_list.append(index_name_2)
if index_list:
search_results = es_text.search(index=index_list, doc_type=flow_text_index_type, body=query_all_body)[
"aggregations"
]["all_sentiments"]["buckets"]
if search_results:
for item in search_results:
key = item["key"]
count = item["doc_count"]
results[key] = count
print "results: ", results, sum(results.values())
return results
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:58,代码来源:sensing_v4.py
示例15: main
def main():
now_ts = time.time()
delete_ts = datetime2ts(ts2datetime(now_ts-EXPIRE_TIME)) #待删除的时间戳
delete_date = ts2datetime(now_ts-EXPIRE_TIME)
del_day = ts2datetime(now_ts-MONTH_TIME)
index_name = flow_text_index_name_pre + del_day
exist_es = es_flow_text.indices.exists(index=index_name)
if exist_es:
es_flow_text.indices.delete(index=index_name)
index_bci = "bci_" + del_day.replace('-', '')
exist_bci = ES_CLUSTER_FLOW1.indices.exists(index=index_bci)
if exist_bci:
ES_CLUSTER_FLOW1.indices.delete(index=index_bci)
#delete @
redis_cluster.delete("at_"+str(delete_ts))
redis_cluster.delete("sensitive_at_"+str(delete_ts))
#delete ip
redis_ip.delete('ip_'+str(delete_ts))
if WORK_TYPE == 0:
exist_ip = es_cluster.indices.exists(index="ip_"+delete_date)
if exist_ip:
es_cluster.indices.delete(index="ip_"+delete_date)
redis_ip.delete('sensitive_ip_'+str(delete_ts))
if WORK_TYPE == 0:
exist_ip = es_cluster.indices.exists(index="sensitive_ip_"+delete_date)
if exist_ip:
es_cluster.indices.delete(index="sensitive_ip_"+delete_date)
#delete activity
redis_activity.delete('activity_'+str(delete_ts))
if WORK_TYPE == 0:
exist_activity = es_cluster.indices.exists(index="activity_"+delete_date)
if exist_activity:
es_cluster.indices.delete(index="activity_"+delete_date)
redis_activity.delete('sensitive_activity_'+str(delete_ts))
if WORK_TYPE == 0:
exist_activity = es_cluster.indices.exists(index="sensitive_activity_"+delete_date)
if exist_activity:
es_cluster.indices.delete(index="sensitive_activity_"+delete_date)
#delete hashtag
redis_cluster.delete('hashtag_'+str(delete_ts))
redis_cluster.delete('sensitive_hashtag_'+str(delete_ts))
#delete sensitive words
redis_cluster.delete('sensitive_'+str(delete_ts))
#delete recommendation
r.delete('recomment_'+str(delete_date)+"_influence")
r.delete('recomment_'+str(delete_date)+"_sensitive")
r.delete("identify_in_sensitive_" + str(delete_date))
r.delete("identify_in_influence_" + str(delete_date)))
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:56,代码来源:delete_redis.py
示例16: query_hot_weibo
def query_hot_weibo(ts, origin_mid_list, time_segment, keywords_list, aggregation_field="root_mid", size=100):
query_all_body = {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{"range": {
"timestamp":{
"gte": ts - time_segment,
"lt": ts
}
}}],
"should": [
{"terms":{
"keywords_string": keywords_list
}
}
]
}
}
}
},
"aggs":{
"all_count":{
"terms":{"field": aggregation_field, "size": size}
}
}
}
datetime = ts2datetime(ts)
# test
#datetime = "2013-09-07"
hot_mid_dict = dict()
index_name = flow_text_index_name_pre + datetime
exist_es = es_text.indices.exists(index_name)
if origin_mid_list and exist_es:
query_all_body["query"]["filtered"]["filter"]["bool"]["should"].append({"terms": {"root_mid": origin_mid_list}})
query_all_body["query"]["filtered"]["filter"]["bool"]["should"].append({"terms": {"mid": origin_mid_list}})
results = es_text.search(index=index_name, doc_type=flow_text_index_type, body=query_all_body)['aggregations']['all_count']['buckets']
if results:
for item in results:
hot_mid_dict[item['key']] = item['doc_count']
datetime_1 = ts2datetime(ts-time_segment)
index_name_1 = flow_text_index_name_pre + datetime_1
exist_es_1 = es_text.indices.exists(index_name_1)
if datetime_1 != datetime and exist_es_1:
query_all_body["query"]["filtered"]["filter"]["bool"]["should"].append({"terms": {"root_mid": origin_mid_list}})
query_all_body["query"]["filtered"]["filter"]["bool"]["should"].append({"terms": {"mid": origin_mid_list}})
results_1 = es_text.search(index=index_name, doc_type=flow_text_index_type, body=query_all_body)['aggregations']['all_count']['buckets']
if results_1:
for item in results:
hot_mid_dict[item['key']] = item['doc_count']
return hot_mid_dict
开发者ID:lcwy220,项目名称:user_portrait,代码行数:56,代码来源:aggregation_weibo.py
示例17: update_his_item
def update_his_item(history_item , today_bci , today_date):
last_day = ts2datetime(today_date - DAY)
warehousing_time = history_item['_source']['warehousing_time'] #get the warehousing time yyyy-mm-dd
#get the days of warehousing
day = int((today_date - datetime2ts(warehousing_time))/DAY + 1)
item = history_item['_source']
try:
item['bci_day_change'] = today_bci - item['bci_' + ts2datetime(today_date - 2 * DAY)]
except Exception, e:
print history_item['_id'] + ":" + e.message
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:10,代码来源:bci_history_maker.py
示例18: sort_task
def sort_task(user, keyword, status, start_time, end_time, submit_time):
query_body = {
"query":{
"filtered":{
"filter":{
"bool":{
"must":[
{"term":{"submit_user": user}}
]
}
}
}
},
"size": 10000,
"sort":{"submit_time":{"order":"desc"}}
}
query_list = []
if keyword:
keyword_list = keyword.split(',')
query_list.append({"terms":{"keyword_string":keyword_list}})
if status != 2:
query_list.append({"term":{"status": status}})
if start_time and end_time:
start_ts = datetime2ts(start_time)
end_ts = datetime2ts(end_time)
query_list.append({"range":{"start_time":{"gte":start_ts, "lte":end_ts}}})
query_list.append({"range":{"end_time":{"gte":start_ts, "lte":end_ts}}})
if submit_time:
query_list.append({"term":{"submit_time": submit_time}})
if query_list:
query_body["query"]["filtered"]["filter"]["bool"]["must"].extend(query_list)
#print query_body
search_results = es.search(index=USER_RANK_KEYWORD_TASK_INDEX, doc_type=USER_RANK_KEYWORD_TASK_TYPE, body=query_body)["hits"]["hits"]
results = []
if search_results:
for item in search_results:
iter_item = item['_source']
tmp = []
tmp.append(iter_item['search_type'])
tmp.append(json.loads(iter_item['keyword']))
tmp.append(ts2datetime(iter_item['start_time']))
tmp.append(ts2datetime(iter_item['end_time']))
tmp.append(iter_item['range'])
tmp.append(ts2date(iter_item['create_time']))
tmp.append(iter_item['status'])
tmp.append(iter_item['sort_norm'])
tmp.append(iter_item['sort_scope'])
tmp.append(item['_id']) # task_name
results.append(tmp)
return results
开发者ID:SwoJa,项目名称:ruman,代码行数:54,代码来源:Offline_task.py
示例19: query_related_weibo
def query_related_weibo(ts, origin_mid_list, time_segment):
query_all_body = {
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{"range": {
"timestamp":{
"gte": ts - time_segment,
"lt": ts
}
}},
{"terms":{"root_mid":origin_mid_list}}
]
}
}
}
},
"aggs":{
"all_count":{
"terms":{"field": "message_type"}
}
}
}
return_results = {"origin": 0, "retweeted": 0, "comment": 0}
datetime_1 = ts2datetime(ts)
datetime_2 = ts2datetime(ts-24*3600)
index_name_1 = flow_text_index_name_pre + datetime_1
index_name_2 = flow_text_index_name_pre + datetime_2
index_list = []
exist_es_1 = es_text.indices.exists(index_name_1)
exist_es_2 = es_text.indices.exists(index_name_2)
if exist_es_1:
index_list.append(index_name_1)
if exist_es_2:
index_list.append(index_name_2)
if index_list:
results = es_text.search(index=index_list, doc_type=flow_text_index_type,body=query_all_body)['aggregations']['all_count']['buckets']
if results:
for item in results:
if int(item['key']) == 1:
return_results['origin'] = item['doc_count']
elif int(item['key']) == 3:
return_results['retweeted'] = item['doc_count']
elif int(item['key']) == 2:
return_results['comment'] = item['doc_count']
else:
pass
return_results['total_count'] = sum(return_results.values())
print "return_results: ", return_results
return return_results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:54,代码来源:sensing_v3.py
示例20: main
def main():
filter_uid = all_delete_uid()
#record_time = time.strftime("%Y%m%d", time.localtime(time.time()))
record_time = ts2datetime(time.time()) # 2013-09-08
former_time = ts2datetime(time.time() - 24*3600) # 2013-09-07
recommend_list = search_low_number(threshould) # recommended user to delete in portrait database
print len(recommend_list)
recommend_list = list(set(recommend_list).difference(filter_uid))
recommend_redis.hset("recommend_delete_list", record_time, json.dumps(recommend_list)) # 今日推荐出库名单
recommend_redis.hdel("recommend_delete_list", former_time) # 删除昨日推荐名单,只维护一个推荐出库名单
return 1
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:12,代码来源:recommend_to_delete.py
注:本文中的time_utils.ts2datetime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论