From 7d97f96fe7def51ac57e2307c21eb426c97f542e Mon Sep 17 00:00:00 2001 From: Benedikt Bastin Date: Fri, 15 Jan 2021 00:16:40 +0100 Subject: [PATCH] feat: Initial working version --- .gitignore | 2 ++ plot.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .gitignore create mode 100644 plot.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b4fba1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pdf +*.xlsx diff --git a/plot.py b/plot.py new file mode 100644 index 0000000..239e6e6 --- /dev/null +++ b/plot.py @@ -0,0 +1,88 @@ +import numpy as np +import matplotlib.pyplot as plt +import pandas as pd + +import datetime +import re + +einwohner_deutschland = 83190556 + + +# DIN A4 Plots +plt.rcParams["figure.figsize"] = [11.69, 8.27] + +raw_data = pd.read_excel('Impfquotenmonitoring.xlsx', sheet_name='Impfungen_proTag', engine='openpyxl') + +impfungen = raw_data[:-1].dropna() + +dates = impfungen['Datum'] +daily = impfungen['Gesamtzahl Impfungen'] +cumulative = np.cumsum(impfungen['Gesamtzahl Impfungen']) + +mean_vaccinations_daily = np.mean(daily) + +to_be_vaccinated = einwohner_deutschland - np.sum(daily) +days_extrapolated = int(np.ceil(to_be_vaccinated / mean_vaccinations_daily)) + +extrapolated_dates = np.array([dates[0] + datetime.timedelta(days=i) for i in range(days_extrapolated)]) + +extrapolated_vaccinations = mean_vaccinations_daily * range(days_extrapolated) + + +# Stand aus Daten auslesen +#stand = dates.iloc[-1] +#print_stand = stand.isoformat() + +# Stand aus offiziellen Angaben auslesen +stand = pd.read_excel('Impfquotenmonitoring.xlsx', sheet_name='Erläuterung', engine='openpyxl').iloc[1][0] +print(stand) + +stand_regex = re.compile('^Datenstand: (\d\d.\d\d.\d\d\d\d, \d\d:\d\d) Uhr$') +m = stand_regex.match(stand) +stand_date = datetime.datetime.strptime(m.groups()[0], '%d.%m.%Y, %H:%M') +print_stand = stand_date.isoformat() + +filename_stand = stand_date.strftime("%Y%m%d%H%M%S") + +def plot_extrapolation_portion(percentage): + + fig, ax = plt.subplots(1) + + print_percentage = int(percentage * 100) + print_today = datetime.date.today().isoformat() + + plt.title( + 'Tägliche Impfquote, kumulierte Impfungen und lineare Extrapolation bis {} % der Bevölkerung Deutschlands\n' + 'Erstellung: {}, Datenquelle: RKI, Stand: {}'.format(print_percentage, print_today, print_stand) + ) + + ax2 = ax.twinx() + + ax.bar(dates, daily, label='Tägliche Impfungen') + + ax2.set_ylim([0, einwohner_deutschland * percentage]) + ax2.set_xlim(xmax=dates[0] + datetime.timedelta(days=percentage * days_extrapolated)) + ax2.grid(True) + ax2.plot(dates, cumulative, color='red', label='Kumulierte Impfungen') + ax2.plot(extrapolated_dates, extrapolated_vaccinations, color='orange', label='Kumulierte Impfungen (linear extrap.)') + #ax2.plot() + + ax.legend(loc='upper left') + ax.get_yaxis().get_major_formatter().set_scientific(False) + + ax.set_xlabel('Datum') + ax.set_ylabel('Tägliche Impfungen') + + ax2.legend(loc='center right') + ax2.get_yaxis().get_major_formatter().set_scientific(False) + + ax2.axline((0, einwohner_deutschland * 0.7), slope=0, color='green') + + ax2.set_ylabel('Kumulierte Impfungen') + + plt.savefig('{}_extrapolated_to_{}_percent.pdf'.format(filename_stand, print_percentage)) + plt.close() + + +plot_extrapolation_portion(0.1) +plot_extrapolation_portion(1.0)