stats 2
This commit is contained in:
@@ -16,21 +16,13 @@ from app import oidc
|
|||||||
@oidc.require_login
|
@oidc.require_login
|
||||||
def pvstats():
|
def pvstats():
|
||||||
try:
|
try:
|
||||||
stepX_time = time.time()
|
|
||||||
dbh = psycopg.connect()
|
dbh = psycopg.connect()
|
||||||
engine = sqlalchemy.create_engine("postgresql+psycopg://", creator=lambda: dbh)
|
engine = sqlalchemy.create_engine("postgresql+psycopg://", creator=lambda: dbh)
|
||||||
|
|
||||||
step0_time = time.time()
|
|
||||||
df = pd.read_sql("SELECT month, cast(year AS varchar), current_energy AS value FROM pv_energy_by_month", con=engine)
|
df = pd.read_sql("SELECT month, cast(year AS varchar), current_energy AS value FROM pv_energy_by_month", con=engine)
|
||||||
step1_time = time.time()
|
|
||||||
duration1 = step1_time - step0_time
|
|
||||||
logger.info(f"{duration1=}")
|
|
||||||
fig_1 = px.bar(df, x='month', y='value', color='year', barmode='group')
|
fig_1 = px.bar(df, x='month', y='value', color='year', barmode='group')
|
||||||
step2_time = time.time()
|
|
||||||
duration2 = step2_time - step1_time
|
|
||||||
logger.info(f"{duration2=}")
|
|
||||||
fig_1.update_layout(
|
fig_1.update_layout(
|
||||||
title=f"Jahreswerte Exportierte Energie {duration1:.3f}, {duration2:.3f}",
|
title=f"Jahreswerte Exportierte Energie PV-Anlage",
|
||||||
xaxis_title="",
|
xaxis_title="",
|
||||||
yaxis_title="",
|
yaxis_title="",
|
||||||
legend_title="Jahr",
|
legend_title="Jahr",
|
||||||
@@ -43,18 +35,34 @@ def pvstats():
|
|||||||
)
|
)
|
||||||
graph_html_1 = fig_1.to_html(full_html=False, default_height='30%')
|
graph_html_1 = fig_1.to_html(full_html=False, default_height='30%')
|
||||||
|
|
||||||
|
df = pd.read_sql("SELECT month, cast(year AS varchar), current_energy AS value FROM car_energy_by_month", con=engine)
|
||||||
|
fig_2 = px.bar(df, x='month', y='value', color='year', barmode='group')
|
||||||
|
fig_2.update_layout(
|
||||||
|
title=f"Jahreswerte Verbrauch Elektroauto",
|
||||||
|
xaxis_title="",
|
||||||
|
yaxis_title="",
|
||||||
|
legend_title="Jahr",
|
||||||
|
xaxis=dict(
|
||||||
|
tickmode="array",
|
||||||
|
tickvals=list(range(1, 13)), # Monate 1–12
|
||||||
|
ticktext=["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"]
|
||||||
|
),
|
||||||
|
yaxis=dict(ticksuffix=" kWh")
|
||||||
|
)
|
||||||
|
graph_html_2 = fig_2.to_html(full_html=False, default_height='30%')
|
||||||
return render_template_string(f"""
|
return render_template_string(f"""
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Jahreswerte PV-Energie</title>
|
<title>Jahreswerte PV und Auto</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{graph_html_1}
|
{graph_html_1}
|
||||||
|
{graph_html_2}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
""")
|
""")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(f"Error when querying energy export values: {e}")
|
raise Exception(f"Error when querying energy values: {e}")
|
||||||
finally:
|
finally:
|
||||||
if dbh is not None:
|
if dbh is not None:
|
||||||
dbh.close()
|
dbh.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user