1
0
Fork 0

feat: Modified to parse some information of v2 data format

This commit is contained in:
Benedikt Bastin 2021-01-31 20:57:02 +01:00
parent 4db877325a
commit 372d02d122
2 changed files with 220 additions and 110 deletions

View File

@ -14,24 +14,24 @@
<section>
<p class="data-text">
Bislang wurden <em>{{ total_vaccinations }}</em> Impfungen<sup><a href="#footnote-001">1</a></sup> innerhalb von <em>{{ days_since_start }}</em> Tagen<sup><a href="#footnote-002">2</a></sup> vorgenommen.
Das entspricht einem Anteil von <em>{{ total_vaccinations_percentage }} %</em> der Bevölkerung<sup><a href="#footnote-003">3</a></sup>.
Bislang wurden <em>{{ '{:n}'.format(data_first_vaccination.total).replace('.', '') }}</em> Erstimpfungen innerhalb von <em>{{ '{:n}'.format(data_first_vaccination.days_since_start).replace('.', '') }}</em> Tagen<sup><a href="#footnote-001">1</a></sup> vorgenommen.
Das entspricht einem Anteil von <em>{{ '{:.3n}'.format(data_first_vaccination.total_percentage) }} %</em> der Bevölkerung<sup><a href="#footnote-002">2</a></sup>.
</p>
<p class="data-text">
Durchschnittlich fanden seit Start täglich <em>{{ mean_vaccinations_daily }}</em> Impfungen statt.
Mit dieser durchnittlichen Rate dauert es bis zum <em>{{ mean_vaccinations_daily_herd_immunity }}</em>, bis {{ herd_immunity }} %<sup><a href="#footnote-004">4</a></sup> der Bevölkerung die erste Impfung erhalten haben,
und bis zum <em>{{ mean_vaccinations_daily_done }}</em> für 100 %.
Seit <em>{{ '{:n}'.format(data_second_vaccination.days_since_start).replace('.', '') }}</em> Tagen laufen die Zweitimpfungen.
Bislang wurden <em>{{ '{:n}'.format(data_second_vaccination.total).replace('.', '') }}</em> Zweitimpfungen verabreicht, das entspricht einem Anteil von <em>{{ '{:.3n}'.format(data_second_vaccination.total_percentage) }} %</em> der Bevölkerung.
</p>
<p class="data-text">
Am <em>{{ last_date }}</em> wurden <em>{{ last_date_day_rate }}</em> Impfungen vorgenommen.
Mit der Rate vom <em>{{ last_date }}</em> dauert es bis zum <em>{{ last_date_day_rate_herd_immunity }}</em> für {{ herd_immunity }} % und bis zum <em>{{ last_date_day_rate_done }}</em> für 100 %<sup><a href="#footnote-005">5</a></sup>.
Durchschnittlich fanden seit Start täglich <em>{{ '{:n}'.format(data_first_vaccination['extrapolation_mean_all_time']['rate_int']).replace('.', '') }}</em> Impfungen statt.
Mit dieser durchnittlichen Rate dauert es bis zum <em>{{ data_first_vaccination['extrapolation_mean_all_time']['date_herd_immunity_str'] }}</em>, bis {{ herd_immunity }} %<sup><a href="#footnote-003">3</a></sup> der Bevölkerung die erste Impfung erhalten haben,
und bis zum <em>{{ data_first_vaccination['extrapolation_mean_all_time']['date_done_str'] }}</em> für 100 %.
</p>
<p class="data-text">
In den letzten sieben Tagen wurden durschnittlich <em>{{ mean_vaccinations_last_seven_days }}</em> Impfungen pro Tag vorgenommen.
Mit dieser Rate dauert es bis zum <em>{{ mean_vaccinations_last_seven_days_herd_immunity }}</em> für {{ herd_immunity }} % und bis zum <em>{{ mean_vaccinations_last_seven_days_done }}</em> für 100 %.
In den letzten sieben Tagen wurden durschnittlich <em>{{ '{:n}'.format(data_first_vaccination['extrapolation_mean_seven_days']['rate_int']).replace('.', '') }}</em> Impfungen pro Tag vorgenommen.
Mit dieser Rate dauert es bis zum <em>{{ data_first_vaccination['extrapolation_mean_seven_days']['date_herd_immunity_str'] }}</em> für {{ herd_immunity }} % und bis zum <em>{{ data_first_vaccination['extrapolation_mean_seven_days']['date_done_str'] }}</em> für 100 %.
</p>
</section>
<section>
<!--<section>
<h1>Details</h1>
<figure>
<div>
@ -43,7 +43,7 @@
Impfungen<br />
gesamt
</th>
<th colspan="8">Impfung wegen<sup><a href="#footnote-006">6</a></sup></th>
<th colspan="8">Impfung wegen<sup><a href="#footnote-004">4</a></sup></th>
</tr>
<tr>
<th colspan="2">Alter</th>
@ -64,38 +64,7 @@
<th>%</th>
</tr>
</thead>
<tbody>
{% for land in details_per_land %}
<tr>
<th>{{ land }}</th>
<td class="number">{{ details_per_land[land].total_vaccinations }}</td>
<td class="number">{{ details_per_land[land].total_vaccinations_percentage }} %</td>
<td class="number">{{ details_per_land[land].vaccination_reason_age }}</td>
<td class="number">{{ details_per_land[land].vaccination_reason_age_percentage }} %</td>
<td class="number">{{ details_per_land[land].vaccination_reason_job }}</td>
<td class="number">{{ details_per_land[land].vaccination_reason_job_percentage }} %</td>
<td class="number">{{ details_per_land[land].vaccination_reason_medical }}</td>
<td class="number">{{ details_per_land[land].vaccination_reason_medical_percentage }} %</td>
<td class="number">{{ details_per_land[land].vaccination_reason_oldhome }}</td>
<td class="number">{{ details_per_land[land].vaccination_reason_oldhome_percentage }} %</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<th>Gesamt</th>
<td class="number">{{ details_total.total_vaccinations }}</td>
<td class="number">{{ details_total.total_vaccinations_percentage }} %</td>
<td class="number">{{ details_total.vaccination_reason_age }}</td>
<td class="number">{{ details_total.vaccination_reason_age_percentage }} %</td>
<td class="number">{{ details_total.vaccination_reason_job }}</td>
<td class="number">{{ details_total.vaccination_reason_job_percentage }} %</td>
<td class="number">{{ details_total.vaccination_reason_medical }}</td>
<td class="number">{{ details_total.vaccination_reason_medical_percentage }} %</td>
<td class="number">{{ details_total.vaccination_reason_oldhome }}</td>
<td class="number">{{ details_total.vaccination_reason_oldhome_percentage }} %</td>
</tr>
</tfoot>
</table>
</div>
<figcaption>
@ -105,7 +74,7 @@
Eine Impfung kann mehrere der genannten Gründe haben oder bei keinen der Gründen genannt werden, daher stimmen die Summe der Gründe und die Gesamtzahl der Impfungen nicht überein.
</figcaption>
</figure>
</section>
</section>-->
<section>
<h1>Fragen und Antworten</h1>
<section>
@ -160,6 +129,17 @@
</p>
<a href="archive/">Zum Archiv</a>
</section>
<section>
<h2>Kann ich die Inhalte hier teilen?</h2>
<p>
Ja, das ist erlaubt, nach den Bedingungen der <a href="https://creativecommons.org/licenses/by-sa/4.0/deed.de">Creative Commons Namensnennung - Weitergabe unter gleichen Bedingungen 4.0 International (CC BY-SA 4.0)</a>.
Das heißt, dass du einen Hinweis auf den Ersteller (also mich) geben musst (bevorzugt per Link auf diese Seite), und dass Abwandlungen, die du hiervon erstellst, wieder unter ähnlich freien Bedingungen weitergegeben werden müssen.
</p>
<p>
In den Plots stehen die nötigen Infos dafür oben mit drauf.
Ein Link wäre aber auch hier nett.
</p>
</section>
</section>
<section>
<h1>Plots</h1>
@ -203,17 +183,29 @@
<a href="extrapolated_to_100_percent.pdf" download="extrapolated_to_100_percent.pdf">Download als PDF</a>
</figcaption>
</figure>
<figure>
<a href="vaccination_bar_graph_total_time.png">
<img
src="vaccination_bar_graph_total_time.png"
alt="" />
</a>
<figcaption>
<a name="figure-004"><span class="ref">Abbildung 4:</span></a>
Tägliche Impfrate (Erst- und Zweitimpfung)<br />
<a href="vaccination_bar_graph_total_time.png" download="vaccination_bar_graph_total_time.png">Download als PNG</a>
<a href="vaccination_bar_graph_total_time.pdf" download="vaccination_bar_graph_total_time.pdf">Download als PDF</a>
</figcaption>
</figure>
</section>
<section>
<h3>Fußnoten</h3>
<ol>
<li><a name="footnote-001">Gezählt werden verabreichte Dosen, unabhängig ob erste oder zweite Dosis.</a></li>
<li><a name="footnote-002">Starttermin der Impfungen war der 27. Dezember 2020, der letzte Tag der Daten ist der {{ last_date }}.</a></li>
<li><a name="footnote-003">Bevölkerungsstand vom 31. Dezember 2019: {{ einwohner_deutschland }}.</a></li>
<li><a name="footnote-004">{{ herd_immunity }} % ist der Wert, bei dem aktuell von einer Herdenimmunität ausgegangen wird.</a></li>
<li><a name="footnote-005">Die täglichen Impfraten unterliegen starken Schwankungen und sind daher wenig aussagekräftig.</a></li>
<li><a name="footnote-006">Nicht alle Länder veröffentlichen alle in der Aufschlüsselung aufgelisteten Daten.</a></li>
<li><a name="footnote-001">Starttermin der Erstimpfungen war der {{ data_first_vaccination.start_of_vaccination_date_str }} und {{ data_second_vaccination.start_of_vaccination_date_str }} war der Start für die Zweitimpfungen. Der letzte Tag der Daten ist der {{ data_first_vaccination.last_date_str }}.</a></li>
<li><a name="footnote-002">Bevölkerungsstand vom 31. Dezember 2019: {{ einwohner_deutschland }}.</a></li>
<li><a name="footnote-003">{{ herd_immunity }} % ist der Wert, bei dem aktuell von einer Herdenimmunität ausgegangen wird.</a></li>
<!--<li><a name="footnote-004">Die täglichen Impfraten unterliegen starken Schwankungen und sind daher wenig aussagekräftig.</a></li>-->
<li><a name="footnote-004">Nicht alle Länder veröffentlichen alle in der Aufschlüsselung aufgelisteten Daten.</a></li>
</ol>
</section>
</body>

