Ejemplo n.º 1
0
def city_map_view():
    topic = request.args.get('topic', '')
    during = request.args.get('pointInterval', 60 * 60) # 默认查询时间粒度为3600秒
    during = int(during)
    end_ts = request.args.get('end_ts', '')
    end_ts = long(end_ts)
    start_ts = request.args.get('start_ts', '')
    start_ts = long(start_ts)
    ts_arr = []
    results = []
    print time.time(), topic.encode('utf-8'), during, end_ts, start_ts
    top_city_weibo = get_city_weibo(topic, start_ts, end_ts)
    items = db.session.query(CityRepost).filter(CityRepost.topic == topic).all()
    print time.time(), 'get repost done'
    if items:
        for item in items:
            r = {}
            r['original'] = item.original
            r['topic'] = item.topic
            r['mid'] = item.mid
            r['ts'] = item.ts
            r['origin_location'] = item.origin_location
            r['repost_location'] = item.repost_location
            if (r['origin_location'] == u'未知') or (r['repost_location'] == u'未知'):
                continue
            if (r['origin_location'] == u'海外') or (r['repost_location'] == u'海外'):
                continue

            ts_arr.append(r['ts'])
            results.append(r)
        ts_arr = sorted(list(set(ts_arr)))
        print time.time(), 'endfor'
        raw_ts_series, raw_groups = partition_time(ts_arr, results, during)
        print time.time(), 'step 1 done'
        ts_series, groups = select_groups(raw_ts_series, raw_groups, start_ts, end_ts)
        print time.time(), 'step 2 done'
        # draw_circle_data = map_circle_data(groups, True)
        max_repost_num, draw_line_data = map_line_data(groups, True)
        print time.time(), 'step 3 done'
        in_out_results = work_in_out(draw_line_data)
        print time.time(), 'step 4 done'
        repost_series, origin_series, post_series, statistic_data = statistics_data(groups, draw_line_data, True)
        print time.time(), 'step 5 done'
        return json.dumps({'draw_line_data': draw_line_data, 'in_out_results': in_out_results,'statistics_data': statistic_data, 'top_city_weibo': top_city_weibo})

        '''
        return json.dumps({'ts_arr':ts_arr, 'results':results, 'ts_series':ts_series, 'groups': groups, \
                'draw_circle_data':draw_circle_data, 'draw_line_data': draw_line_data, 'max_repost_num': max_repost_num, \
                'repost_series':repost_series, 'origin_series':origin_series, 'post_series':post_series, 'statistics_data':statistic_data})
        '''
    else:
            return json.dumps({'draw_line_data': [], 'in_out_results': [],'statistics_data': [], 'top_city_weibo': top_city_weibo})
Ejemplo n.º 2
0
def in_out_map_news():
    topic = request.args.get('topic', '')
    during = request.args.get('pointInterval', 60 * 60) # 默认查询时间粒度为3600秒
    during = int(during)
    end_ts = request.args.get('end_ts', '')
    end_ts = long(end_ts)
    start_ts = request.args.get('start_ts', '')
    start_ts = long(start_ts)
    ts_arr = []
    results = []

    top_city_news = get_city_news(topic, start_ts, end_ts)
    # top_city_news = {city:[weibo1,weibo2...],...}

    items = db.session.query(CityRepostNews).filter(CityRepostNews.topic == topic).all()
    if items:
        for item in items:
            r = {}
            r['original'] = item.original
            r['topic'] = item.topic
            r['mid'] = item.mid
            r['ts'] = item.ts
            r['origin_location'] = item.origin_location
            r['repost_location'] = item.repost_location
            if (r['origin_location'] == u'未知') or (r['repost_location'] == u'未知'):
                continue
            if (r['origin_location'] == u'海外') or (r['repost_location'] == u'海外'):
                continue

            ts_arr.append(r['ts'])
            results.append(r)
        ts_arr = sorted(list(set(ts_arr)))
        raw_ts_series, raw_groups = partition_time(ts_arr, results, during)
        ts_series, groups = select_groups(raw_ts_series, raw_groups, start_ts, end_ts)
        # draw_circle_data = map_circle_data(groups, True)
        max_repost_num, draw_line_data = map_line_data(groups, True)
        in_out_results = work_in_out(draw_line_data)
        repost_series, origin_series, post_series, statistic_data = statistics_data(groups, draw_line_data, True)
        return json.dumps({'draw_line_data': draw_line_data, 'in_out_results': in_out_results, 'statistics_data': statistic_data, 'top_city_news': top_city_news})

        '''
        return json.dumps({'ts_arr':ts_arr, 'results':results, 'ts_series':ts_series, 'groups': groups, \
                'draw_circle_data':draw_circle_data, 'draw_line_data': draw_line_data, 'max_repost_num': max_repost_num, \
                'repost_series':repost_series, 'origin_series':origin_series, 'post_series':post_series, 'statistics_data':statistic_data})
        '''
    else:
        return json.dumps({'draw_line_data': [], 'in_out_results': [],'statistics_data': [], 'top_city_news': top_city_news})
