feat(backend): presence stats count time online from sessions in the browser time zone, capture uptime marks hours without data, presence reaches every stream of the account, message volume keeps empty days
This commit is contained in:
1 parent
bb38e23f29
commit
f44597b2dc
14 files changed
+585
-26
No files matched your search
@@ -0,0 +1,27 @@
|
||||
from datetime import datetime
|
||||
|
||||
import asyncpg
|
||||
|
||||
DEFAULT_TZ = "UTC"
|
||||
MAX_DAYS = 365
|
||||
|
||||
_timezones: set[str] = set()
|
||||
|
||||
|
||||
async def known_timezone(pool: asyncpg.Pool, tz: str) -> bool:
|
||||
if not _timezones:
|
||||
rows = await pool.fetch("SELECT name FROM pg_timezone_names")
|
||||
_timezones.update(row["name"] for row in rows)
|
||||
return tz in _timezones
|
||||
|
||||
|
||||
async def period_bounds(
|
||||
pool: asyncpg.Pool, days: int, tz: str
|
||||
) -> tuple[datetime, datetime]:
|
||||
row = await pool.fetchrow(
|
||||
"SELECT (date_trunc('day', now() AT TIME ZONE $1) "
|
||||
"- make_interval(days => $2 - 1)) AT TIME ZONE $1 AS since, now() AS until",
|
||||
tz,
|
||||
days,
|
||||
)
|
||||
return row["since"], row["until"]
|
||||
Reference in new issue
Block a user