feat(anchoring): 가격구간을 자릿수 계단식 사다리(46칸)로 재설계 (TODO 1)

균일 3,000원 × 33,334칸 → 자릿수 사다리 46칸. 폭 = 구간 상한의 10%
(선행 자릿수 밴드): [0, 1,000) 통일 1칸 + 자릿수(1천~1억, 5개)당 9칸
— "1천 원대·2천 원대 … 9천만 원대". 1억 초과는 마지막 인덱스(45) 클램프.

- 고가 구간의 무의미한 3,000원 해상도 제거 → 칸당 표본 밀도 대폭 개선
  (희소 칸 이월 문제 구조적 완화), 정적 테이블 2MB → 3KB
- 사다리 단일 소스 = constants.UPPER_BOUNDS(생성식), json 은 기동 시 대조 검증
- calc_bracket_index: // 3000 → bisect_right (좌폐우개 경계 규약 동일 유지)
- 조정 이력 0건 시점 적용 — 인덱스 재매핑/마이그레이션 없음. DB 스키마 무변경
- 골든 테스트 재작성(경계·자릿수 진입·클램프) + 사다리 형태 검증 추가 — 16 passed
- 문서 5종·인수인계·README·스키마 주석 동기화, TODO 과제 1 완료 처리

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
민헌andClaude Fable 5 committed 2026-07-02 20:08:23 +09:00
1 parent 84786134c2
commit e1940c69aa
16 files changed
+177 -33451

No files matched your search

+2 -2
View File
@@ -15,8 +15,8 @@ from conftest import requires_db
pytestmark = requires_db
# 시드 기본값: target 30,000 / rate 10‰ / anchor 29,700 → bracket = 30000//3000 = 10
BRACKET = 10
# 시드 기본값: target 30,000 / rate 10‰ / anchor 29,700 → bracket 12 ("3만 원대" 칸)
BRACKET = 12
SUCCESS_BID = 29_000 # ≤ anchor → BID_SUCCESS
FAIL_BID = 29_999 # > anchor → BID_FAIL
+27 -13
View File
@@ -5,7 +5,7 @@
import pytest
from anchoring.base_table import BaseTableError, _validate, get_base_rate_permille, load_base_table
from anchoring.constants import BRACKET_COUNT, AnchoringSampleType
from anchoring.constants import BRACKET_COUNT, UPPER_BOUNDS, AnchoringSampleType
from anchoring.service import (
calc_anchor_price,
calc_bracket_index,
@@ -27,27 +27,41 @@ def test_calc_anchor_price_floor():
assert calc_anchor_price(0, 10) == 0
# ── §11.2 구간 인덱스 (상한 클램프 포함) ──────────────────
# ── §11.2 구간 인덱스 (자릿수 계단식 사다리 · 상한 클램프) ──
def test_bracket_index():
assert calc_bracket_index(0) == 0
assert calc_bracket_index(2_999) == 0
assert calc_bracket_index(3_000) == 1 # 경계는 상위 구간
assert calc_bracket_index(99_999_000) == 33_333 # 마지막 구간 진입
assert calc_bracket_index(100_000_000) == 33_333
assert calc_bracket_index(150_000_000) == 33_333 # 1억 초과 → 마지막 인덱스 클램프
assert calc_bracket_index(0) == 0 # [0, 1,000) 통일 칸
assert calc_bracket_index(999) == 0
assert calc_bracket_index(1_000) == 1 # 경계는 상위 구간
assert calc_bracket_index(1_999) == 1 # 1천 원대
assert calc_bracket_index(9_999) == 9 # 9천 원대
assert calc_bracket_index(10_000) == 10 # 1만 원대 진입
assert calc_bracket_index(30_000) == 12 # 3만 원대
assert calc_bracket_index(99_999) == 18 # 9만 원대
assert calc_bracket_index(150_000) == 19 # 10만 원대
assert calc_bracket_index(99_999_999) == 45 # 마지막 구간(9천만 원대) 진입
assert calc_bracket_index(100_000_000) == 45 # 정확히 1억 → 마지막 칸
assert calc_bracket_index(150_000_000) == 45 # 1억 초과 → 마지막 인덱스 클램프
def test_ladder_shape():
"""사다리 자체 검증: 1 + 자릿수(5)×9 = 46칸, 단조 증가, 마지막 1억."""
assert BRACKET_COUNT == 46
assert UPPER_BOUNDS[0] == 1_000 and UPPER_BOUNDS[-1] == 100_000_000
assert list(UPPER_BOUNDS) == sorted(set(UPPER_BOUNDS))
assert UPPER_BOUNDS[9] == 10_000 and UPPER_BOUNDS[18] == 100_000 # 자릿수 경계
# ── §2 정적 테이블 로드·검증 ─────────────────────────────
def test_base_table_load_and_values():
load_base_table()
assert get_base_rate_permille(0) == 10
assert get_base_rate_permille(33_333) == 10
assert get_base_rate_permille(45) == 10
def _rows(n: int = BRACKET_COUNT):
def _rows():
return [
{"idx": k, "upper_bound": min(k * 3000, 100_000_000), "anchoring_value": 0.01}
for k in range(1, n + 1)
{"idx": i + 1, "upper_bound": ub, "anchoring_value": 0.01}
for i, ub in enumerate(UPPER_BOUNDS)
]
@@ -64,7 +78,7 @@ def test_base_table_validate_rejects_bad():
with pytest.raises(BaseTableError):
_validate(rows)
rows = _rows()
rows[-1]["upper_bound"] = 100_002_000 # 마지막 행은 정확히 1억이어야 함
rows[-1]["upper_bound"] = 100_002_000 # 사다리 불일치(마지막은 정확히 1억)
with pytest.raises(BaseTableError):
_validate(rows)
rows = _rows()