Compare commits

..

No commits in common. "29459d538623610e32fa2e841d72d927454cf67d" and "2cbf2af0de9da020d2e027d22b458f32d8a89181" have entirely different histories.

2 changed files with 11 additions and 24 deletions

View File

@ -15,7 +15,8 @@ from wsgi import create_fig, create_plot_df, get_tables, plot
def create_dfs(url: str = "https://beschaeftigtenbefragung.verdi.de/"):
try:
df, df_state, curr_datetime = get_tables(url)
curr_datetime = datetime.datetime.now()
df, df_state = get_tables(url)
df = df.sort_values(
["Digitale Befragung", "Bundesland", "Bezirk"],

32
wsgi.py
View File

@ -46,13 +46,13 @@ app.config.from_mapping(config)
cache = Cache(app)
def get_tables(url: str) -> tuple[pd.DataFrame, pd.DataFrame, datetime.datetime]:
def get_tables(url: str) -> tuple[pd.DataFrame, pd.DataFrame]:
bez_data = get_bez_data(["bez_data_0", "bez_data_2"], url)
df = construct_dataframe(bez_data=bez_data[0], special_tag="stud")
df_state = construct_dataframe(bez_data=bez_data[1])
return df, df_state, datetime.datetime.now()
return df, df_state
def create_plot_df(
@ -224,7 +224,7 @@ def create_fig(
):
curr_datetime = datetime.datetime.now()
try:
df, df_state, curr_datetime = get_tables(url)
df, df_state = get_tables(url)
df = df.sort_values(
["Digitale Befragung", "Bundesland", "Bezirk"],
@ -291,19 +291,11 @@ def _print_as_html(
dropna: bool = True,
) -> list[str]:
df = df.astype({"Digitale Befragung": "Int32"})
missing_df = (
df[["Digitale Befragung"]]
.isna()
.join(df[["Landesbezirk"]])
.groupby("Landesbezirk")
.sum()
)
missing_df = df[["Digitale Befragung"]].isna().join(df[["Landesbezirk"]]).groupby("Landesbezirk").sum()
total = df_state["Digitale Befragung"].sum() if df_state is not None else None
if df_state is not None:
for idx, row in missing_df.loc[
missing_df["Digitale Befragung"] == 1
].iterrows():
for idx, row in missing_df.loc[missing_df["Digitale Befragung"] == 1].iterrows():
df_tmp = df.loc[df["Landesbezirk"] == idx]
df_state_tmp = df_state.loc[df_state["Landesbezirk"] == idx]
missing_idx = df_tmp.loc[df_tmp.isna().any(axis=1)].iloc[0].name
@ -342,7 +334,7 @@ def _print_as_html(
)
if total and (diff := total - df["Digitale Befragung"].sum()):
tfoot.append(" <tr>")
num_missing = missing_df["Digitale Befragung"].sum()
num_missing = missing_df['Digitale Befragung'].sum()
tfoot.append(
f" <td>Weitere Bezirke ({num_missing})</td>"
if num_missing
@ -393,7 +385,9 @@ def state_dashboard(state: str):
output_str = []
output_str = _print_as_html(df_state, output_str, dropna=False)
output_str = _print_as_html(df, output_str, df_state=df_state, dropna=False)
output_str = _print_as_html(
df, output_str, df_state=df_state, dropna=False
)
return render_template(
"base.html",
@ -431,13 +425,5 @@ def dashboard():
)
@app.route("/total")
@cache.cached(timeout=60)
def total_result(url: str = "https://beschaeftigtenbefragung.verdi.de/"):
df, df_state, curr_datetime = get_tables(url)
total = df_state["Digitale Befragung"].sum().item()
return f"{total}"
if __name__ == "__main__":
app.run()