Compare commits

..

2 Commits
0.7.0 ... 0.7.2

Author SHA1 Message Date
cab9ed705e order by year
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-15 18:19:38 +01:00
2faa19bc54 stats 2
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2025-12-15 18:09:13 +01:00

View File

@@ -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 ORDER BY year, 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 ORDER BY year, 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 112
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()