本文整理汇总了Python中user_portrait.time_utils.datetime2ts函数的典型用法代码示例。如果您正苦于以下问题:Python datetime2ts函数的具体用法?Python datetime2ts怎么用?Python datetime2ts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了datetime2ts函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: get_user_weibo
def get_user_weibo(uid):
result = []
#use to test
datestr = '2013-09-02'
end_ts = datetime2ts(datestr)
#real way to get datestr and ts_segment
'''
now_ts = time.time()
now_date = ts2datetime(now_ts)
now_date_ts = datetime2ts(now_date)
ts_segment = (int((now_ts - now_date_ts) / 3600)) % 24
end_ts = now_date_ts + ts_segment * 3600
'''
file_list = set(os.listdir(DEFAULT_LEVELDBPATH))
for i in range(24*7, 0, -1):
ts = end_ts - i * 3600
datestr = ts2datetime(ts)
ts_segment = (int((ts - datetime2ts(datestr)) / 3600)) % 24 + 1
leveldb_folder = datestr + str(ts_segment)
if leveldb_folder in file_list:
leveldb_bucket = dynamic_leveldb(leveldb_folder)
try:
user_weibo = leveldb_bucket.Get(uid)
weibo_list = json.loads(user_weibo)
result.extend(weibo_list)
except:
pass
return result
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:31,代码来源:utils.py
示例2: search_sentiment_all_portrait
def search_sentiment_all_portrait(start_date, end_date, time_segment):
sentiment_ts_count_dict = {}
start_ts = datetime2ts(start_date)
end_ts = datetime2ts(end_date)
search_date_list = []
domain_list = domain_en2ch_dict.keys()
for i in range(start_ts, end_ts + DAY, DAY):
iter_date = ts2datetime(i)
search_date_list.append(iter_date)
for sentiment in sentiment_type_list:
sentiment_ts_count_dict[sentiment] = []
for date_item in search_date_list:
ts_count_result_list = []
for domain in domain_list:
iter_r_name = r_domain_sentiment_pre + date_item + '_' + sentiment + '_' + domain
#get ts_count_dict in one day
ts_count_result = R_DOMAIN_SENTIMENT.hgetall(iter_r_name)
ts_count_result_list.append(ts_count_result)
#union all domain to get all portrait
all_ts_count_result = union_dict(ts_count_result_list)
#get x and y list by timesegment
new_ts_count_dict = get_new_ts_count_dict(all_ts_count_result, time_segment, date_item)
sort_new_ts_count = sorted(new_ts_count_dict.items(), key=lambda x:x[0])
sentiment_ts_count_dict[sentiment].extend(sort_new_ts_count)
return sentiment_ts_count_dict
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:25,代码来源:utils.py
示例3: 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
示例4: 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('-'))
tmp_ts = str(datetime2ts(date) - DAY)
sensitive_string = "sensitive_score_" + tmp_ts
query_sensitive_body = {
"query":{
"match_all":{}
},
"size":1,
"sort":{sensitive_string:{"order":"desc"}}
}
try:
top_sensitive_result = es_bci_history.search(index=ES_SENSITIVE_INDEX, doc_type=DOCTYPE_SENSITIVE_INDEX, body=query_sensitive_body, _source=False, fields=[sensitive_string])['hits']['hits']
top_sensitive = top_sensitive_result[0]['fields'][sensitive_string][0]
except Exception, reason:
print Exception, reason
top_sensitive = 400
开发者ID:huxiaoqian,项目名称:user_portrait_ending2,代码行数:30,代码来源:utils.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: show_user_operation_index
def show_user_operation_index(admin_user, start_ts, end_ts):
results = {}
if admin_user == '' and start_ts == '' and end_ts == '':
query_body = {
'query': {
'match_all':{}
},
'size': MAX_VALUE
}
elif admin_user and start_ts and end_ts:
start = datetime2ts(start_ts) - 1
end = datetime2ts(end_ts) + DAY
query_body = {
'query':{
'bool':{
'must':[
{'term': {'admin_user': admin_user}},
{'range':{'timestamp': {'gte': start, 'lt': end}}}
]
}
},
'size': MAX_VALUE
}
elif admin_user and (start_ts == '' or end_ts == ''):
query_body = {
'query':{
'term':{'admin_user': admin_user}
},
'size': MAX_VALUE
}
elif admin_user == '' and start_ts != '' and end_ts != '':
start = datetime2ts(start_ts) - 1
end = datetime2ts(end_ts) + DAY
query_body = {
'query':{
'range':{'timestamp':{'gte': start, 'lt': end}}
},
'size': MAX_VALUE
}
try:
results = es_operation.search(index=operation_index_name, doc_type=operation_index_type, body=query_body)['hits']['hits']
except:
results = []
return_results = []
all_operation_dict = {}
stat_operation_list = ['rank_count', 'compute_count', 'sentiment_count',\
'recomment_count', 'detect_count', 'analysis_count', 'tag_count', 'network_count', 'sensing_count']
for item in results:
source = item['_source']
return_results.append(source)
for stat_item in stat_operation_list:
try:
all_operation_dict[stat_item] += source[stat_item]
except:
all_operation_dict[stat_item] = source[stat_item]
sort_return_results = sorted(return_results, key=lambda x:x['timestamp'], reverse=False)
if sort_return_results:
sort_return_results.append(all_operation_dict)
return sort_return_results
开发者ID:huxiaoqian,项目名称:user_portrait_ending2,代码行数:59,代码来源:utils.py
示例7: 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
示例8: get_psycho_status
def get_psycho_status(uid_list):
results = {}
uid_sentiment_dict = {}
#time for es_flow_text
now_ts = time.time()
now_date_ts = datetime2ts(ts2datetime(now_ts))
#run_type
if RUN_TYPE == 0:
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
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=['uid', 'sentiment'])['hits']['hits']
except:
flow_text_exist = []
for flow_text_item in flow_text_exist:
uid = flow_text_item['fields']['uid'][0]
sentiment = flow_text_item['fields']['sentiment'][0]
if uid in uid_sentiment_dict:
try:
uid_sentiment_dict[uid][str(sentiment)] += 1
except:
uid_sentiment_dict[uid][str(sentiment)] = 1
else:
uid_sentiment_dict[uid] = {str(sentiment): 1}
#compute first and second psycho_status
for uid in uid_list:
results[uid] = {'first':{}, 'second':{}}
try:
user_sentiment_result = uid_sentiment_dict[uid]
except:
user_sentiment_result = {}
all_count = sum(user_sentiment_result.values())
#compute second level sentiment---negative type sentiment
second_sentiment_count_list = [user_sentiment_result[item] for item in user_sentiment_result if item in SENTIMENT_SECOND]
second_sentiment_all_count = sum(second_sentiment_count_list)
for sentiment_item in SENTIMENT_SECOND:
try:
results[uid]['second'][sentiment_item] = float(user_sentiment_result[sentiment_item]) / all_count
except:
results[uid]['second'][sentiment_item] = 0
#compute first level sentiment---middle, postive, negative
user_sentiment_result['7'] = second_sentiment_all_count
for sentiment_item in SENTIMENT_FIRST:
try:
sentiment_ratio = float(user_sentiment_result[sentiment_item]) / all_count
except:
sentiment_ratio = 0
results[uid]['first'][sentiment_item] = sentiment_ratio
return results
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:55,代码来源:utils.py
示例9: get_social_inter_content
def get_social_inter_content(uid1, uid2, type_mark):
weibo_list = []
#get two type relation about uid1 and uid2
#search weibo list
now_ts = int(time.time())
#run_type
if RUN_TYPE == 1:
now_date_ts = datetime2ts(ts2datetime(now_ts))
else:
now_date_ts = datetime2ts(RUN_TEST_TIME)
#uid2uname
uid2uname = {}
try:
portrait_result = es_user_portrait.mget(index=portrait_index_name, doc_type=portrait_index_type ,\
body={'ids': [uid1, uid2]}, _source=False, fields=['uid', 'uname'])['docs']
except:
portrait_result = []
for item in portrait_result:
uid = item['_id']
if item['found'] == True:
uname = item['fields']['uname'][0]
uid2uname[uid] = uname
else:
uid2uname[uid] = 'unknown'
#iter date to search weibo list
for i in range(7, 0, -1):
iter_date_ts = now_date_ts - i*DAY
iter_date = ts2datetime(iter_date_ts)
flow_text_index_name = flow_text_index_name_pre + str(iter_date)
query = []
query.append({'bool':{'must':[{'term':{'uid':uid1}}, {'term':{'directed_uid': int(uid2)}}]}})
if type_mark=='out':
query.append({'bool':{'must':[{'term':{'uid':uid2}}, {'term':{'directed_uid': int(uid1)}}]}})
try:
flow_text_result = es_flow_text.search(index=flow_text_index_name, doc_type=flow_text_index_type,\
body={'query': {'bool':{'should': query}}, 'sort':[{'timestamp':{'order': 'asc'}}], 'size':MAX_VALUE})['hits']['hits']
except:
flow_text_result = []
for flow_text in flow_text_result:
source = flow_text['_source']
weibo = {}
weibo['timestamp'] = source['timestamp']
weibo['ip'] = source['ip']
weibo['geo'] = source['geo']
weibo['text'] = '\t'.join(source['text'].split('&'))
weibo['uid'] = source['uid']
weibo['uname'] = uid2uname[weibo['uid']]
weibo['directed_uid'] = str(source['directed_uid'])
weibo['directed_uname'] = uid2uname[str(source['directed_uid'])]
weibo_list.append(weibo)
return weibo_list
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:53,代码来源:utils.py
示例10: 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
示例11: read_flow_text_sentiment
def read_flow_text_sentiment(uid_list):
"""
读取用户微博(返回结果有微博情绪标签):
输入数据:uid_list(字符串型列表)
输出数据:word_dict(用户分词结果字典),weibo_list(用户微博列表)
word_dict示例:{uid1:{'w1':f1,'w2':f2...}...}
weibo_list示例:[[uid1,text1,s1,ts1],[uid2,text2,s2,ts2],...](每一条记录对应四个值:uid、text、sentiment、timestamp)
"""
word_dict = dict() # 词频字典
weibo_list = [] # 微博列表
now_ts = time.time()
now_date_ts = datetime2ts(ts2datetime(now_ts))
now_date_ts = datetime2ts("2013-09-08")
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", "sentiment", "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")
sentiment = int(flow_text_item["fields"]["sentiment"][0])
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, sentiment, ts])
return word_dict, weibo_list
开发者ID:jianjian0dandan,项目名称:sensitive_user_portrait,代码行数:50,代码来源:weibo_api.py
示例12: 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
示例13: 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
示例14: recommentation_in_auto
def recommentation_in_auto(seatch_date, submit_user):
results = []
#run type
if RUN_TYPE == 1:
now_date = ts2datetime(time.time() - DAY)
else:
now_date = ts2datetime(datetime2ts(RUN_TEST_TIME) - DAY)
recomment_hash_name = 'recomment_' + now_date + '_auto'
recomment_influence_hash_name = 'recomment_' + now_date + '_influence'
recomment_sensitive_hash_name = 'recomment_' + now_date + '_sensitive'
recomment_compute_hash_name = 'compute'
#step1: get auto
auto_result = r.hget(recomment_hash_name, 'auto')
if auto_result:
auto_user_list = json.loads(auto_result)
else:
auto_user_list = []
#step2: get admin user result
admin_result = r.hget(recomment_hash_name, submit_user)
if admin_result:
admin_user_list = json.loads(admin_result)
else:
admin_user_list = []
#step3: get union user and filter compute/influence/sensitive
union_user_auto_set = set(auto_user_list) | set(admin_user_list)
influence_user = set(r.hkeys(recomment_influence_hash_name))
sensitive_user = set(r.hkeys(recomment_sensitive_hash_name))
compute_user = set(r.hkeys(recomment_compute_hash_name))
filter_union_user = union_user_auto_set - (influence_user | sensitive_user | compute_user)
auto_user_list = list(filter_union_user)
#step4: get user detail
results = get_user_detail(now_date, auto_user_list, 'show_in', 'auto')
return results
开发者ID:huxiaoqian,项目名称:user_portrait_0324,代码行数:33,代码来源:utils.py
示例15: new_get_activeness_trend
def new_get_activeness_trend(uid, time_segment):
results = {}
try:
activeness_history = ES_COPY_USER_PORTRAIT.get(index=COPY_USER_PORTRAIT_ACTIVENESS, doc_type=COPY_USER_PORTRAIT_ACTIVENESS_TYPE,\
id=uid)['_source']
except:
activeness_history = {}
if activeness_history:
results = get_evaluate_trend(activeness_history, 'activeness')
else:
results = {}
#deal results for situation---server power off
new_time_list = []
new_count_list = []
new_results = {}
now_time_ts = time.time()
now_date_ts = datetime2ts(ts2datetime(now_time_ts))
for i in range(time_segment, 0, -1):
iter_date_ts = now_date_ts - i * DAY
try:
date_count = results[iter_date_ts]
except:
date_count = 0
new_time_list.append(iter_date_ts)
new_count_list.append(date_count)
new_results = {'timeline': new_time_list, 'evaluate_index': new_count_list}
return new_results
开发者ID:huxiaoqian,项目名称:user_portrait_ending2,代码行数:27,代码来源:new_search.py
示例16: 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
示例17: get_db_num
def get_db_num(timestamp):
date = ts2datetime(timestamp)
date_ts = datetime2ts(date)
db_number = ((date_ts - r_beigin_ts) / (DAY * 7)) % 2 + 1
if RUN_TYPE == 0:
db_number = 1
return db_number
开发者ID:huxiaoqian,项目名称:revised_user_portrait,代码行数:7,代码来源:new_search.py
示例18: search_sentiment_all_keywords_task
def search_sentiment_all_keywords_task(submit_date, keywords_string, submit_user, start_date, end_date, status):
results = []
query_list = []
if submit_date:
submit_ts_start = datetime2ts(submit_date)
submit_ts_end = submit_ts_start + DAY
query_list.append({'range': {'submit_ts': {'gte': submit_ts_start, 'lt':submit_ts_end}}})
if keywords_string:
keywords_list = keywords_string.split(',')
query_list.append({'terms':{'query_keywords': keywords_list}})
if submit_user:
query_list.append({'term': {'submit_user': submit_user}})
if start_date:
start_s_ts = datetime2ts(start_date)
if end_date:
start_e_ts = datetime2ts(end_date)
else:
start_e_ts = start_s_ts + DAY * 30
start_date_nest_body_list = [ts2datetime(ts) for ts in range(start_s_ts, start_e_ts + DAY, DAY)]
query_list.append({'terms':{'start_date': start_date_nest_body_list}})
if end_date:
end_e_ts = datetime2ts(end_date)
if start_date:
end_s_ts = datetime2ts(start_date)
else:
end_s_ts = end_e_ts - DAY * 30
end_date_nest_body_list = [ts2datetime(ts) for ts in range(end_s_ts, end_e_ts + DAY, DAY)]
query_list.append({'terms': {'end_date': end_date_mest_body_list}})
if status:
query_list.append({'term': {'status': status}})
try:
task_results = es_sentiment_task.search(index=sentiment_keywords_index_name, \
doc_type=sentiment_keywords_index_type, body={'query':{'bool':{'must':query_list}}})['hits']['hits']
except:
task_results = []
for task_item in task_results:
task_source = task_item['_source']
task_id = task_source['task_id']
start_date = task_source['start_date']
end_date = task_source['end_date']
keywords = task_source['query_keywords']
submit_ts = ts2date(task_source['submit_ts'])
status = task_source['status']
segment = task_source['segment']
results.append([task_id, start_date, end_date, keywords, submit_ts, status, segment])
return results
开发者ID:ferrero-zhang,项目名称:user_portrait_0324,代码行数:47,代码来源:utils.py
示例19: get_influence_content
def get_influence_content(uid, timestamp_from, timestamp_to):
weibo_list = []
#split timestamp range to new_range_dict_list
from_date_ts = datetime2ts(ts2datetime(timestamp_from))
to_date_ts = datetime2ts(ts2datetime(timestamp_to))
new_range_dict_list = []
if from_date_ts != to_date_ts:
iter_date_ts = from_date_ts
while iter_date_ts < to_date_ts:
iter_next_date_ts = iter_date_ts + DAY
new_range_dict_list.append({'range':{'timestamp':{'gte':iter_date_ts, 'lt':iter_next_date_ts}}})
iter_date_ts = iter_next_date_ts
if new_range_dict_list[0]['range']['timestamp']['gte'] < timestamp_from:
new_range_dict_list[0]['range']['timestamp']['gte'] = timestamp_from
if new_range_dict_list[-1]['range']['timestamp']['lt'] > timestamp_to:
new_range_dict_list[-1]['range']['timestamp']['lt'] = timestamp_to
else:
new_range_dict_list = [{'range':{'timestamp':{'gte':timestamp_from, 'lt':timestamp_to}}}]
#iter date to search flow_text
iter_result = []
for range_item in new_range_dict_list:
range_from_ts = range_item['range']['timestamp']['gte']
range_from_date = ts2datetime(range_from_ts)
flow_text_index_name = flow_text_index_name_pre + range_from_date
query = []
query.append({'term':{'uid':uid}})
query.append(range_item)
try:
flow_text_exist = es_flow_text.search(index=flow_text_index_name, doc_type=flow_text_index_type,\
body={'query':{'bool':{'must': query}}, 'sort':[{'timestamp':'asc'}]})['hits']['hits']
except:
flow_text_exist = []
iter_result.extend(flow_text_exist)
# get weibo list
for item in flow_text_exist:
source = item['_source']
weibo = {}
weibo['timestamp'] = ts2date(source['timestamp'])
weibo['ip'] = source['ip']
weibo['text'] = source['text']
if source['geo']:
weibo['geo'] = '\t'.join(source['geo'].split('&'))
else:
weibo['geo'] = ''
weibo_list.append(weibo)
return weibo_list
开发者ID:huxiaoqian,项目名称:user_portrait,代码行数:47,代码来源:utils.py
示例20: get_db_num
def get_db_num(timestamp):
date = ts2datetime(timestamp)
date_ts = datetime2ts(date)
db_number = 2 - (((date_ts - begin_ts) / (DAY * 7))) % 2
#run_type
if RUN_TYPE == 0:
db_number = 1
return db_number
开发者ID:jianjian0dandan,项目名称:user_portrait_0324,代码行数:8,代码来源:utils.py
注:本文中的user_portrait.time_utils.datetime2ts函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论