Add needs-attention alerts, last charged, health %, quick charge, sortable columns

This commit is contained in:
2026-04-14 18:49:07 -05:00
parent 8fb03e1fa3
commit c7b7c24a7e
2 changed files with 162 additions and 13 deletions
+23 -2
View File
@@ -76,17 +76,38 @@ def create_app(config_object="config"):
]
devices = db.query(Device).order_by(Device.name).all()
devices_with_slots = [d for d in devices if d.installed_count() < d.battery_slots]
one_year_ago = (date.today() - timedelta(days=365)).isoformat()
today = date.today()
one_year_ago = (today - timedelta(days=365)).isoformat()
total_charges = db.query(func.count(ChargeLog.id)).scalar() or 0
charges_last_year = (db.query(func.count(ChargeLog.id))
.filter(ChargeLog.charged_date >= one_year_ago)
.scalar()) or 0
last_charged_map = {
r[0]: r[1]
for r in db.query(ChargeLog.battery_id, func.max(ChargeLog.charged_date))
.group_by(ChargeLog.battery_id).all()
}
active = [b for b in batteries if b.status in ("available", "installed")]
needs_attention = {
"low_capacity": [
b for b in active
if b.tested_capacity_mah and b.capacity_mah
and b.tested_capacity_mah < 0.8 * b.capacity_mah
],
"low_pct": [
b for b in batteries
if b.battery_percentage is not None and b.battery_percentage < 20
] if ha_client.enabled else [],
}
return render_template("dashboard.html", batteries=batteries,
storage_locations=storage_locations, devices=devices,
devices_with_slots=devices_with_slots,
ha_enabled=ha_client.enabled,
total_charges=total_charges,
charges_last_year=charges_last_year)
charges_last_year=charges_last_year,
last_charged_map=last_charged_map,
needs_attention=needs_attention,
today=today)
# ------------------------------------------------------------------ #
# Battery — add