1
0
Fork 0

Compare commits

..

No commits in common. "4b828cdad993c397b73fc2cd196886c95dfa610f" and "0b2b13b07b3f001e6e4508c222906bd2df365bab" have entirely different histories.

2 changed files with 115 additions and 117 deletions

View file

@ -175,16 +175,16 @@
<h1>Plots</h1> <h1>Plots</h1>
{% for fig in figures %} {% for fig in figures %}
<figure> <figure>
<picture> <a href="{{ fig['filename'] }}.png">
<source srcset="{{ fig['filename']}}.svg" alt="{{ fig['caption']}}" /> <img
<img src="{{ fig['filename'] }}.png" alt="{{ fig['caption'] }}" /> src="{{ fig['filename'] }}.png"
</picture> alt="{{ fig['caption'] }}" />
</a>
<figcaption> <figcaption>
<a name="figure-{{ '{:03d}'.format(fig['index']) }}"><span class="ref">Abbildung {{ fig['index'] }}:</span></a> <a name="figure-{{ '{:03d}'.format(fig['index']) }}"><span class="ref">Abbildung {{ fig['index'] }}:</span></a>
{{ fig['caption'] }}<br /> {{ fig['caption'] }}<br />
<a href="{{ fig['filename'] }}.png" download="{{ fig['filename'] }}.png">Download als PNG</a> <a href="{{ fig['filename'] }}.png" download="{{ fig['filename'] }}.png">Download als PNG</a>
<a href="{{ fig['filename'] }}.pdf" download="{{ fig['filename'] }}.pdf">Download als PDF</a> <a href="{{ fig['filename'] }}.pdf" download="{{ fig['filename'] }}.pdf">Download als PDF</a>
<a href="{{ fig['filename'] }}.svg" download="{{ fig['filename'] }}.pdf">Download als SVG</a>
</figcaption> </figcaption>
</figure> </figure>
{% endfor %} {% endfor %}

222
plot.py
View file

