Add needs-attention alerts, last charged, health %, quick charge, sortable columns
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user