feat: refine web analytics and history views
This commit is contained in:
@@ -28,6 +28,7 @@ FALLBACK_DATABASE_ENV = "ARR_DATABASE_URL"
|
||||
|
||||
CURRENT_REPORT_SQL = """
|
||||
SELECT
|
||||
min(current_version.business_date) AS data_start_date,
|
||||
max(current_version.business_date) AS as_of_date,
|
||||
max(current_version.activated_at) AS updated_at,
|
||||
count(*) AS daily_version_count
|
||||
@@ -143,6 +144,7 @@ class ChannelManifestItem:
|
||||
class ReportContext:
|
||||
period_start: date
|
||||
period_end: date
|
||||
data_start_date: date
|
||||
as_of_date: date
|
||||
activated_at: datetime
|
||||
source_projection_sha256: str
|
||||
@@ -303,11 +305,12 @@ class PostgresAnalyticsRepository:
|
||||
) -> ReportContext:
|
||||
cursor.execute(CURRENT_REPORT_SQL, (period_start, period_end))
|
||||
row = cursor.fetchone()
|
||||
if not row or row[0] is None or _integer(row[2], "daily_version_count") == 0:
|
||||
if not row or row[0] is None or row[1] is None or _integer(row[3], "daily_version_count") == 0:
|
||||
raise AnalyticsMonthNotFound()
|
||||
as_of_date = _date(row[0], "as_of_date")
|
||||
activated_at = _datetime(row[1])
|
||||
daily_version_count = _integer(row[2], "daily_version_count")
|
||||
data_start_date = _date(row[0], "data_start_date")
|
||||
as_of_date = _date(row[1], "as_of_date")
|
||||
activated_at = _datetime(row[2])
|
||||
daily_version_count = _integer(row[3], "daily_version_count")
|
||||
|
||||
cursor.execute(REPORT_PIN_COUNT_SQL, (period_start, period_end))
|
||||
identity_rows = list(cursor.fetchall())
|
||||
@@ -348,6 +351,7 @@ class PostgresAnalyticsRepository:
|
||||
return ReportContext(
|
||||
period_start=period_start,
|
||||
period_end=period_end,
|
||||
data_start_date=data_start_date,
|
||||
as_of_date=as_of_date,
|
||||
activated_at=activated_at,
|
||||
source_projection_sha256=_projection_sha256(identity_rows),
|
||||
@@ -419,6 +423,7 @@ class PostgresAnalyticsRepository:
|
||||
source_monthly_sha256=context.source_projection_sha256,
|
||||
channel_names=(item.worksheet for item in context.channels),
|
||||
facts=facts,
|
||||
min_arrival_date=context.data_start_date.isoformat(),
|
||||
)
|
||||
except AnalyticsError:
|
||||
raise
|
||||
|
||||
Reference in New Issue
Block a user