コード例 #1
0
def seoul_seq():
    if request.method == 'GET':
        mpl.rc('font', family='Malgun Gothic')
        mpl.rc('axes', unicode_minus=False)
        menu = {'ho':0, 'da':1, 'ml':0, 'se':0, 'co':1, 'cg':0, 'cr':0, 'st':0, 'wc':0}

        start_date = request.args.get('startDate', '2020-01-01')
        end_date = request.args.get('endDate', datetime.now().strftime('%Y-%m-%d'))
        cdf_raw, gu_list = cu.make_corona_raw_df(start_date, end_date)

        gu_str = request.args.get('gu', '강서구 양천구 영등포구')
        selected_gu = gu_str.split()
        img_file = os.path.join(current_app.root_path, 'static/img/seoul_seq.png')
        plt.figure(figsize=(12,6))
        for gu in selected_gu:
            cdf_raw[gu].plot(grid=True)
        plt.title('서울시 자치구별 확진자 추이', fontsize=15)
        plt.legend()
        plt.savefig(img_file)
        mtime = int(os.stat(img_file).st_mtime)
        gu_str = ', '.join(gu for gu in selected_gu)

        return render_template('covid/seoul_seq.html', menu=menu, weather=get_weather_main(),
                                mtime=mtime, gu_list=gu_list, gu_str=gu_str,
                                start_date=start_date, end_date=end_date)

    else:
        start_date = request.form['startDate'] if request.form['startDate'] else '2020-01-01'
        end_date = request.form['endDate'] if request.form['endDate'] else datetime.now().strftime('%Y-%m-%d')
        selected_gu = request.form.getlist('gu') if request.form.getlist('gu') else ['강서구', '양천구', '영등포구']
        gu_str = ' '.join(gu for gu in selected_gu)
        current_app.logger.debug(f'{start_date} ~ {end_date}, {gu_str}')
        return redirect(url_for('covid_bp.seoul_seq')+f'?gu={gu_str}&startDate={start_date}&endDate={end_date}')
コード例 #2
0
def seoul_map(option):
    menu = {'ho':0, 'da':1, 'ml':0, 'se':0, 'co':1, 'cg':0, 'cr':0, 'st':0, 'wc':0}
    geo_data = json.load(open('./static/data/skorea_municipalities_geo_simple.json', encoding='utf8'))
    
    start_date = request.args.get('startDate', '2020-01-01')
    end_date = request.args.get('endDate', datetime.now().strftime('%Y-%m-%d'))
    cdf_raw, _ = cu.make_corona_raw_df(start_date, end_date)
    cdf = cu.make_corona_df(cdf_raw)

    html_file = os.path.join(current_app.root_path, 'static/img/seoul_corona.html')
    map = folium.Map(location=[37.5502, 126.982], zoom_start=11, tiles='Stamen Toner')
    if option == 'ratio':
        folium.Choropleth(geo_data = geo_data,
               data = cdf['천명당 확진자 수'],
               columns = [cdf.index, cdf['천명당 확진자 수']],
               fill_color = 'YlGnBu',
               key_on = 'feature.id').add_to(map)
    else:
        folium.Choropleth(geo_data = geo_data,
               data = cdf['누적'],
               columns = [cdf.index, cdf['누적']],
               fill_color = 'PuRd',
               key_on = 'feature.id').add_to(map)
    map.save(html_file)
    mtime = int(os.stat(html_file).st_mtime)
    option_str = '천명당 확진자 수' if option == 'ratio' else '누적 확진자 수'

    return render_template('covid/seoul_map.html', menu=menu, weather=get_weather_main(),
                            mtime=mtime, option_str=option_str)
コード例 #3
0
def seoul_comp():
    if request.method == 'GET':
        mpl.rc('font', family='Malgun Gothic')
        mpl.rc('axes', unicode_minus=False)
        menu = {
            'ho': 0,
            'da': 1,
            'ml': 0,
            'se': 0,
            'co': 1,
            'cg': 0,
            'cr': 0,
            'wc': 0,
            'cf': 0,
            'ac': 0,
            're': 0,
            'cu': 0
        }

        start_date = request.args.get('startDate', '2020-01-01')
        end_date = request.args.get('endDate',
                                    datetime.now().strftime('%Y-%m-%d'))
        cdf_raw, _ = cu.make_corona_raw_df(start_date, end_date)
        cdf = cu.make_corona_df(cdf_raw)

        month = request.args.get('month', 'ratio')
        img_file = os.path.join(current_app.root_path,
                                'static/img/seoul_comp.png')
        plt.figure(figsize=(12, 8))
        if month == 'ratio':
            cdf['천명당 확진자 수'].sort_values().plot(kind='barh', grid=True)
            plt.title('자치구별 천명당 확진자 수', fontsize=15)
        else:
            cdf[month].sort_values().plot(kind='barh', grid=True)
            plt.title(f'자치구별 {month} 확진자 수', fontsize=15)

        plt.ylabel('')
        plt.savefig(img_file)
        mtime = int(os.stat(img_file).st_mtime)
        month_list = [
            '누적', '12월', '11월', '10월', '9월', '8월', '7월', '6월', '5월', '4월',
            '3월', '2월', '1월'
        ]

        return render_template('covid/seoul_comp.html',
                               menu=menu,
                               weather=get_weather_main(),
                               mtime=mtime,
                               month=month,
                               month_list=month_list)

    else:
        gubun = request.form['gubun']
        if gubun == 'ratio':
            return redirect(url_for('covid_bp.seoul_comp'))

        month = request.form['month']
        return redirect(url_for('covid_bp.seoul_comp') + f'?month={month}')
