fix(forecasting): deal_count confidence note carries «за N мес» window (#1637)
Some checks failed
CI / changes (push) Waiting to run
CI / backend-tests (push) Blocked by required conditions
CI / frontend-tests (push) Blocked by required conditions
CI / openapi-codegen-check (push) Blocked by required conditions
CI / changes (pull_request) Successful in 6s
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Successful in 1m53s
CI / backend-tests (pull_request) Failing after 8m54s
Some checks failed
CI / changes (push) Waiting to run
CI / backend-tests (push) Blocked by required conditions
CI / frontend-tests (push) Blocked by required conditions
CI / openapi-codegen-check (push) Blocked by required conditions
CI / changes (pull_request) Successful in 6s
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Successful in 1m53s
CI / backend-tests (pull_request) Failing after 8m54s
Add `deal_count_months: int | None = None` to `compute_report_confidence`. When provided, threads it as suffix into `_factor_from_count` so the deal_count ConfidenceFactor note reads «7 сделок за 6 мес — мало» instead of the windowless «7 сделок — мало». Existing callers unaffected (default None). Tests: two new cases in TestComputeReportConfidence — with/without window.
This commit is contained in:
parent
18da92ccc7
commit
afa7d80ecf
2 changed files with 25 additions and 0 deletions
|
|
@ -375,6 +375,7 @@ def compute_report_confidence(
|
||||||
*,
|
*,
|
||||||
component_confidences: list[Confidence] | None = None,
|
component_confidences: list[Confidence] | None = None,
|
||||||
deal_count: int | None = None,
|
deal_count: int | None = None,
|
||||||
|
deal_count_months: int | None = None,
|
||||||
analog_count: int | None = None,
|
analog_count: int | None = None,
|
||||||
domrf_coverage: float | None = None,
|
domrf_coverage: float | None = None,
|
||||||
history_months: int | None = None,
|
history_months: int | None = None,
|
||||||
|
|
@ -403,6 +404,8 @@ def compute_report_confidence(
|
||||||
component_confidences: per-service confidence (#950/#952/#985/#986…), None/[]→
|
component_confidences: per-service confidence (#950/#952/#985/#986…), None/[]→
|
||||||
нет вкладывающих компонентов.
|
нет вкладывающих компонентов.
|
||||||
deal_count: число сделок за окно (None → нет данных, тянет в low).
|
deal_count: число сделок за окно (None → нет данных, тянет в low).
|
||||||
|
deal_count_months: окно наблюдения для deal_count (мес) — добавляет «за N мес»
|
||||||
|
в ноту фактора («7 сделок за 6 мес — мало»). None → нота без периода.
|
||||||
analog_count: число ЖК-аналогов в выборке (= market_metrics.obj_count).
|
analog_count: число ЖК-аналогов в выборке (= market_metrics.obj_count).
|
||||||
domrf_coverage: доля domrf↔objective ∈ [0,1] (главный sparse-риск проекта).
|
domrf_coverage: доля domrf↔objective ∈ [0,1] (главный sparse-риск проекта).
|
||||||
history_months: глубина ряда (мес).
|
history_months: глубина ряда (мес).
|
||||||
|
|
@ -417,6 +420,7 @@ def compute_report_confidence(
|
||||||
|
|
||||||
# ── 1. Сырые счётчики качества данных → факторы (только заданные) ──────────
|
# ── 1. Сырые счётчики качества данных → факторы (только заданные) ──────────
|
||||||
if deal_count is not None:
|
if deal_count is not None:
|
||||||
|
_deal_suffix = f"за {deal_count_months} мес" if deal_count_months is not None else ""
|
||||||
factors.append(
|
factors.append(
|
||||||
_factor_from_count(
|
_factor_from_count(
|
||||||
_F_DEAL_COUNT,
|
_F_DEAL_COUNT,
|
||||||
|
|
@ -424,6 +428,7 @@ def compute_report_confidence(
|
||||||
high_at=_DEAL_COUNT_HIGH,
|
high_at=_DEAL_COUNT_HIGH,
|
||||||
low_below=_DEAL_COUNT_LOW,
|
low_below=_DEAL_COUNT_LOW,
|
||||||
unit="сделок",
|
unit="сделок",
|
||||||
|
suffix=_deal_suffix,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if analog_count is not None:
|
if analog_count is not None:
|
||||||
|
|
|
||||||
|
|
@ -342,6 +342,26 @@ class TestComputeReportConfidence:
|
||||||
# Полностью JSON-сериализуем (контракт для экспортёров/чата).
|
# Полностью JSON-сериализуем (контракт для экспортёров/чата).
|
||||||
assert json.loads(json.dumps(d, ensure_ascii=False)) == d
|
assert json.loads(json.dumps(d, ensure_ascii=False)) == d
|
||||||
|
|
||||||
|
def test_deal_count_note_carries_window_months(self) -> None:
|
||||||
|
# #1637: deal_count_months → нота «за N мес» в факторе (и в rationale).
|
||||||
|
res = compute_report_confidence(
|
||||||
|
deal_count=7,
|
||||||
|
deal_count_months=6,
|
||||||
|
advisory=False,
|
||||||
|
)
|
||||||
|
dc_factor = next(f for f in res.factors if f.name == "deal_count")
|
||||||
|
assert "за 6 мес" in dc_factor.note
|
||||||
|
assert "7 сделок" in dc_factor.note
|
||||||
|
# Структурная причина тоже содержит период (через ноту фактора-виновника).
|
||||||
|
assert "за 6 мес" in res.rationale
|
||||||
|
|
||||||
|
def test_deal_count_note_without_window_has_no_period(self) -> None:
|
||||||
|
# deal_count_months=None (по умолчанию) → нота без «за N мес» (backward compat).
|
||||||
|
res = compute_report_confidence(deal_count=7, advisory=False)
|
||||||
|
dc_factor = next(f for f in res.factors if f.name == "deal_count")
|
||||||
|
assert "7 сделок" in dc_factor.note
|
||||||
|
assert "за" not in dc_factor.note
|
||||||
|
|
||||||
def test_ignores_garbage_component_confidence(self) -> None:
|
def test_ignores_garbage_component_confidence(self) -> None:
|
||||||
# Мусорный component-уровень не учитывается (whitelist), не роняет искусственно.
|
# Мусорный component-уровень не учитывается (whitelist), не роняет искусственно.
|
||||||
res = compute_report_confidence(
|
res = compute_report_confidence(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue