refactor(realestate-matcher): integer tier points + clearer legacy path docstring

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-28 08:38:09 +09:00
parent a75ff069df
commit eb04b954a5
2 changed files with 30 additions and 6 deletions

View File

@@ -6,12 +6,13 @@ from .db import _conn, _profile_row_to_dict
logger = logging.getLogger("realestate-lab")
TIER_WEIGHTS = {"S": 1.00, "A": 0.80, "B": 0.60, "C": 0.40, "D": 0.20}
TIER_POINTS = {"S": 25, "A": 20, "B": 15, "C": 10, "D": 5}
def _region_score(profile: Dict[str, Any], ann: Dict[str, Any]) -> tuple[int, list[str]]:
"""지역 점수 계산. 광역 10점 + 자치구 5티어 가중치 0~25점.
자치구 기준 미설정 시 광역 매칭만으로 35점 풀 점수(기존 호환).
"""지역 점수 계산. 광역 10점 + 자치구 5티어 점수 0~25점.
preferred_districts에 자치구가 하나라도 등록되면 티어 가중 모드로 동작.
자치구가 하나도 등록되지 않으면(빈 dict 또는 모든 티어가 빈 리스트) 광역 매칭만으로 35점 풀 점수(기존 호환).
"""
region_name = ann.get("region_name") or ""
district = ann.get("district") or ""
@@ -22,15 +23,14 @@ def _region_score(profile: Dict[str, Any], ann: Dict[str, Any]) -> tuple[int, li
if not region_match:
return 0, []
has_districts = any(preferred_districts.get(t) for t in TIER_WEIGHTS)
has_districts = any(preferred_districts.values())
if not has_districts:
return 35, [f"선호 지역 일치: {region_name}"]
score = 10
reasons = [f"광역 일치: {region_name}"]
for tier, weight in TIER_WEIGHTS.items():
for tier, tier_score in TIER_POINTS.items():
if district and district in (preferred_districts.get(tier) or []):
tier_score = round(25 * weight)
score += tier_score
reasons.append(f"자치구 {tier}티어: {district} (+{tier_score})")
break