238
plot.py
View File

@ -38,59 +38,82 @@ r = req.get('https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Daten/
with open(data_filename, 'wb') as outfile:
outfile.write(r.content)
#data_filename = 'data/20210118151908_Impfquotenmonitoring.xlsx'
rki_file = pd.read_excel(data_filename, sheet_name=None, engine='openpyxl')
raw_data = rki_file['Impfungen_proTag']
impfungen = raw_data[:-1].dropna()
impfungen = raw_data[:-1].dropna(subset=['Datum'])#.fillna(0)
dates = impfungen['Datum']
daily = impfungen['Gesamtzahl Impfungen']
cumulative = np.cumsum(impfungen['Gesamtzahl Impfungen'])
total_vaccinations = int(np.sum(daily))
total_vaccinations_percentage = float(total_vaccinations) / einwohner_deutschland
start_of_reporting_date = dates.iloc[0].date()
mean_vaccinations_daily = np.mean(daily)
mean_vaccinations_daily_int = int(np.round(mean_vaccinations_daily))
def calculate_vaccination_data(data):
cumulative = np.cumsum(data)
to_be_vaccinated = einwohner_deutschland - total_vaccinations
days_extrapolated = int(np.ceil(to_be_vaccinated / mean_vaccinations_daily))
total = int(np.sum(data))
total_percentage = float(total) / einwohner_deutschland * 100
extrapolated_dates = np.array([dates[0] + datetime.timedelta(days=i) for i in range(days_extrapolated)])
mean_all_time = np.mean(data)
mean_seven_days = np.mean(data[-7:])
mean_vaccinations_daily_done = extrapolated_dates[-1]
mean_vaccinations_daily_herd_immunity = extrapolated_dates[int(np.ceil(days_extrapolated * herd_immunity))]
to_be_vaccinated = einwohner_deutschland - total
days_extrapolated_with_todays_rate = int(np.ceil(to_be_vaccinated / daily.iloc[-1]))
last_date = dates.iloc[-1].date()
start_of_vaccination_date = dates[data.first_valid_index()].date()
days_since_start_of_vaccination = (last_date - start_of_vaccination_date).days
days_since_start_of_reporting = (last_date - start_of_reporting_date).days
last_date = dates.iloc[-1]
def extrapolate(rate, to_be_vaccinated):
days_extrapolated = int(np.ceil(to_be_vaccinated / rate))
extrapolated_dates = np.array([dates[0] + datetime.timedelta(days=i) for i in range(days_extrapolated)])
last_date_day_rate = daily.iloc[-1]
last_date_day_rate_done = dates[0] + datetime.timedelta(days=days_extrapolated_with_todays_rate)
last_date_day_rate_herd_immunity = dates[0] + datetime.timedelta(days=int(np.ceil(days_extrapolated_with_todays_rate * herd_immunity)))
date_done = extrapolated_dates[-1]
date_herd_immunity = extrapolated_dates[int(np.ceil(days_extrapolated * herd_immunity))]
extrapolated_vaccinations = total + rate * range(-days_since_start_of_reporting, days_extrapolated - days_since_start_of_reporting)
return {
'rate': rate,
'rate_int': int(np.round(rate)),
'days_extrapolated': days_extrapolated,
'dates': extrapolated_dates,
'date_done': date_done,
'date_done_str': date_done.strftime('%d. %B %Y'),
'date_herd_immunity': date_herd_immunity,
'date_herd_immunity_str': date_herd_immunity.strftime('%d. %B %Y'),
'extrapolated_vaccinations': extrapolated_vaccinations
}
extrapolated_vaccinations = mean_vaccinations_daily * range(1, days_extrapolated + 1)
extrapolation_mean_all_time = extrapolate(mean_all_time, to_be_vaccinated)
extrapolation_last_rate = extrapolate(data.iloc[-1], to_be_vaccinated)
extrapolation_mean_seven_days = extrapolate(mean_seven_days, to_be_vaccinated)
days_since_start = (dates.iloc[-1].date() - dates[0].date()).days
mean_vaccination_rates_daily = np.round(cumulative / range(1, len(cumulative) + 1))
mean_vaccinations_last_seven_days = np.mean(daily[-7:])
mean_vaccinations_last_seven_days_int = int(np.round(mean_vaccinations_last_seven_days))
days_extrapolated_last_seven_days = int(np.ceil(to_be_vaccinated / mean_vaccinations_last_seven_days))
extrapolated_vaccinations_last_seven_days = total_vaccinations + mean_vaccinations_last_seven_days * range(-days_since_start, days_extrapolated - days_since_start)
mean_vaccinations_last_seven_days_done = dates.iloc[-1] + datetime.timedelta(days=days_extrapolated_last_seven_days)
mean_vaccinations_last_seven_days_herd_immunity = dates.iloc[-1] + datetime.timedelta(days=int(np.ceil(days_extrapolated_last_seven_days * herd_immunity)))
return {
'daily': data,
'cumulative': cumulative,
'total': total,
'total_percentage': total_percentage,
'to_be_vaccinated': to_be_vaccinated,
'last_date': last_date,
'last_date_str': last_date.strftime('%d. %B %Y'),
'days_since_start': days_since_start_of_vaccination + 1, # Shift from zero to one-based-index
'start_of_vaccination_date': start_of_vaccination_date,
'start_of_vaccination_date_str': start_of_vaccination_date.strftime('%d. %B %Y'),
'extrapolation_mean_all_time': extrapolation_mean_all_time,
'extrapolation_last_rate': extrapolation_last_rate,
'extrapolation_mean_seven_days': extrapolation_mean_seven_days,
'mean_vaccination_rates_daily': mean_vaccination_rates_daily
}
mean_vaccinations_daily_up_to_date = np.round(cumulative / range(1, len(cumulative) + 1))
data_first_vaccination = calculate_vaccination_data(impfungen['Erstimpfung'])
data_second_vaccination = calculate_vaccination_data(impfungen['Zweitimpfung'])
# Stand aus Daten auslesen
#stand = dates.iloc[-1]
@ -107,11 +130,14 @@ print_stand = stand_date.isoformat()
filename_stand = stand_date.strftime("%Y%m%d%H%M%S")
'''
# Infos der einzelnen Länder
details_sheet_name = (set(rki_file.keys()) - {'Erläuterung', 'Impfungen_proTag'}).pop()
details_sheet = rki_file[details_sheet_name]
regionalcodes = details_sheet['RS'].iloc[0:17]
land_names = details_sheet['Bundesland'].iloc[0:17]
total_vaccinations_by_land = details_sheet['Impfungen kumulativ'].iloc[0:17]
@ -125,8 +151,37 @@ vaccination_reason_oldhome_by_land = details_sheet['Pflegeheim-bewohnerIn*'].ilo
details_per_land = {}
details_per_land_formatted = {}
# Regionalcodes der Länder zu Abkürzung und Name (Plus gesamt)
laendernamen = [
('SH', 'Schleswig-Holstein'),
('HH', 'Hamburg'),
('NI', 'Niedersachsen'),
('HB', 'Bremen'),
('NW', 'Nordrhein-Westfalen'),
('HE', 'Hessen'),
('RP', 'Rheinland-Pfalz'),
('BW', 'Baden-Württemberg'),
('BY', 'Bayern'),
('SL', 'Saarland'),
('BE', 'Berlin'),
('BB', 'Brandenburg'),
('MV', 'Mecklenburg-Vorpommern'),
('SN', 'Sachsen'),
('ST', 'Sachsen-Anhalt'),
('TH', 'Thüringen'),
('𝚺', 'Gesamt')
]
def row_to_details(i):
regionalcode = regionalcodes[i] if i != 16 else 16
print(laendernamen[regionalcode])
shortname, name = laendernamen[regionalcode]
return {
'name': name,
'shortname': shortname,
'total_vaccinations': int(total_vaccinations_by_land[i]),
'total_vaccinations_percentage': vaccination_per_mille_by_land[i] / 10,
'vaccination_reason_age': int(vaccination_reason_age_by_land[i]),
@ -140,7 +195,15 @@ def row_to_details(i):
}
def row_to_details_formatted(i):
regionalcode = regionalcodes[i] if i != 16 else 16
print(laendernamen[regionalcode])
shortname, name = laendernamen[regionalcode]
return {
'name': name,
'shortname': shortname,
'total_vaccinations': '{:n}'.format(int(total_vaccinations_by_land[i])).replace('.', ''),
'total_vaccinations_percentage': '{:.3n}'.format(np.round(vaccination_per_mille_by_land[i] / 10, 2)),
'vaccination_reason_age': '{:n}'.format(int(vaccination_reason_age_by_land[i])).replace('.', ''),
@ -162,6 +225,13 @@ for i in range(len(land_names) - 1):
details_total = row_to_details(16)
details_total_formatted = row_to_details_formatted(16)
'''
archive_folder = site_folder + 'archive/' + filename_stand
if os.path.isdir(archive_folder):
@ -169,6 +239,9 @@ if os.path.isdir(archive_folder):
else:
os.mkdir(archive_folder)
def plot_extrapolation_portion(percentage):
print_percentage = int(percentage * 100)
@ -183,26 +256,38 @@ def plot_extrapolation_portion(percentage):
plt.title(
'Tägliche Impfquote, kumulierte Impfungen und lineare Extrapolation bis {:n} % der Bevölkerung Deutschlands\n'
'Erstellung: {}, Datenquelle: RKI, Stand: {}\n'
'Impfungen gesamt: {:n} ({:n} %), Durchschnittliche Impfrate: {:n} Impfungen/Tag'.format(
'Tägliche Impfrate (Erst- und Zweitimpfung), kumulierte Impfungen und lineare Extrapolation bis {:n} % der Bevölkerung Deutschlands\n'
'Datenquelle: RKI, Stand: {}. Erstellung: {}, Ersteller: Benedikt Bastin, Lizenz: CC BY-SA 4.0\n'
'Erstimpfungen: {:n} ({:n} %), Durchschnittliche Impfrate: {:n} Impfungen/Tag (läuft seit {:n} Tagen)\n'
'Zweitimpfungen: {:n} ({:n} %), Durchschnittliche Impfrate: {:n} Impfungen/Tag (läuft seit {:n} Tagen)'.format(
print_percentage,
print_today, print_stand,
total_vaccinations, np.round(total_vaccinations_percentage * 100, 2), mean_vaccinations_daily_int
print_stand, print_today,
data_first_vaccination['total'], np.round(data_first_vaccination['total_percentage'], 2), data_first_vaccination['extrapolation_mean_all_time']['rate'], data_first_vaccination['days_since_start'],
data_second_vaccination['total'], np.round(data_second_vaccination['total_percentage'], 2), data_second_vaccination['extrapolation_mean_all_time']['rate'], data_second_vaccination['days_since_start']
)
)
ax2 = ax.twinx()
ax.bar(dates, daily, label='Tägliche Impfungen', color='blue')
ax.plot(dates, mean_vaccinations_daily_up_to_date, color='violet', label='Durchschnittliche Impfquote\nbis zu diesem Tag (inkl.)')
ax.bar(dates, data_first_vaccination['daily'], label='Tägliche Erstimpfungen', color='blue')
ax.bar(dates, data_second_vaccination['daily'], label='Tägliche Zweitimpfungen', color='lightblue')
ax.plot(dates, data_first_vaccination['mean_vaccination_rates_daily'], color='violet', label='Durchschnittliche Erstimpfrate\nbis zu diesem Tag (inkl.)')
ax.plot(dates, data_second_vaccination['mean_vaccination_rates_daily'], color='magenta', label='Durchschnittliche Zweitimpfrate\nbis zu diesem Tag (inkl.)')
ax2.set_ylim([0, einwohner_deutschland * percentage])
ax2.set_xlim(xmax=dates[0] + datetime.timedelta(days=percentage * days_extrapolated))
ax2.set_xlim(xmax=dates[0] + datetime.timedelta(days=percentage * data_first_vaccination['extrapolation_mean_all_time']['days_extrapolated']))
ax2.grid(True)
ax2.plot(dates, cumulative, color='red', label='Kumulierte Impfungen')
ax2.plot(extrapolated_dates, extrapolated_vaccinations, color='orange', label='Extrap. kumulierte Impfungen (Øgesamt)\n{:n} Impfungen/Tag'.format(mean_vaccinations_daily_int))
ax2.plot(extrapolated_dates, extrapolated_vaccinations_last_seven_days, color='goldenrod', label='Extrap. kumulierte Impfungen (Ø7 Tage)\n{:n} Impfungen/Tag'.format(mean_vaccinations_last_seven_days_int))
ax2.plot(dates, data_first_vaccination['cumulative'], color='red', label='Kumulierte Erstimpfungen')
ax2.plot(dates, data_second_vaccination['cumulative'], color='indianred', label='Kumulierte Zweitimpfungen')
ax2.plot(data_first_vaccination['extrapolation_mean_all_time']['dates'], data_first_vaccination['extrapolation_mean_all_time']['extrapolated_vaccinations'], color='orange', label='Extrap. kumulierte Erstimpfungen (Øgesamt)\n{:n} Impfungen/Tag'.format(data_first_vaccination['extrapolation_mean_all_time']['rate_int']))
ax2.plot(data_first_vaccination['extrapolation_mean_seven_days']['dates'], data_first_vaccination['extrapolation_mean_seven_days']['extrapolated_vaccinations'], color='goldenrod', label='Extrap. kumulierte Erstimpfungen (Ø7 Tage)\n{:n} Impfungen/Tag'.format(data_first_vaccination['extrapolation_mean_seven_days']['rate_int']))
ax2.plot()
ax2.plot(data_second_vaccination['extrapolation_mean_all_time']['dates'], data_second_vaccination['extrapolation_mean_all_time']['extrapolated_vaccinations'], color='orange', label='Extrap. kumulierte Zweitimpfungen (Øgesamt)\n{:n} Impfungen/Tag'.format(data_second_vaccination['extrapolation_mean_all_time']['rate_int']))
ax2.plot(data_second_vaccination['extrapolation_mean_seven_days']['dates'], data_second_vaccination['extrapolation_mean_seven_days']['extrapolated_vaccinations'], color='goldenrod', label='Extrap. kumulierte Zweitimpfungen (Ø7 Tage)\n{:n} Impfungen/Tag'.format(data_second_vaccination['extrapolation_mean_seven_days']['rate_int']))
#ax2.plot()
ax.legend(loc='upper left')
@ -211,7 +296,7 @@ def plot_extrapolation_portion(percentage):
ax.set_xlabel('Datum')
ax.set_ylabel('Tägliche Impfungen')
ax2.legend(loc='center right')
ax2.legend(loc='lower right')
ax2.get_yaxis().get_major_formatter().set_scientific(False)
# Estimated percentage for herd immunity
@ -229,10 +314,54 @@ def plot_extrapolation_portion(percentage):
plot_extrapolation_portion(0.1)
plot_extrapolation_portion(0.7)
#plot_extrapolation_portion(0.7)
plot_extrapolation_portion(1.0)
def plot_vaccination_bar_graph_total_time():
archive_plot_filename = '{}/vaccination_bar_graph_total_time'.format(archive_folder)
latest_plot_filename = '{}/vaccination_bar_graph_total_time'.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(
'Tägliche Impfrate (Erst- und Zweitimpfung)\n'
'Datenquelle: RKI, Stand: {}. Erstellung: {}, Ersteller: Benedikt Bastin, Lizenz: CC BY-SA 4.0\n'.format(
print_stand, print_today
)
)
ax.grid()
ax.bar(dates, data_first_vaccination['daily'], label='Tägliche Erstimpfungen', color='blue')
ax.bar(dates, data_second_vaccination['daily'], label='Tägliche Zweitimpfungen', color='lightblue', bottom=data_first_vaccination['daily'])
ax.set_ylim([0, np.max(data_first_vaccination['daily']) + np.max(data_second_vaccination['daily'])])
ax.legend(loc='upper left')
ax.get_yaxis().get_major_formatter().set_scientific(False)
ax.set_xlabel('Datum')
ax.set_ylabel('Tägliche Impfungen')
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_bar_graph_total_time()
def render_dashboard():
dashboard_filename = 'site/index.xhtml'
dashboard_archive_filename = 'site/archive/{}/index.xhtml'.format(filename_stand)
@ -264,21 +393,10 @@ def render_dashboard():
filename_stand = filename_stand,
einwohner_deutschland = '{:n}'.format(einwohner_deutschland).replace('.', ''),
herd_immunity = '{:n}'.format(int(herd_immunity * 100)),
total_vaccinations = '{:n}'.format(total_vaccinations).replace('.', ''),
total_vaccinations_percentage = '{:.3n}'.format(total_vaccinations_percentage * 100),
days_since_start = days_since_start,
last_date = last_date.strftime(df),
last_date_day_rate = '{:n}'.format(last_date_day_rate).replace('.', ''),
mean_vaccinations_daily = '{:n}'.format(mean_vaccinations_daily_int).replace('.', ''),
mean_vaccinations_daily_herd_immunity = mean_vaccinations_daily_herd_immunity.strftime(df),
mean_vaccinations_daily_done = mean_vaccinations_daily_done.strftime(df),
last_date_day_rate_herd_immunity = last_date_day_rate_herd_immunity.strftime(df),
last_date_day_rate_done = last_date_day_rate_done.strftime(df),
mean_vaccinations_last_seven_days = '{:n}'.format(mean_vaccinations_last_seven_days_int).replace('.', ''),
mean_vaccinations_last_seven_days_herd_immunity = mean_vaccinations_last_seven_days_herd_immunity.strftime(df),
mean_vaccinations_last_seven_days_done = mean_vaccinations_last_seven_days_done.strftime(df),
details_per_land = dict(sorted(details_per_land_formatted.items(), key=lambda item: item[0])),
details_total = details_total_formatted
data_first_vaccination = data_first_vaccination,
data_second_vaccination = data_second_vaccination,
#details_per_land = dict(sorted(details_per_land_formatted.items(), key=lambda item: item[0])),
#details_total = details_total_formatted
).dump('site/index.xhtml')
shutil.copyfile(dashboard_filename, dashboard_archive_filename)