diff --git a/backend/app/analysis/__init__.py b/backend/app/analysis/__init__.py index 67c4ec37..895df813 100644 --- a/backend/app/analysis/__init__.py +++ b/backend/app/analysis/__init__.py @@ -111,6 +111,7 @@ def recompute(result: AnalysisResult, load: Callable[[str], InputSnapshot | None """复算:load 按 sha256 取回输入快照,load_result 按 sha256 取回 parent 那份结论。用结论里记下的 params(含运行当天、 目录事实)、settings、probes,不现查、不读目录。取不回输入时抛 CallError(code input_missing);方法升版后调用不再成立 时同样抛 CallError(照 run 的说法)。和封存的那份用 contract.same 比。""" + from app.analysis.common import DERIVED_PARAMS from app.analysis.facts import Facts from app.analysis.inputs import _CELL, Inputs from app.analysis.probe import Book @@ -149,7 +150,7 @@ def recompute(result: AnalysisResult, load: Callable[[str], InputSnapshot | None today = date.fromisoformat(params["today"]) if isinstance(params.get("today"), str) else None env = _env(op, mode, settings, Inputs(resolve, dialect), Facts(recorded=params.get("catalog") or {}), Book(result.get("probes") or []), today, parents, result.get("hypothesis")) - raw = {k: v for k, v in params.items() if k not in ("catalog", "today", "depth")} + raw = {k: v for k, v in params.items() if k not in DERIVED_PARAMS} return _compute(op, mode, raw, env) diff --git a/backend/app/analysis/differ.py b/backend/app/analysis/differ.py index a6d5e7ef..733ceb52 100644 --- a/backend/app/analysis/differ.py +++ b/backend/app/analysis/differ.py @@ -21,7 +21,6 @@ direction 是 A 相对 B。 """ from __future__ import annotations -import math from collections.abc import Mapping, Sequence from dataclasses import dataclass, field from fractions import Fraction diff --git a/backend/app/analysis/series.py b/backend/app/analysis/series.py index 8bf7267a..37f022a0 100644 --- a/backend/app/analysis/series.py +++ b/backend/app/analysis/series.py @@ -111,10 +111,6 @@ def _completeness(env: Env, series: Series, item: pd.Period) -> tuple[str, str | return cmp.span_coverage(span, env.today, env.book) # type: ignore[arg-type] -def _shown_period(item: pd.Period) -> Any: - return item.raw - - # -------------------------------------------------------------------------- # 波动基线 # -------------------------------------------------------------------------- diff --git a/backend/tests/test_analysis_comparable.py b/backend/tests/test_analysis_comparable.py index bf9bb3d8..5b9c514d 100644 --- a/backend/tests/test_analysis_comparable.py +++ b/backend/tests/test_analysis_comparable.py @@ -3,8 +3,8 @@ probes,不现查)。""" from __future__ import annotations -from analysis_samples import analyze, fixed_prober, snap from app.analysis import comparable_reasons +from tests.analysis_samples import analyze, fixed_prober, snap WINDOW = "SELECT SUM(amount) AS gmv FROM orders WHERE order_date >= '{a}' AND order_date < '{b}'" RANGE = {("orders", "order_date"): ("2025-01-01", "2026-10-20")} diff --git a/backend/tests/test_analysis_decompose.py b/backend/tests/test_analysis_decompose.py index 8e34a692..129c4b76 100644 --- a/backend/tests/test_analysis_decompose.py +++ b/backend/tests/test_analysis_decompose.py @@ -9,8 +9,8 @@ from fractions import Fraction import pytest -from analysis_samples import analyze, call_error, fixed_prober, notes, snap from app.analysis.decompose import lmdi, ratio_effects +from tests.analysis_samples import analyze, call_error, fixed_prober, notes, snap SQL = "SELECT region, week, SUM(amount) AS gmv FROM orders GROUP BY region, week" TYPES = {"region": "text", "week": "text", "gmv": "number"} diff --git a/backend/tests/test_analysis_differ.py b/backend/tests/test_analysis_differ.py index b8120d7b..5f7e10c0 100644 --- a/backend/tests/test_analysis_differ.py +++ b/backend/tests/test_analysis_differ.py @@ -7,8 +7,8 @@ from fractions import Fraction import pytest -from analysis_samples import analyze, call_error, snap from app.analysis import stats +from tests.analysis_samples import analyze, call_error, snap RATE_SQL = "SELECT region, SUM(refund_flag) AS refunds, COUNT(*) AS orders FROM orders GROUP BY region" diff --git a/backend/tests/test_analysis_probe.py b/backend/tests/test_analysis_probe.py index f84a873e..b358fed9 100644 --- a/backend/tests/test_analysis_probe.py +++ b/backend/tests/test_analysis_probe.py @@ -9,7 +9,6 @@ from datetime import date, datetime, timedelta, timezone import pytest -from analysis_samples import CATALOGS, recomputed, snap from app import analysis from app.analysis.contract import effective_settings, same from app.analysis.probe import Book, make_prober @@ -17,6 +16,7 @@ from app.data import introspect from app.data.engine import engines from app.db.base import SessionLocal from app.db.models import DataSource +from tests.analysis_samples import CATALOGS, recomputed, snap CLOCK = "2026-10-21T09:30:00" #: SQLite 的 date('now') 按 UTC 算:表里的数据造到 UTC 的昨天 diff --git a/backend/tests/test_analysis_run.py b/backend/tests/test_analysis_run.py index 262716ca..6baa0ccb 100644 --- a/backend/tests/test_analysis_run.py +++ b/backend/tests/test_analysis_run.py @@ -7,10 +7,10 @@ from datetime import date, timedelta import pytest -from analysis_samples import CATALOGS, analyze, call_error, fixed_prober, recomputed, snap from app import analysis from app.analysis import contract as c from app.analysis.contract import CallError, effective_settings, same +from tests.analysis_samples import CATALOGS, analyze, call_error, fixed_prober, recomputed, snap WEEKLY_SQL = "SELECT region, week, SUM(amount) AS gmv FROM orders GROUP BY region, week" WEEKLY = snap("Q2", WEEKLY_SQL, ["region", "week", "gmv"], diff --git a/backend/tests/test_analysis_series.py b/backend/tests/test_analysis_series.py index bb4c4774..b09c5fed 100644 --- a/backend/tests/test_analysis_series.py +++ b/backend/tests/test_analysis_series.py @@ -7,8 +7,8 @@ from fractions import Fraction import pytest -from analysis_samples import analyze, call_error, fixed_prober, snap from app.analysis.series import MAD_SCALE, run_length +from tests.analysis_samples import analyze, call_error, fixed_prober, snap SQL = "SELECT DATE(order_date, 'weekday 0', '-6 days') AS week, COUNT(*) AS orders FROM orders GROUP BY 1" #: 每周一的日期:最后一周是 2026-10-12(到 10-18,运行当天 10-21 之前已经过完)