Esempio n. 1
0
def monitor_query():

    term = request.get_json()

    if term.has_key('keywords'):
        keywords = term['keywords']
    else:
        keywords = []
    if term.has_key('user'):
        user = term['user']
    else:
        user = '******'
    if term.has_key('from_ts'):
        from_ts = datehour2ts(term['from_ts'])
    else:
        from_ts = time.time()
    if term.has_key('to_ts'):
        to_ts = datehour2ts(term['to_ts'])
    else:
        if term.has_key('to_num'):
            to_num = term['to_num']
        else:
            to_num = 6
        to_ts = from_ts - to_num * 3600
    if term.has_key('page'):
        page = term['page']
    else:
        page = 1

    results = query_monitor(keywords=keywords,
                            user=user,
                            from_ts=from_ts,
                            to_ts=to_ts)

    content = []
    for item in results:
        item_dict = {}
        item_dict['task_name'] = item["_source"]['task_name']
        item_dict['start_time'] = ts2datetime_full(
            float(item["_source"]['from_date']))
        item_dict['end_time'] = ts2datetime_full(
            float(item["_source"]['to_date']))
        item_dict['create_user'] = item["_source"]['create_user']
        item_dict['event_detail'] = item["_source"]['event_detail']
        item_dict['create_at'] = ts2datetime_full(
            float(item["_source"]['create_at']))
        item_dict['delete'] = item["_source"]['delete']
        item_dict['processing_status'] = item["_source"]['processing_status']
        item_dict['weixin_stat'] = item["_source"]['weixin_count']
        item_dict['xinwen_stat'] = item["_source"]['baidunews_count']
        item_dict['weibo_stat'] = item["_source"]['weibo_count']

        content.append(item_dict)

    return_results = dict()
    return_results['page_count'] = len(results)
    return_results['list'] = content[5 * (page - 1):5 * page]

    return json.dumps(return_results)
Esempio n. 2
0
def map_calculate():

    term = request.get_json()

    if term.has_key('keywords'):
    	keywords = term['keywords']
    else:
    	keywords = []
    if term.has_key('sort'):
    	sort = term['sort']
    else:
    	sort = 'heat'
    if term.has_key('place'):
    	place = term['place']
    else:
    	place = '*'
    if term.has_key('from_ts'):
    	from_ts = datehour2ts(term['from_ts'])
    else:
    	from_ts = time.time()
    if term.has_key('to_ts'):
    	to_ts = datehour2ts(term['to_ts'])
    else:
	    if term.has_key('to_num'):
	    	to_num = term['to_num']
	    else:
	    	to_num = 180
	    to_ts = from_ts-to_num*3600*24
    if term.has_key('page'):
		page = term['page']
    else:
    	page = 1

    results, count_mid, province_dict, city_dict = query_sensing(keywords=keywords, place=place, sort=sort, from_ts=from_ts, to_ts=to_ts)


    content = []
    for item in results:
    	item_dict = {}
    	item_dict['name'] = item["_source"]['uid']
        item_dict['date'] = ts2datetime_full(item["_source"]['timestamp'])
        item_dict['initiator'] = item["_source"]['initiator']
        item_dict['heat'] = item["_source"]['heat']
        item_dict['geo'] = item["_source"]['geo']
        item_dict['keywords_string'] = item["_source"]['keywords_string']
        item_dict['status'] = item["_source"]['status']
        content.append(item_dict)


    return_results = dict()
    return_results['event_count'] = count_mid
    return_results['place_count'] = len(province_dict)
    return_results['color'] = city_dict
    return_results['list'] = content[5*(page-1):5*page]

    print count_mid, province_dict, city_dict

    return json.dumps(return_results)