feat: refine web analytics and history views
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
|
||||
Read model:
|
||||
|
||||
- Dashboard responses now expose the earliest and latest ARRIVAL coverage dates from the same current daily-version
|
||||
snapshot, so the UI can show actual data coverage instead of inferring a full calendar month.
|
||||
|
||||
- available months and source pins: `finance.current_daily_versions`;
|
||||
- channels/order/counts: `finance.daily_channel_metrics` for those current versions;
|
||||
- aggregates and detail: `finance.v_active_daily_facts` (`current + retained` only);
|
||||
|
||||
@@ -168,6 +168,7 @@ def build_dashboard(
|
||||
source_monthly_sha256: str,
|
||||
channel_names: Iterable[str],
|
||||
facts: Iterable[AggregatedRoomFact],
|
||||
min_arrival_date: Optional[str] = None,
|
||||
) -> Dict[str, Any]:
|
||||
validate_month_key(month_key)
|
||||
names = tuple(channel_names)
|
||||
@@ -213,6 +214,7 @@ def build_dashboard(
|
||||
"version": DASHBOARD_VERSION,
|
||||
"month_key": month_key,
|
||||
"updated_at": updated_at,
|
||||
"min_arrival_date": min_arrival_date,
|
||||
"max_arrival_date": max_arrival_date,
|
||||
"source_monthly_sha256": source_monthly_sha256,
|
||||
"overall": {
|
||||
|
||||
@@ -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