Ejemplo n.º 3
0
def in_out_map_news():
    topic = request.args.get('topic', '')
    during = request.args.get('pointInterval', 60 * 60)  # 默认查询时间粒度为3600秒
    during = int(during)
    end_ts = request.args.get('end_ts', '')
    end_ts = long(end_ts)
    start_ts = request.args.get('start_ts', '')
    start_ts = long(start_ts)
    ts_arr = []
    results = []

    top_city_news = get_city_news(topic, start_ts, end_ts)
    # top_city_news = {city:[weibo1,weibo2...],...}

    items = db.session.query(CityRepostNews).filter(
        CityRepostNews.topic == topic).all()
    if items:
        for item in items:
            r = {}
            r['original'] = item.original
            r['topic'] = item.topic
            r['mid'] = item.mid
            r['ts'] = item.ts
            r['origin_location'] = item.origin_location
            r['repost_location'] = item.repost_location
            if (r['origin_location'] == u'未知') or (r['repost_location']
                                                   == u'未知'):
                continue
            if (r['origin_location'] == u'海外') or (r['repost_location']
                                                   == u'海外'):
                continue

            ts_arr.append(r['ts'])
            results.append(r)
        ts_arr = sorted(list(set(ts_arr)))
        raw_ts_series, raw_groups = partition_time(ts_arr, results, during)
        ts_series, groups = select_groups(raw_ts_series, raw_groups, start_ts,
                                          end_ts)
        # draw_circle_data = map_circle_data(groups, True)
        max_repost_num, draw_line_data = map_line_data(groups, True)
        in_out_results = work_in_out(draw_line_data)
        repost_series, origin_series, post_series, statistic_data = statistics_data(
            groups, draw_line_data, True)
        return json.dumps({
            'draw_line_data': draw_line_data,
            'in_out_results': in_out_results,
            'statistics_data': statistic_data,
            'top_city_news': top_city_news
        })
        '''
        return json.dumps({'ts_arr':ts_arr, 'results':results, 'ts_series':ts_series, 'groups': groups, \
                'draw_circle_data':draw_circle_data, 'draw_line_data': draw_line_data, 'max_repost_num': max_repost_num, \
                'repost_series':repost_series, 'origin_series':origin_series, 'post_series':post_series, 'statistics_data':statistic_data})
        '''
    else:
        return json.dumps({
            'draw_line_data': [],
            'in_out_results': [],
            'statistics_data': [],
            'top_city_news': top_city_news
        })
Ejemplo n.º 4
0
def city_map_view():
    topic = request.args.get('topic', '')
    during = request.args.get('pointInterval', 60 * 60)  # 默认查询时间粒度为3600秒
    during = int(during)
    end_ts = request.args.get('end_ts', '')
    end_ts = long(end_ts)
    start_ts = request.args.get('start_ts', '')
    start_ts = long(start_ts)
    ts_arr = []
    results = []
    print time.time(), topic.encode('utf-8'), during, end_ts, start_ts
    top_city_weibo = get_city_weibo(topic, start_ts, end_ts)
    items = db.session.query(CityRepost).filter(
        CityRepost.topic == topic).all()
    print time.time(), 'get repost done'
    if items:
        for item in items:
            r = {}
            r['original'] = item.original
            r['topic'] = item.topic
            r['mid'] = item.mid
            r['ts'] = item.ts
            r['origin_location'] = item.origin_location
            r['repost_location'] = item.repost_location
            if (r['origin_location'] == u'未知') or (r['repost_location']
                                                   == u'未知'):
                continue
            if (r['origin_location'] == u'海外') or (r['repost_location']
                                                   == u'海外'):
                continue

            ts_arr.append(r['ts'])
            results.append(r)
        ts_arr = sorted(list(set(ts_arr)))
        print time.time(), 'endfor'
        raw_ts_series, raw_groups = partition_time(ts_arr, results, during)
        print time.time(), 'step 1 done'
        ts_series, groups = select_groups(raw_ts_series, raw_groups, start_ts,
                                          end_ts)
        print time.time(), 'step 2 done'
        # draw_circle_data = map_circle_data(groups, True)
        max_repost_num, draw_line_data = map_line_data(groups, True)
        print time.time(), 'step 3 done'
        in_out_results = work_in_out(draw_line_data)
        print time.time(), 'step 4 done'
        repost_series, origin_series, post_series, statistic_data = statistics_data(
            groups, draw_line_data, True)
        print time.time(), 'step 5 done'
        return json.dumps({
            'draw_line_data': draw_line_data,
            'in_out_results': in_out_results,
            'statistics_data': statistic_data,
            'top_city_weibo': top_city_weibo
        })
        '''
        return json.dumps({'ts_arr':ts_arr, 'results':results, 'ts_series':ts_series, 'groups': groups, \
                'draw_circle_data':draw_circle_data, 'draw_line_data': draw_line_data, 'max_repost_num': max_repost_num, \
                'repost_series':repost_series, 'origin_series':origin_series, 'post_series':post_series, 'statistics_data':statistic_data})
        '''
    else:
        return json.dumps({
            'draw_line_data': [],
            'in_out_results': [],
            'statistics_data': [],
            'top_city_weibo': top_city_weibo
        })