Files
ai-agent/backend/dashboards/timebins.py
gabrielvidalandClaude Opus 5.5 2a3f1924f4 feat(plugins): batch 1 platform hooks for the next seven plugin extractions
Shared hooks for templates, memories, desk-phone, activity, project-env,
ship and blue-green-deploy, with no legacy module removed:

- manifest: owner-only templates.read / memories.read / projects.env /
  activity.read / ship.run (one _OPERATOR_CAPS set); provides
  memories.index, notify.audio, app.banner
- runner: AIA_TEMPLATES_DIR / AIA_MEMORIES_DIR / AIA_PROJECTS_DIR for the
  owner's runs; requester_context() carries sessionId for runAs: owner
- /api/plugins (+ ui): active provides keys (no app.banner for guests)
- hub/conversations: memories=1 (memoriesRead, model), memory=<slug>
- hub/activity (plugins/activitydata.py now holds the rollup;
  dashboards/activity.py is a shim; dashboards/timebins.py helpers)
- /api/usage/daily (owner, lab.read); Home's usage card reads it
- memories_bridge.py (plans_bridge twin), Graph prefers it
- banner.py + /api/app-banner + StatusBanner.tsx; webhook/action of the
  provider invalidates and publishes SSE banner; is_maintenance pauses
  guest-job delivery
- hubbridge: inline scaffold template list; ship/deploy, ship/audit,
  ship/scan bridges
- project.detail slot on Project.tsx; aiAgentPlugin.copy(text)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 10:14:14 +01:00

50 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Local-day arithmetic over the parser's 5-minute bins — shared by the
activity rollup, the guest stats, the analytics bridge and ``/api/usage/daily``.
Bins are stored epoch-absolute in UTC (``conversations._bin5``); every reader
wants *local* days, so it passes ``off_ms`` — the caller's offset east of UTC
in milliseconds (the browser's ``-new Date().getTimezoneOffset()`` minutes ×
60 000).
"""
from __future__ import annotations
import datetime
import functools
from conversations import BIN_MINUTES
#: 5-minute bins in one day (288).
BINS_PER_DAY = 24 * 60 // BIN_MINUTES
BIN_MS = BIN_MINUTES * 60 * 1000
DAY_MS = 24 * 60 * 60 * 1000
_EPOCH_DATE = datetime.date(1970, 1, 1)
@functools.lru_cache(maxsize=4096)
def _day_iso(day_num: int) -> str:
return (_EPOCH_DATE + datetime.timedelta(days=day_num)).isoformat()
def _local_day_and_slot(bin_idx: int, off_ms: int) -> tuple[str, int]:
"""Split an absolute bin index into its local ``(YYYY-MM-DD, slot)``."""
local_ms = bin_idx * BIN_MS + off_ms
day_num, rem = divmod(local_ms, DAY_MS)
return _day_iso(day_num), rem // BIN_MS
def _local_date(iso: str | None, off_ms: int) -> str | None:
"""The local ``YYYY-MM-DD`` an ISO transcript timestamp falls on."""
if not iso:
return None
try:
dt = datetime.datetime.fromisoformat(iso.replace("Z", "+00:00"))
except ValueError:
return None
return (dt + datetime.timedelta(milliseconds=off_ms)).date().isoformat()
def local_today(off_ms: int) -> str:
"""Today's local ``YYYY-MM-DD``."""
now = datetime.datetime.now(datetime.timezone.utc)
return (now + datetime.timedelta(milliseconds=off_ms)).date().isoformat()