Пример #1
0
def drewi():
    """
        获得全国各省数据
        :return: 各省数据
    """
    cities = list(
        getData(
            """SELECT area_name, map_name FROM area_china WHERE area_level=1;"""
        ))
    # 获取全国各省二月累计确诊数
    data = list(
        getData(
            """select province_name, SUM(confirmed_count) as province_confirmed from covid_data_2017
                        where day(update_time ) = 29 group by province_name;"""
        ))
    map_chart = []
    map_chart_list = []
    for x in data:
        map_chart.append({'name': x[0], 'value': int(x[1])})
    for confirmed in map_chart:
        for provice in cities:
            if confirmed['name'] == provice[0]:
                map_chart = {'name': provice[1], 'value': confirmed['value']}
                map_chart_list.append(map_chart)
    return map_chart_list
Пример #2
0
def get_chart1_data():
    # # 绘制二月每日全国数据
    chart1_info = {}
    chart1_date_list = []
    chart1_confirm_list = []
    chart1_heal_list = []
    chart1_dead_list = []
    chart1_today_confirm_list = []
    trend_data = list(
        getData(
            """select SUM(confirmed_add) as today_confirm,SUM(confirmed_count) as confirm,
                         SUM(cured_count)as heal,SUM(dead_count) as dead, update_time from covid_data_2017
                          WHERE DAY(update_time) != 13 GROUP BY update_time;"""
        ))
    for date in trend_data:
        chart1_date_list.append(date[4].strftime('%m-%d'))
        chart1_confirm_list.append(int(date[1]))
        chart1_heal_list.append(int(date[2]))
        chart1_dead_list.append(int(date[3]))
        chart1_today_confirm_list.append(int(date[0]))
    chart1_info['x_name'] = chart1_date_list
    chart1_info['confirm'] = chart1_confirm_list
    chart1_info['heal'] = chart1_heal_list
    chart1_info['dead'] = chart1_dead_list
    chart1_info['today_confirm'] = chart1_today_confirm_list
    return chart1_info
Пример #3
0
def migration():
    data = list(
        getData(
            """SELECT map_name, `value` FROM (SELECT source_province_name, target_province_name, `value`
                    FROM migrate_data_2017 WHERE source_province_name="湖北省") as a
                    JOIN area_china ON a.target_province_name=area_china.area_name;"""
        ))
    migrate_list = []
    for i in data:
        migrate_list.append(['湖北', i[0], i[1]])
    return migrate_list
Пример #4
0
def ncov_totalcount(request):
    ncov_data = list(
        getData(
            """SELECT SUM(confirmed_count) as total, (SUM(confirmed_count)-SUM(cured_count)-SUM(dead_count))
                as now_confirmed FROM covid_data_2017 WHERE DAY(update_time)=29 GROUP BY update_time;"""
        ))
    confirmedCount = ncov_data[0][0]
    confirmedNow = ncov_data[0][1]
    return JsonResponse({
        'confirmedCount': confirmedCount,
        'confirmedNow': confirmedNow
    })
Пример #5
0
def get_chart6_data():
    chart6_info = []
    gx_city_confirm = list(
        getData(
            """SELECT SUM(confirmed_count), city_name FROM covid_data_2017 WHERE
                        province_name = "广西壮族自治区" and DAY(update_time)=29 GROUP BY city_name;"""
        ))
    for data in gx_city_confirm:
        dic = {'value': int(data[0]), 'name': data[1]}
        chart6_info.append(dic)
        del dic
    return chart6_info
Пример #6
0
def get_chart4_data():
    gx_everyday_add = list(
        getData(
            """SELECT SUM(confirmed_add), update_time FROM covid_data_2017 WHERE
                    province_name = "广西壮族自治区" GROUP BY update_time;"""))
    chart4_info = {}
    days = []
    confirmed_add = []
    for data in gx_everyday_add:
        days.append(data[1].strftime('%m-%d'))
        confirmed_add.append(int(data[0]))
    chart4_info['days'] = days
    chart4_info['today_confirmed'] = confirmed_add
    return chart4_info
Пример #7
0
def get_chart2_data():
    chart2_info = []
    migra_confirm = list(
        getData(
            """SELECT `value`, confirmed_count, target_province_name FROM(SELECT migrate_data_2017.target_province_name,
         `value` FROM migrate_data_2017 WHERE source_province_name = '湖北省')as a JOIN (SELECT province_name,
          SUM(confirmed_count) as confirmed_count FROM covid_data_2017 WHERE DAY(update_time)=29 AND 
           province_name != '湖北省' GROUP BY province_name) AS b ON a.target_province_name = b.province_name;"""
        ))
    for data in migra_confirm:
        lists = list(data)
        lists[1] = int(lists[1])
        chart2_info.append(lists)
    return chart2_info
Пример #8
0
def drawmap():
    """
        获得各省内各市的疫情数据,由于Echarts和pyechart传入的地市名成不一致,Echarts传入的是市名比如:‘郑州’,
        而pyecharts传入的为‘郑州市’所以地图名不用再做之前的处理。
        :return: 各市级数据
    """
    # 获取城市名
    province = list(
        getData(
            """SELECT father_code, map_name FROM area_china WHERE area_level=1;"""
        ))
    cities = list(
        getData(
            """SELECT area_name, father_code FROM area_china WHERE area_level=2"""
        ))
    # 获取全国各城市二月累计确诊数
    data = getData(
        """select SUM(confirmed_count) as province_confirmed from covid_data_2017
                        where day(update_time) = 29 group by province_name;""")
    confirmed = []
    for x in data:
        confirmed.append(int(x[0]))
    map_chart_list = []
    for i in range(len(data)):
        map_chart_list.append([{
            'name': cities[i][0],
            'value': str(confirmed[i])
        }, cities[i][1]])
    get_all_city_map_data = {}
    for province_code in province:
        province_citise = []
        for city in map_chart_list:
            if city[1] == province_code[0]:
                province_citise.append(city[0])
        get_all_city_map_data[province_code[1]] = province_citise
    return get_all_city_map_data
Пример #9
0
def get_chart5_data():
    gx_city_confirm = list(
        getData(
            """SELECT SUM(confirmed_count), city_name FROM covid_data_2017 WHERE
                        province_name = "广西壮族自治区" and DAY(update_time)=29 GROUP BY city_name;"""
        ))
    chart5_info = {}
    cities = []
    confirmed_count = []
    for data in gx_city_confirm:
        cities.append(data[1])
        confirmed_count.append(int(data[0]))
        chart5_info['cities'] = cities
        chart5_info['confirmed'] = confirmed_count
    return chart5_info
Пример #10
0
def get_chart3_data():
    data = getData(
        """SELECT SUM(dead_count)/SUM(confirmed_count) as dead_rate FROM covid_data_2017
                        WHERE DAY(update_time)=29 GROUP BY update_time;""")
    chart3_info = data[0][0] * 100
    return chart3_info