From 794fcf87d2e1e9a8e626e9a465598a4d7490eeb0 Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Tue, 9 Mar 2021 16:24:13 +0100 Subject: [PATCH] feat: Plot for remaining days until done over time --- plot.py | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/plot.py b/plot.py index 326b3c4..a27fe6d 100644 --- a/plot.py +++ b/plot.py @@ -679,6 +679,110 @@ def plot_vaccination_rate(): plot_vaccination_rate() +def plot_vaccination_done_days(): + + archive_plot_filename = '{}/vaccination_done_days'.format(archive_folder) + latest_plot_filename = '{}/vaccination_done_days'.format(site_folder) + + #if os.path.isfile(archive_plot_filename + '.pdf'): + #print('Plot {} already exists'.format(archive_plot_filename)) + #return + + fig, ax = plt.subplots(1) + + + plt.title( + 'Lin. Extrapolation der Erstimpfungen bis 70 % der Bevölkerung anhand der durchschn. Impfrate (Anzahl Tage, Gesamt und 7 Tage)\n' + 'Datenquelle: RKI, Stand: {}. Erstellung: {}, Ersteller: Benedikt Bastin, Lizenz: CC BY-SA 4.0\n'.format( + print_stand, print_today + ) + ) + d = data_first_vaccination + + days_remaining_daily = np.ceil((einwohner_deutschland * 0.7 - d['cumulative']) / (d['mean_vaccination_rates_daily'])) + days_remaining_rolling = np.ceil((einwohner_deutschland * 0.7 - d['cumulative']) / (d['vaccination_rates_daily_rolling_average'])) + + ax.set_ylim(0, 2500) + + ax.plot(dates, days_remaining_daily, label='Durchschnitt Gesamt', linewidth=0.5) + ax.plot(dates, days_remaining_rolling, label='Durchschnitt 7 Tage', linewidth=2) + + ax.grid(True) + + + ax.legend(loc='upper right') + ax.get_yaxis().get_major_formatter().set_scientific(False) + + ax.set_xlabel('Datum') + ax.set_ylabel('Tage, bis 70 % erreicht sind') + + plt.savefig(archive_plot_filename + '.pdf') + plt.savefig(archive_plot_filename + '.png') + plt.savefig(latest_plot_filename + '.pdf') + plt.savefig(latest_plot_filename + '.png') + plt.close() + + print('Created plot {} as pdf and png'.format(archive_plot_filename)) + +plot_vaccination_done_days() + +def plot_vaccination_done_dates(): + + archive_plot_filename = '{}/vaccination_done_dates'.format(archive_folder) + latest_plot_filename = '{}/vaccination_done_dates'.format(site_folder) + + #if os.path.isfile(archive_plot_filename + '.pdf'): + #print('Plot {} already exists'.format(archive_plot_filename)) + #return + + fig, ax = plt.subplots(1) + + + plt.title( + 'Lin. Extrapolation der Erstimpfungen bis 70 % der Bevölkerung anhand der durchschn. Impfrate (Datum, Gesamt und 7 Tage)\n' + 'Datenquelle: RKI, Stand: {}. Erstellung: {}, Ersteller: Benedikt Bastin, Lizenz: CC BY-SA 4.0\n'.format( + print_stand, print_today + ) + ) + d = data_first_vaccination + + #print(d['cumulative']) + #print(np.sum(d['daily'])) + + #print((einwohner_deutschland - d['cumulative'])[:-1] - d['to_be_vaccinated']) + + + days_remaining_daily = np.ceil((einwohner_deutschland * 0.7 - d['cumulative']) / (d['mean_vaccination_rates_daily'])) + days_remaining_rolling = np.ceil((einwohner_deutschland * 0.7 - d['cumulative']) / (d['vaccination_rates_daily_rolling_average'])) + + dates_daily = [today + datetime.timedelta(days) for days in days_remaining_daily] + dates_rolling = [today + datetime.timedelta(days) for days in days_remaining_rolling.dropna()] + + #print(dates_rolling) + + ax.set_ylim(today, today + datetime.timedelta(int(np.max(days_remaining_rolling) * 1.05))) + + ax.plot(dates, dates_daily, label='Durchschnitt Gesamt', linewidth=0.5) + ax.plot(dates[6:], dates_rolling, label='Durchschnitt 7 Tage', linewidth=2) + + ax.grid(True) + + + ax.legend(loc='upper right') + + ax.set_xlabel('Datum') + ax.set_ylabel('Datum, an dem 70 % erreicht sind') + + plt.savefig(archive_plot_filename + '.pdf') + plt.savefig(archive_plot_filename + '.png') + plt.savefig(latest_plot_filename + '.pdf') + plt.savefig(latest_plot_filename + '.png') + plt.close() + + print('Created plot {} as pdf and png'.format(archive_plot_filename)) + +plot_vaccination_done_dates() + def render_dashboard(): dashboard_filename = 'site/index.xhtml' dashboard_archive_filename = 'site/archive/{}/index.xhtml'.format(filename_stand) @@ -758,6 +862,14 @@ def render_dashboard(): 'index': 10, 'filename': 'vaccination_rate', 'caption': 'Tägliche Impfrate sowie durchschnittliche Impfrate' + },{ + 'index': 11, + 'filename': 'vaccination_done_days', + 'caption': 'Lineare Extrapolation bis 70 % der Bevölkerung anhand der Erstimpfungen der durchschnittlichen Impfrate (Anzahl Tage, Gesamt und 7 Tage)' + },{ + 'index': 12, + 'filename': 'vaccination_done_dates', + 'caption': 'Lineare Extrapolation bis 70 % der Bevölkerung anhand der Erstimpfungen der durchschnittlichen Impfrate (Datum, Gesamt und 7 Tage)' } ] ).dump('site/index.xhtml')