Compare commits
No commits in common. "387b976f810d412d870eb4bad087b80c0d4e3fe6" and "40c30fdde8ec0c6876bc97c64e8f3b80a83a39c6" have entirely different histories.
387b976f81
...
40c30fdde8
19
wsgi.py
19
wsgi.py
@ -82,12 +82,11 @@ def create_plot_df(
|
|||||||
data_dict[key] = df["Digitale Befragung"]
|
data_dict[key] = df["Digitale Befragung"]
|
||||||
|
|
||||||
df = pd.DataFrame(data=data_dict).T
|
df = pd.DataFrame(data=data_dict).T
|
||||||
max_date = df.index.max()
|
|
||||||
|
|
||||||
df.index = df.index.astype("datetime64[ns]") + pd.DateOffset(hours=10)
|
df.index = df.index.astype("datetime64[ns]") + pd.DateOffset(hours=10)
|
||||||
|
|
||||||
df = df.reindex(
|
df = df.reindex(
|
||||||
pd.date_range(start="2023-08-15", end=max_date) + pd.DateOffset(hours=10)
|
pd.date_range(start="2023-08-15", end=curr_datetime) + pd.DateOffset(hours=10)
|
||||||
)
|
)
|
||||||
|
|
||||||
if current_df is not None:
|
if current_df is not None:
|
||||||
@ -105,20 +104,16 @@ def create_plot_df(
|
|||||||
|
|
||||||
|
|
||||||
def plot(
|
def plot(
|
||||||
|
curr_datetime,
|
||||||
df: pd.DataFrame,
|
df: pd.DataFrame,
|
||||||
annotate_current: bool = False,
|
annotate_current: bool = False,
|
||||||
total_targets: tuple[int, ...] = (1500, 2500, 3500),
|
total_targets: tuple[int, ...] = (1500, 2500, 3500),
|
||||||
alpha: float | None = None,
|
alpha: float | None = None,
|
||||||
landesbez_str: str | None = None,
|
landesbez_str: str | None = None,
|
||||||
fix_lims: bool = True,
|
fix_lims: bool = True,
|
||||||
max_shading_date = None,
|
|
||||||
) -> str:
|
) -> str:
|
||||||
fig = plt.figure(dpi=300)
|
fig = plt.figure(dpi=300)
|
||||||
|
|
||||||
if fix_lims:
|
|
||||||
for total_target in total_targets:
|
|
||||||
plt.axhline(y=total_target, color="#48a9be", linestyle="--")
|
|
||||||
|
|
||||||
for bez in landesbez_str:
|
for bez in landesbez_str:
|
||||||
series = df.sum(axis=1) if bez is None else df[bez]
|
series = df.sum(axis=1) if bez is None else df[bez]
|
||||||
plot_df = series.to_frame("Digitale Befragung").replace(0, np.nan)
|
plot_df = series.to_frame("Digitale Befragung").replace(0, np.nan)
|
||||||
@ -198,12 +193,15 @@ def plot(
|
|||||||
sec_ax.set_ylabel("# Teilnahmen [% Erfolg]")
|
sec_ax.set_ylabel("# Teilnahmen [% Erfolg]")
|
||||||
sec_ax.yaxis.set_major_formatter(mtick.PercentFormatter())
|
sec_ax.yaxis.set_major_formatter(mtick.PercentFormatter())
|
||||||
|
|
||||||
|
if fix_lims:
|
||||||
|
for total_target in total_targets:
|
||||||
|
plt.axhline(y=total_target, color="#48a9be", linestyle="--")
|
||||||
|
|
||||||
xlim = plt.xlim()
|
xlim = plt.xlim()
|
||||||
|
|
||||||
# fill weekends
|
# fill weekends
|
||||||
if max_shading_date is None:
|
max_date = curr_datetime + datetime.timedelta(days=3)
|
||||||
max_shading_date = df.index.max() + datetime.timedelta(days=3)
|
days = pd.date_range(start="2023-08-14", end=max_date)
|
||||||
days = pd.date_range(start="2023-08-14", end=max_shading_date)
|
|
||||||
for idx, day in enumerate(days[:-1]):
|
for idx, day in enumerate(days[:-1]):
|
||||||
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")
|
||||||
@ -264,6 +262,7 @@ def create_fig(
|
|||||||
]
|
]
|
||||||
return (
|
return (
|
||||||
plot(
|
plot(
|
||||||
|
curr_datetime,
|
||||||
plot_df,
|
plot_df,
|
||||||
annotate_current=annotate_current,
|
annotate_current=annotate_current,
|
||||||
landesbez_str=landesbez_strs,
|
landesbez_str=landesbez_strs,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user