[feat] solution/backend,frontend: 방문 통계 오늘 방문자·직접 유입 — 최근 5분 대신 KST 오늘 0시부터, 리퍼러 없는 페이지뷰를 '직접·알 수 없음'으로

This commit is contained in:
skkim committed 2026-10-13 09:40:47 +09:00
1 parent 832fc81272
commit 2fc50de161
7 files changed
+52 -32

No files matched your search

+10 -6
View File
@@ -17,9 +17,9 @@ class IVisitCRUD(ABC):
pass
@abstractmethod
async def stats(self, cdb: AsyncSession, start: datetime, end: datetime, realtime_since: datetime, site_id,
async def stats(self, cdb: AsyncSession, start: datetime, end: datetime, today_since: datetime, site_id,
overall: bool) -> Tuple[ErrorType, dict]:
"""기간 [start, end) 집계 + realtime_since 이후 고유 방문자. 키: realtime·summary·daily·referrers·devices + (overall) sites | (사이트) pages·utm."""
"""기간 [start, end) 집계 + today_since 이후 고유 방문자. 키: today·summary·daily·referrers·devices + (overall) sites | (사이트) pages·utm."""
pass
@@ -31,7 +31,7 @@ class VisitCRUD(IVisitCRUD):
LOG.e_no_callstack(ex)
return ErrorType.DB_RUN_FAILED
async def stats(self, cdb: AsyncSession, start: datetime, end: datetime, realtime_since: datetime, site_id,
async def stats(self, cdb: AsyncSession, start: datetime, end: datetime, today_since: datetime, site_id,
overall: bool) -> Tuple[ErrorType, dict]:
try:
v = site_page_views
@@ -44,9 +44,13 @@ class VisitCRUD(IVisitCRUD):
# GROUP BY 는 라벨로 — 같은 식 두 번이면 'Asia/Seoul' 바인드가 갈라져 Postgres 가 거부한다(크롤러 통계와 같은 이유).
day = func.date(func.timezone("Asia/Seoul", v.created_at)).label("day")
queries = {
# 실시간은 기간 선택과 무관하다 — "지금 몇 명" 을 묻는 숫자다.
"realtime": select(func.count(distinct(v.visitor_hash)).label("n")).where(scope, v.created_at >= realtime_since),
"summary": select(views, visitors, func.max(v.created_at).label("last_at")).where(where),
# 오늘 방문자는 기간 선택과 무관하다 — "오늘 몇 명" 을 묻는 숫자다.
"today": select(func.count(distinct(v.visitor_hash)).label("n")).where(scope, v.created_at >= today_since),
"summary": select(
views, visitors, func.max(v.created_at).label("last_at"),
# 리퍼러가 빈 방문 — 직접 입력·즐겨찾기·앱·QR 이 섞여 있어 "직접" 으로 단정하지 않는다.
func.count().filter(v.referrer_domain.is_(None)).label("direct_views"),
).where(where),
"daily": select(day, views, visitors).where(where).group_by("day").order_by("day"),
"referrers": (
select(v.referrer_domain, views)