stats 2
This commit is contained in:
@@ -16,21 +16,13 @@ from app import oidc
|
||||
@oidc.require_login
|
||||
def pvstats():
|
||||
try:
|
||||
stepX_time = time.time()
|
||||
dbh = psycopg.connect()
|
||||
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)
|
||||
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')
|
||||
step2_time = time.time()
|
||||
duration2 = step2_time - step1_time
|
||||
logger.info(f"{duration2=}")
|
||||
fig_1.update_layout(
|
||||
title=f"Jahreswerte Exportierte Energie {duration1:.3f}, {duration2:.3f}",
|
||||
title=f"Jahreswerte Exportierte Energie PV-Anlage",
|
||||
xaxis_title="",
|
||||
yaxis_title="",
|
||||
legend_title="Jahr",
|
||||
@@ -43,18 +35,34 @@ def pvstats():
|
||||
)
|
||||
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"""
|
||||
<html>
|
||||
<head>
|
||||
<title>Jahreswerte PV-Energie</title>
|
||||
<title>Jahreswerte PV und Auto</title>
|
||||
</head>
|
||||
<body>
|
||||
{graph_html_1}
|
||||
{graph_html_2}
|
||||
</body>
|
||||
</html>
|
||||
""")
|
||||
except Exception as e:
|
||||
raise Exception(f"Error when querying energy export values: {e}")
|
||||
raise Exception(f"Error when querying energy values: {e}")
|
||||
finally:
|
||||
if dbh is not None:
|
||||
dbh.close()
|
||||
|
||||
Reference in New Issue
Block a user