Compare commits

..

3 Commits

Author SHA1 Message Date
Felix Blanke
bd804f1464 Make ylim rendering dynamic 2023-08-31 11:30:48 +02:00
Felix Blanke
87f54c6fef Add further target values 2023-08-31 11:30:13 +02:00
Felix Blanke
cc7ba64dd3 Add time series logging to plot.py 2023-08-31 11:17:01 +02:00
2 changed files with 14 additions and 3 deletions

View File

@ -1,15 +1,18 @@
import datetime
from pathlib import Path from pathlib import Path
import fire import fire
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from wsgi import create_fig from wsgi import create_fig, create_plot_df
def main(folder: str = "plots"): def main(folder: str = "plots"):
fig, _df, _df_state, timestamp = create_fig() fig, _df, _df_state, timestamp = create_fig()
timestamp = timestamp.replace(" ", "_") timestamp = timestamp.replace(" ", "_")
timestamp = timestamp.replace(":", "-") timestamp = timestamp.replace(":", "-")
plot_df = create_plot_df(datetime.datetime.now(), _df_state)
print(plot_df.sum(1))
fig.savefig(Path(folder) / f"digital_plot_{timestamp}.png", dpi=300) fig.savefig(Path(folder) / f"digital_plot_{timestamp}.png", dpi=300)

12
wsgi.py
View File

@ -93,7 +93,7 @@ def plot(
curr_datetime, curr_datetime,
df: pd.DataFrame, df: pd.DataFrame,
annotate_current: bool = False, annotate_current: bool = False,
total_targets: tuple[int, ...] = (1500,), 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,
) -> str: ) -> str:
@ -151,7 +151,15 @@ def plot(
plt.title("Teilnahme an Digitaler Beschäftigtenbefragung") plt.title("Teilnahme an Digitaler Beschäftigtenbefragung")
plt.ylabel("# Teilnahmen") plt.ylabel("# Teilnahmen")
plt.ylim(0, total_targets[0] + 100)
max_val = df.sum(axis=1).max().item()
nearest_target = np.array(total_targets, dtype=np.float32) - max_val
nearest_target[nearest_target <= 0] = np.inf
idx = np.argmin(nearest_target)
ceil_val = max(max_val, total_targets[idx])
plt.ylim(0, ceil_val * 1.025)
plt.legend() plt.legend()
# use timezone offset to center tick labels # use timezone offset to center tick labels