various new features: new vaccination overview on country specific side, slightly changed text on index head, moved data correction to parser, made population an int, added the used vaccines to the vaccination table, and some bugfixing here and there

This commit is contained in:
fordprefect
2021-01-21 18:42:48 +01:00
parent 3f0ce1b621
commit 71c4ef8065
4 changed files with 166 additions and 22 deletions

View File

@@ -23,7 +23,7 @@ corr = {"Chile": 10000,
"Spain": 30000,
}
def plot(data, countries, pop, **kwargs):
def plot(data, countries, pop, metadata={}, **kwargs):
figsize = (10,5)
vaccs = []
@@ -33,7 +33,7 @@ def plot(data, countries, pop, **kwargs):
if loc == "International":
continue
name = basename+loc
time, new_cases, new_deaths, total_cases, total_deaths, total_vaccinations, stringency_index = data[loc]['time'], data[loc]['new_cases'], data[loc]['new_deaths'], data[loc]['total_cases'], data[loc]['total_deaths'], data[loc]['total_vaccinations'], data[loc]['stringency_index']
time, new_cases, new_deaths, total_cases, total_deaths, total_vaccinations, stringency_index, new_vaccinations = data[loc]['time'], data[loc]['new_cases'], data[loc]['new_deaths'], data[loc]['total_cases'], data[loc]['total_deaths'], data[loc]['total_vaccinations'], data[loc]['stringency_index'], data[loc]['new_vaccinations']
fig, ax1 = pp.subplots(num=name, figsize=figsize)
@@ -49,16 +49,25 @@ def plot(data, countries, pop, **kwargs):
ax1.plot(time[3:-3], np.convolve(new_cases, np.ones((7,))/7, mode="valid"), label="new cases 7day mean", color="orange", linestyle="-", linewidth=2)
# plot vaccinations
if not np.isnan(total_vaccinations).all() :
print(f"{loc} has vaccines, adding to plot")
# fix data: not all countries report daily
for n in range(1, len(total_vaccinations)):
if np.isnan(total_vaccinations[n]) and not np.isnan(total_vaccinations[n-1]):
total_vaccinations[n] = total_vaccinations[n-1]
if not np.isnan(total_vaccinations).all():
# notify of new vaccine programs
if np.isnan(total_vaccinations[-2]):
print(f"{loc} starts vaccinating, adding to plot")
ax2.plot(time, np.array(total_vaccinations), label=f"Total vaccinations", marker="", linestyle="-.", color="crimson")
if False:
# plot detailed vaccination plot for all_countries.py
rfig, rax = pp.subplots(1,1,num=f"{loc}_vacc")
rax2 = rax.twinx()
rax.plot(time, new_vaccinations, linestyle="--", color="green", label="new vac")
rax2.plot(time, total_vaccinations, linestyle="-.", color="red", label="total vac")
rax.set_ylabel("new vaccinatios")
rax2.set_ylabel("total vaccinations")
rax.legend(frameon=False, loc=2)
rfig.savefig("img/"+f"{loc}".replace(" ", "_").replace("'", "").replace("/", "") + "/vaccs.png")
# fix lower bound of plot
for ax in (ax1, ax2):
axis = ax.axis()
@@ -154,10 +163,17 @@ def plot(data, countries, pop, **kwargs):
with open("index.html.head", "r") as g:
f.write(g.read())
# table header
f.write("<table><tr><th>Land</th><th>Impfungen</th><th>Impfrate</th></tr>\n")
f.write("<table><tr><th>Land</th><th>Impfungen</th><th>Impfrate</th><th>Impfstoffe</th></tr>\n")
# data
for loc, tvac, rvac in vaccs:
f.write(f"<tr><td>{loc}</td><td>" + f"{tvac:,d}".replace(",",".") + f"</td><td>{rvac:3.3f}%</td></tr>\n".replace(".", ","))
line = f"<tr><td>{loc}</td><td>" + \
f"{tvac:,d}".replace(",",".") + \
f"</td><td>{rvac:3.3f}%</td>".replace(".", ",")
if "vaccines" in metadata[loc]:
line += f"<td>{metadata[loc]['vaccines']}</td></tr>\n"
else:
line += f"<td>-</td></tr>\n"
f.write(line)
# table footer
f.write("</table>\n")
# site footer