Refactor
This commit is contained in:
parent
0292db36e2
commit
dbf477ed17
83
wsgi.py
83
wsgi.py
@ -257,73 +257,72 @@ def convert_fig_to_svg(fig: plt.Figure) -> str:
|
|||||||
return imgdata.read()
|
return imgdata.read()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
def _print_as_html(df: pd.DataFrame, output_str: list[str], total: int | None = None) -> list[str]:
|
||||||
@cache.cached(query_string=True)
|
df = df.astype({"Digitale Befragung": "Int32"})
|
||||||
def tables():
|
df = df.dropna()
|
||||||
def _print_as_html(df: pd.DataFrame, total: int | None = None) -> None:
|
with pd.option_context("display.max_rows", None):
|
||||||
df = df.astype({"Digitale Befragung": "Int32"})
|
table = df.to_html(
|
||||||
df = df.dropna()
|
index_names=False,
|
||||||
with pd.option_context("display.max_rows", None):
|
justify="left",
|
||||||
table = df.to_html(
|
index=False,
|
||||||
index_names=False,
|
classes="sortable dataframe",
|
||||||
justify="left",
|
)
|
||||||
index=False,
|
|
||||||
classes="sortable dataframe",
|
|
||||||
)
|
|
||||||
|
|
||||||
tfoot = [
|
tfoot = [
|
||||||
" <tfoot>",
|
" <tfoot>",
|
||||||
" <tr>",
|
" <tr>",
|
||||||
" <td>Gesamt</td>",
|
" <td>Gesamt</td>",
|
||||||
|
]
|
||||||
|
for i in range(len(df.columns) - 2):
|
||||||
|
tfoot.append(" <td></td>")
|
||||||
|
tfoot.extend(
|
||||||
|
[
|
||||||
|
f" <td>{df['Digitale Befragung'].sum()}</td>",
|
||||||
|
" </tr>",
|
||||||
]
|
]
|
||||||
|
)
|
||||||
|
if total:
|
||||||
|
tfoot.extend([
|
||||||
|
" <tr>",
|
||||||
|
" <td>Weitere Bezirke</td>",
|
||||||
|
])
|
||||||
for i in range(len(df.columns) - 2):
|
for i in range(len(df.columns) - 2):
|
||||||
tfoot.append(" <td></td>")
|
tfoot.append(" <td></td>")
|
||||||
tfoot.extend(
|
tfoot.extend(
|
||||||
[
|
[
|
||||||
f" <td>{df['Digitale Befragung'].sum()}</td>",
|
f" <td>{total - df['Digitale Befragung'].sum()}</td>",
|
||||||
" </tr>",
|
" </tr>",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
if total:
|
tfoot.append(" </tfoot>")
|
||||||
tfoot.extend([
|
|
||||||
" <tr>",
|
|
||||||
" <td>Weitere Bezirke</td>",
|
|
||||||
])
|
|
||||||
for i in range(len(df.columns) - 2):
|
|
||||||
tfoot.append(" <td></td>")
|
|
||||||
tfoot.extend(
|
|
||||||
[
|
|
||||||
f" <td>{total - df['Digitale Befragung'].sum()}</td>",
|
|
||||||
" </tr>",
|
|
||||||
]
|
|
||||||
)
|
|
||||||
tfoot.append(" </tfoot>")
|
|
||||||
|
|
||||||
tfoot = "\n".join(tfoot)
|
tfoot = "\n".join(tfoot)
|
||||||
idx = table.index("</table>")
|
idx = table.index("</table>")
|
||||||
output_str.append(table[: idx - 1])
|
output_str.append(table[: idx - 1])
|
||||||
output_str.append(tfoot)
|
output_str.append(tfoot)
|
||||||
output_str.append(table[idx:])
|
output_str.append(table[idx:])
|
||||||
|
return output_str
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
@cache.cached(query_string=True)
|
||||||
|
def tables():
|
||||||
importance_factor = request.args.get("importance")
|
importance_factor = request.args.get("importance")
|
||||||
if not importance_factor:
|
if not importance_factor:
|
||||||
importance_factor = 1.0
|
importance_factor = 1.0
|
||||||
else:
|
else:
|
||||||
importance_factor = float(importance_factor)
|
importance_factor = float(importance_factor)
|
||||||
|
|
||||||
output_str = []
|
|
||||||
|
|
||||||
fig, df, df_state, timestamp = create_fig(importance_factor=importance_factor)
|
fig, df, df_state, timestamp = create_fig(importance_factor=importance_factor)
|
||||||
svg_string = convert_fig_to_svg(fig)
|
svg_string = convert_fig_to_svg(fig)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
_print_as_html(df_state)
|
|
||||||
|
|
||||||
df["Bundesland"] = df.index.map(get_landesbezirk)
|
df["Bundesland"] = df.index.map(get_landesbezirk)
|
||||||
df = df.rename(columns={"Bundesland": "Landesbezirk"})
|
df = df.rename(columns={"Bundesland": "Landesbezirk"})
|
||||||
|
|
||||||
_print_as_html(df, total=df_state['Digitale Befragung'].sum())
|
output_str = []
|
||||||
|
output_str = _print_as_html(df_state, output_str)
|
||||||
|
output_str = _print_as_html(df, output_str, total=df_state['Digitale Befragung'].sum())
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"base.html",
|
"base.html",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user