Allow filtering for landesbezirk

This commit is contained in:
Felix Blanke 2023-08-28 17:08:03 +02:00
parent dc80671295
commit 11a4cf4248

19
wsgi.py
View File

@ -90,6 +90,7 @@ def plot(
sheet_name: str = "digital", sheet_name: str = "digital",
total_targets: tuple[int, ...] = (1500, ), total_targets: tuple[int, ...] = (1500, ),
alpha: float | None = None, alpha: float | None = None,
landesbez_str: str | None = None
) -> str: ) -> str:
curr_datetime = datetime.datetime.now() curr_datetime = datetime.datetime.now()
df = create_plot_df( df = create_plot_df(
@ -108,33 +109,39 @@ def plot(
if day.weekday() >= 5: if day.weekday() >= 5:
plt.gca().axvspan(days[idx], days[idx + 1], alpha=0.2, color="gray") plt.gca().axvspan(days[idx], days[idx + 1], alpha=0.2, color="gray")
series = df.sum(axis=1) if landesbez_str is None else df[landesbez_str]
plot_df = series.to_frame("Digitale Befragung").replace(0, np.nan)
plot_df = plot_df.astype({"Digitale Befragung": "float32"})
if pd.isna(plot_df).all().item():
continue
if alpha is not None: if alpha is not None:
plt.fill_between( plt.fill_between(
df.dropna().index, plot_df.dropna().index,
df.dropna()["Digitale Befragung"], plot_df.dropna()["Digitale Befragung"],
color="#e4004e", color="#e4004e",
alpha=alpha, alpha=alpha,
) )
plt.plot( plt.plot(
df.dropna().index, plot_df.dropna().index,
df.dropna()["Digitale Befragung"], plot_df.dropna()["Digitale Befragung"],
ls="--", ls="--",
marker="o", marker="o",
lw=1, lw=1,
color="#e4004e", color="#e4004e",
markersize=4, markersize=4,
label=landesbez_str,
) )
if current_df is not None: if current_df is not None:
plt.annotate( plt.annotate(
"Jetzt", "Jetzt",
(df.dropna().index[-1], df.dropna()["Digitale Befragung"][-1] * 1.03), (plot_df.dropna().index[-1], plot_df.dropna()["Digitale Befragung"][-1] * 1.03),
fontsize=8, fontsize=8,
ha="center", ha="center",
) )
plt.plot(df.index, df["Digitale Befragung"], lw=1.5, color="#e4004e") plt.plot(plot_df.index, plot_df["Digitale Befragung"], lw=1.5, color="#e4004e", label=landesbez_str,)
plt.title("Teilnahme an Digitaler Beschäftigtenbefragung") plt.title("Teilnahme an Digitaler Beschäftigtenbefragung")
plt.ylabel("# Teilnahmen") plt.ylabel("# Teilnahmen")