@ -37,8 +37,7 @@ print_today = today.isoformat()
filename_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S") filename_now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
force_renew_plots = True force_renew = True
force_renew_dashboard = True
# https://www.tagesschau.de/ausland/europa/ursula-von-der-leyen-zu-corona-impfstoffen-101.html # https://www.tagesschau.de/ausland/europa/ursula-von-der-leyen-zu-corona-impfstoffen-101.html
target_date_for_herd_immunity = datetime.date(2021, 9, 22) target_date_for_herd_immunity = datetime.date(2021, 9, 22)
@ -286,47 +285,15 @@ if os.path.isdir(archive_folder):
else: else:
os.mkdir(archive_folder) os.mkdir(archive_folder)
def check_recreate_plot(plot_name):
archive_plot_filename = '{}/{}'.format(archive_folder, plot_name)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew_plots:
print('Plot {} already exists'.format(plot_name))
return False
return True
def save_plot(plot_name):
folders = [archive_folder, site_folder]
file_formats = ['pdf', 'png', 'svg']
file_template = '{folder}/{plot_name}.{format}'
for folder in folders:
for format in file_formats:
plt.savefig(file_template.format(folder=folder, plot_name=plot_name, format=format))
print('Created plot {} as {}'.format(plot_name, file_formats))
def labeled_timeperiod(ax, start, end, text, color='lightgrey'):
centre = start + (end - start) / 2
ax.axvspan(start, end, color=color, alpha=0.5)
ax.text(centre, ax.get_ylim()[1], text, bbox={
'boxstyle': 'square',
'fc': color,
'ec': 'black'
}, ha='center')
def add_annotations(ax):
labeled_timeperiod(ax, datetime.date(2021, 3, 15), datetime.date(2021, 3, 19), 'AZ-Stopp', 'silver')
labeled_timeperiod(ax, datetime.date(2021, 3, 29), today, 'AZ-Stopp u. 60', 'lightgrey')
def plot_vaccination_bar_graph_total_time(): def plot_vaccination_bar_graph_total_time():
plot_name = 'vaccination_bar_graph_total_time' archive_plot_filename = '{}/vaccination_bar_graph_total_time'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_bar_graph_total_time'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -352,18 +319,24 @@ def plot_vaccination_bar_graph_total_time():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Tägliche Impfungen') ax.set_ylabel('Tägliche Impfungen')
add_annotations(ax)
save_plot(plot_name) 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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_bar_graph_total_time() plot_vaccination_bar_graph_total_time()
def plot_vaccination_bar_graph_total_time_by_week(): def plot_vaccination_bar_graph_total_time_by_week():
plot_name = 'vaccination_bar_graph_total_time_by_week' archive_plot_filename = '{}/vaccination_bar_graph_total_time_by_week'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_bar_graph_total_time_by_week'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -386,8 +359,6 @@ def plot_vaccination_bar_graph_total_time_by_week():
bar1 = ax.bar(w, f, label='Wöchentliche Erstimpfungen', color='blue', width=6.8) bar1 = ax.bar(w, f, label='Wöchentliche Erstimpfungen', color='blue', width=6.8)
bar2 = ax.bar(w, s, label='Wöchentliche Zweitimpfungen', color='lightblue', width=6.8, bottom=f) bar2 = ax.bar(w, s, label='Wöchentliche Zweitimpfungen', color='lightblue', width=6.8, bottom=f)
i = 0
for r1, r2 in zip(bar1, bar2): for r1, r2 in zip(bar1, bar2):
x = r1.get_x() + r1.get_width() / 2.0 x = r1.get_x() + r1.get_width() / 2.0
@ -404,37 +375,6 @@ def plot_vaccination_bar_graph_total_time_by_week():
plt.text(x, hg * 1000, f'{hg:5n} k'.replace('.', ''), ha='center', va='bottom') plt.text(x, hg * 1000, f'{hg:5n} k'.replace('.', ''), ha='center', va='bottom')
if i == 12:
# Woche der AstraZeneca-Aussetzung
plt.annotate('AZ-Stopp', (x, hg * 1000 + 50000),
xytext=(x, ax.get_ylim()[1]),
arrowprops={
'arrowstyle': '->'
},
bbox={
'boxstyle': 'square',
'fc': 'white',
'ec': 'black'
},
ha='center')
if i == len(bar1) - 1:
plt.annotate('Diese Woche', (x, hg * 1000 + 50000),
xytext=(x, ax.get_ylim()[1]),
arrowprops={
'arrowstyle': '->',
'relpos': (0, 0)
},
bbox={
'boxstyle': 'square',
'fc': 'white',
'ec': 'black'
},
ha='left')
i = i + 1
ax.legend(loc='upper left') ax.legend(loc='upper left')
ax.get_xaxis().set_major_formatter(DateFormatter('%Y-w%W')) ax.get_xaxis().set_major_formatter(DateFormatter('%Y-w%W'))
ax.get_xaxis().set_major_locator(WeekdayLocator(3, 2)) ax.get_xaxis().set_major_locator(WeekdayLocator(3, 2))
@ -443,15 +383,24 @@ def plot_vaccination_bar_graph_total_time_by_week():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Wöchentliche Impfungen') ax.set_ylabel('Wöchentliche Impfungen')
save_plot(plot_name)
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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_bar_graph_total_time_by_week() plot_vaccination_bar_graph_total_time_by_week()
def plot_vaccination_bar_graph_total_time_two_bars(): def plot_vaccination_bar_graph_total_time_two_bars():
plot_name = 'vaccination_bar_graph_total_time_two_bars' archive_plot_filename = '{}/vaccination_bar_graph_total_time_two_bars'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_bar_graph_total_time_two_bars'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -480,17 +429,24 @@ def plot_vaccination_bar_graph_total_time_two_bars():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Tägliche Impfungen') ax.set_ylabel('Tägliche Impfungen')
add_annotations(ax)
save_plot(plot_name) 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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_bar_graph_total_time_two_bars() plot_vaccination_bar_graph_total_time_two_bars()
def plot_vaccination_bar_graph_compare_both_vaccinations(): def plot_vaccination_bar_graph_compare_both_vaccinations():
plot_name = 'vaccination_bar_graph_compare_both_vaccinations' archive_plot_filename = '{}/vaccination_bar_graph_compare_both_vaccinations'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_bar_graph_compare_both_vaccinations'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -520,15 +476,23 @@ def plot_vaccination_bar_graph_compare_both_vaccinations():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Tägliche Impfungen') ax.set_ylabel('Tägliche Impfungen')
save_plot(plot_name)
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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_bar_graph_compare_both_vaccinations() plot_vaccination_bar_graph_compare_both_vaccinations()
def plot_cumulative_two_vaccinations(): def plot_cumulative_two_vaccinations():
archive_plot_filename = '{}/cumulative_two_vaccinations'.format(archive_folder)
latest_plot_filename = '{}/cumulative_two_vaccinations'.format(site_folder)
plot_name = 'cumulative_two_vaccinations' if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
if not check_recreate_plot(plot_name): print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -558,18 +522,24 @@ def plot_cumulative_two_vaccinations():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Kumulative Impfungen') ax.set_ylabel('Kumulative Impfungen')
add_annotations(ax)
save_plot(plot_name) 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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_cumulative_two_vaccinations() plot_cumulative_two_vaccinations()
def plot_cumulative_two_vaccinations_percentage(): def plot_cumulative_two_vaccinations_percentage():
archive_plot_filename = '{}/cumulative_two_vaccinations_percentage'.format(archive_folder)
latest_plot_filename = '{}/cumulative_two_vaccinations_percentage'.format(site_folder)
plot_name = 'cumulative_two_vaccinations_percentage' if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
if not check_recreate_plot(plot_name): print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -600,19 +570,25 @@ def plot_cumulative_two_vaccinations_percentage():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Kumulative Impfungen') ax.set_ylabel('Kumulative Impfungen')
add_annotations(ax)
save_plot(plot_name) 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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_cumulative_two_vaccinations_percentage() plot_cumulative_two_vaccinations_percentage()
def plot_people_between_first_and_second(): def plot_people_between_first_and_second():
archive_plot_filename = '{}/people_between_first_and_second'.format(archive_folder)
latest_plot_filename = '{}/people_between_first_and_second'.format(site_folder)
plot_name = 'people_between_first_and_second' if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
if not check_recreate_plot(plot_name): print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -644,18 +620,25 @@ def plot_people_between_first_and_second():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Personen zwischen Erst- und Zweitimpfung') ax.set_ylabel('Personen zwischen Erst- und Zweitimpfung')
add_annotations(ax)
save_plot(plot_name) 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() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_people_between_first_and_second() plot_people_between_first_and_second()
def plot_vaccination_rate(): def plot_vaccination_rate():
plot_name = 'vaccination_rate' archive_plot_filename = '{}/vaccination_rate'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_rate'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -688,17 +671,23 @@ def plot_vaccination_rate():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Impfrate [Impfungen/Tag]') ax.set_ylabel('Impfrate [Impfungen/Tag]')
add_annotations(ax) plt.savefig(archive_plot_filename + '.pdf')
plt.savefig(archive_plot_filename + '.png')
save_plot(plot_name) plt.savefig(latest_plot_filename + '.pdf')
plt.savefig(latest_plot_filename + '.png')
plt.close() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_rate() plot_vaccination_rate()
def plot_vaccination_done_days(): def plot_vaccination_done_days():
plot_name = 'vaccination_done_days' archive_plot_filename = '{}/vaccination_done_days'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_done_days'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -729,17 +718,23 @@ def plot_vaccination_done_days():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Tage, bis 70 % erreicht sind') ax.set_ylabel('Tage, bis 70 % erreicht sind')
add_annotations(ax) plt.savefig(archive_plot_filename + '.pdf')
plt.savefig(archive_plot_filename + '.png')
save_plot(plot_name) plt.savefig(latest_plot_filename + '.pdf')
plt.savefig(latest_plot_filename + '.png')
plt.close() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_done_days() plot_vaccination_done_days()
def plot_vaccination_done_dates(): def plot_vaccination_done_dates():
plot_name = 'vaccination_done_dates' archive_plot_filename = '{}/vaccination_done_dates'.format(archive_folder)
if not check_recreate_plot(plot_name): latest_plot_filename = '{}/vaccination_done_dates'.format(site_folder)
if os.path.isfile(archive_plot_filename + '.pdf') and not force_renew:
print('Plot {} already exists'.format(archive_plot_filename))
return return
fig, ax = plt.subplots(1) fig, ax = plt.subplots(1)
@ -780,11 +775,14 @@ def plot_vaccination_done_dates():
ax.set_xlabel('Datum') ax.set_xlabel('Datum')
ax.set_ylabel('Datum, an dem 70 % erreicht sind') ax.set_ylabel('Datum, an dem 70 % erreicht sind')
add_annotations(ax) plt.savefig(archive_plot_filename + '.pdf')
plt.savefig(archive_plot_filename + '.png')
save_plot(plot_name) plt.savefig(latest_plot_filename + '.pdf')
plt.savefig(latest_plot_filename + '.png')
plt.close() plt.close()
print('Created plot {} as pdf and png'.format(archive_plot_filename))
plot_vaccination_done_dates() plot_vaccination_done_dates()
def render_dashboard(): def render_dashboard():
@ -793,7 +791,7 @@ def render_dashboard():
stylesheet_filename = 'site/rki-dashboard.css' stylesheet_filename = 'site/rki-dashboard.css'
stylesheet_archive_filename = 'site/archive/{}/rki-dashboard.css'.format(filename_stand) stylesheet_archive_filename = 'site/archive/{}/rki-dashboard.css'.format(filename_stand)
if os.path.isfile(dashboard_archive_filename) and not force_renew_dashboard: if os.path.isfile(dashboard_archive_filename) and not force_renew:
print('Dashboard {} already exists'.format(dashboard_archive_filename)) print('Dashboard {} already exists'.format(dashboard_archive_filename))
return return