Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions data/sightings.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,13 @@ def update_feeder(self, feeder_id: int, name: str | None = None,
def record_refill(self, feeder_id: int | None, amount_oz: float,
notes: str = "", timestamp: str | None = None) -> int:
"""Record a feeder refill. Returns the refill ID."""
ts = timestamp or datetime.now(tz=_local_tz).isoformat()
if timestamp:
dt = datetime.fromisoformat(timestamp)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=_local_tz)
ts = dt.isoformat()
else:
ts = datetime.now(tz=_local_tz).isoformat()
with self._lock:
conn = self._get_conn()
try:
Expand Down Expand Up @@ -937,7 +943,13 @@ def get_refills(self, days: int = 90, limit: int = 50) -> list[dict]:
def record_production(self, amount_oz: float, sugar_ratio: str = "1:4",
notes: str = "", timestamp: str | None = None) -> int:
"""Record nectar production. Returns the production ID."""
ts = timestamp or datetime.now(tz=_local_tz).isoformat()
if timestamp:
dt = datetime.fromisoformat(timestamp)
if dt.tzinfo is None:
dt = dt.replace(tzinfo=_local_tz)
ts = dt.isoformat()
else:
ts = datetime.now(tz=_local_tz).isoformat()
with self._lock:
conn = self._get_conn()
try:
Expand Down Expand Up @@ -983,6 +995,8 @@ def get_feeder_stats(self, days: int = 30) -> dict:
days_since_refill = None
if last_refill:
lr = datetime.fromisoformat(last_refill["timestamp"])
if lr.tzinfo is None:
lr = lr.replace(tzinfo=_local_tz)
days_since_refill = (datetime.now(tz=_local_tz) - lr).days

# Total nectar produced in period
Expand Down
8 changes: 6 additions & 2 deletions web/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,12 @@ def dashboard():
)
analytics = None
if _monitor and _monitor.sightings_db:
from analytics.patterns import get_analytics_summary
analytics = get_analytics_summary(_monitor.sightings_db)
try:
from analytics.patterns import get_analytics_summary
analytics = get_analytics_summary(_monitor.sightings_db)
except Exception:
logger.exception("Failed to load analytics for dashboard")
analytics = None
return render_template(
"dashboard.html",
status=_get_status(),
Expand Down
Loading