コード例 #4
0
def seoul_comp():
    if request.method == 'GET':
        mpl.rc('font', family='Malgun Gothic')
        mpl.rc('axes', unicode_minus=False)

        # 최근 1년치 데이터만 보여주기 위해 수정
        today = date.today()
        last_month = 1 if today.month == 12 else today.month + 1
        last_date = date(today.year - 1, last_month, 1)

        start_date = request.args.get('startDate',
                                      last_date.strftime('%Y-%m-%d'))
        end_date = request.args.get('endDate', today.strftime('%Y-%m-%d'))
        cdf_raw, _ = cu.make_corona_raw_df(start_date, end_date)
        cdf = cu.make_corona_df(cdf_raw, last_month)
        ###################

        month = request.args.get('month', 'ratio')
        img_file = os.path.join(current_app.root_path,
                                'static/img/seoul_comp.png')
        plt.figure(figsize=(12, 8))
        if month == 'ratio':
            cdf['천명당 확진자 수'].sort_values().plot(kind='barh', grid=True)
            plt.title('자치구별 천명당 확진자 수', fontsize=15)
        else:
            cdf[month].sort_values().plot(kind='barh', grid=True)
            plt.title(f'자치구별 {month} 확진자 수', fontsize=15)

        plt.ylabel('')
        plt.savefig(img_file)
        mtime = int(os.stat(img_file).st_mtime)
        month_list = ['누적']
        # 최근 1년치 데이터만 보여주기 위해 수정
        for i in range(12):
            new_month = (today.month + 12 - i) % 12
            month_list.append(f'{new_month if new_month else 12}월')

        return render_template('covid/seoul_comp.html',
                               menu=menu,
                               weather=get_weather_main(),
                               mtime=mtime,
                               month=month,
                               month_list=month_list)

    else:
        gubun = request.form['gubun']
        if gubun == 'ratio':
            return redirect(url_for('covid_bp.seoul_comp'))

        month = request.form['month']
        return redirect(url_for('covid_bp.seoul_comp') + f'?month={month}')
コード例 #5
0
def seoul_map(option):
    geo_data = json.load(
        open('./static/data/skorea_municipalities_geo_simple.json',
             encoding='utf8'))

    # 최근 1년치 데이터만 보여주기 위해 수정
    today = date.today()
    last_month = 1 if today.month == 12 else today.month + 1
    last_date = date(today.year - 1, last_month, 1)

    start_date = request.args.get('startDate', last_date.strftime('%Y-%m-%d'))
    end_date = request.args.get('endDate', today.strftime('%Y-%m-%d'))
    cdf_raw, _ = cu.make_corona_raw_df(start_date, end_date)
    cdf = cu.make_corona_df(cdf_raw, last_month)
    ###################

    html_file = os.path.join(current_app.root_path,
                             'static/img/seoul_corona.html')
    map = folium.Map(location=[37.5502, 126.982],
                     zoom_start=11,
                     tiles='Stamen Toner')
    if option == 'ratio':
        folium.Choropleth(geo_data=geo_data,
                          data=cdf['천명당 확진자 수'],
                          columns=[cdf.index, cdf['천명당 확진자 수']],
                          fill_color='YlGnBu',
                          key_on='feature.id').add_to(map)
    else:
        folium.Choropleth(geo_data=geo_data,
                          data=cdf['누적'],
                          columns=[cdf.index, cdf['누적']],
                          fill_color='PuRd',
                          key_on='feature.id').add_to(map)
    map.save(html_file)
    mtime = int(os.stat(html_file).st_mtime)
    option_str = '천명당 확진자 수' if option == 'ratio' else '누적 확진자 수'

    return render_template('covid/seoul_map.html',
                           menu=menu,
                           weather=get_weather_main(),
                           mtime=mtime,
                           option_str=option_str)