diff --git a/plot.py b/plot.py index 7a511bd..48a50c6 100644 --- a/plot.py +++ b/plot.py @@ -13,7 +13,9 @@ def main(folder: str = "plots"): 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, bbox_inches='tight') + fig.savefig( + Path(folder) / f"digital_plot_{timestamp}.png", dpi=300, bbox_inches="tight" + ) if __name__ == "__main__": diff --git a/regression.py b/regression.py index 38473d7..a126175 100644 --- a/regression.py +++ b/regression.py @@ -10,23 +10,37 @@ import numpy as np import pandas as pd import scipy -from wsgi import create_fig, create_plot_df, plot +from wsgi import create_fig, create_plot_df, get_tables, plot -def create_dfs(): - last_file = sorted(Path("data").iterdir())[-1] - key = last_file.name[:10] +def create_dfs(url: str = "https://beschaeftigtenbefragung.verdi.de/"): + try: + curr_datetime = datetime.datetime.now() + df, df_state = get_tables(url) - with (Path("data") / f"{key}_data.ods").open("rb") as ff: - df = pd.read_excel(ff, sheet_name="digital", index_col=0).astype( - {"Digitale Befragung": "Int32"} - ) - with (Path("data") / f"{key}_state_data.ods").open("rb") as ff: - df_state = pd.read_excel(ff, sheet_name="digital", index_col=0).astype( - {"Digitale Befragung": "Int32"} + df = df.sort_values( + ["Digitale Befragung", "Bundesland", "Bezirk"], + ascending=[False, True, True], ) - plot_df = create_plot_df(None, None) + df_state = df_state.sort_values("Landesbezirk") + plot_df = create_plot_df(curr_datetime, df_state) + + except Exception as e: + print(e) + last_file = sorted(Path("data").iterdir())[-1] + key = last_file.name[:10] + + with (Path("data") / f"{key}_data.ods").open("rb") as ff: + df = pd.read_excel(ff, sheet_name="digital", index_col=0).astype( + {"Digitale Befragung": "Int32"} + ) + with (Path("data") / f"{key}_state_data.ods").open("rb") as ff: + df_state = pd.read_excel(ff, sheet_name="digital", index_col=0).astype( + {"Digitale Befragung": "Int32"} + ) + + plot_df = create_plot_df(None, None) return df, df_state, plot_df @@ -108,7 +122,7 @@ def main(): plt.gca().set_xticks([target_time]) plt.title("Projektion Teilnahme an Digitaler Beschäftigtenbefragung") - plt.savefig("plots/regression.png", bbox_inches='tight', dpi=300) + plt.savefig("plots/regression.png", bbox_inches="tight", dpi=300) if __name__ == "__main__": diff --git a/wsgi.py b/wsgi.py index 5af1f53..6676358 100644 --- a/wsgi.py +++ b/wsgi.py @@ -111,7 +111,7 @@ def plot( alpha: float | None = None, landesbez_str: str | None = None, fix_lims: bool = True, - max_shading_date = None, + max_shading_date=None, ) -> str: fig = plt.figure(dpi=300)