fix(site-finder): smart_suggestions filter parcels above documented score threshold (#1503)
All checks were successful
CI / changes (push) Successful in 7s
CI / changes (pull_request) Successful in 7s
CI / backend-tests (push) Has been skipped
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Has been skipped
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
All checks were successful
CI / changes (push) Successful in 7s
CI / changes (pull_request) Successful in 7s
CI / backend-tests (push) Has been skipped
CI / frontend-tests (push) Has been skipped
CI / openapi-codegen-check (push) Has been skipped
CI / backend-tests (pull_request) Has been skipped
CI / frontend-tests (pull_request) Has been skipped
CI / openapi-codegen-check (pull_request) Has been skipped
Add SCORE_THRESHOLDS constant (mirror of backend/app/api/v1/parcels.py) to server.py and filter out weighted scores below SCORE_THRESHOLDS["хорошо"] (25.0) before appending to the suggestions list, honouring the contract stated in the endpoint docstring.
This commit is contained in:
parent
ba83c36bf4
commit
de8bfdf884
1 changed files with 9 additions and 1 deletions
|
|
@ -130,6 +130,10 @@ AUDIENCES = {
|
||||||
|
|
||||||
# ---------- Scoring ----------
|
# ---------- Scoring ----------
|
||||||
|
|
||||||
|
# Эмпирические пороги score для ЕКБ: средний диапазон 15-30, max редко >40.
|
||||||
|
# Зеркало SCORE_THRESHOLDS из backend/app/api/v1/parcels.py — менять синхронно.
|
||||||
|
SCORE_THRESHOLDS: dict[str, float] = {"плохо": 5.0, "средне": 15.0, "хорошо": 25.0, "отлично": 40.0}
|
||||||
|
|
||||||
EDU = [("kindergarten", 300, 1000, 1.0), ("school", 400, 1500, 1.0), ("university", 1000, 5000, 0.3)]
|
EDU = [("kindergarten", 300, 1000, 1.0), ("school", 400, 1500, 1.0), ("university", 1000, 5000, 0.3)]
|
||||||
HEALTH = [("pharmacy", 300, 1000, 1.0), ("clinic", 500, 2000, 1.0), ("hospital", 1500, 5000, 0.5)]
|
HEALTH = [("pharmacy", 300, 1000, 1.0), ("clinic", 500, 2000, 1.0), ("hospital", 1500, 5000, 0.5)]
|
||||||
TRANSIT_M = [("metro", 1000, 3000, 1.0)]
|
TRANSIT_M = [("metro", 1000, 3000, 1.0)]
|
||||||
|
|
@ -1053,9 +1057,11 @@ def district_time_machine(district: str):
|
||||||
def smart_suggestions(lat: float, lon: float, audience: str = "balanced",
|
def smart_suggestions(lat: float, lon: float, audience: str = "balanced",
|
||||||
radius_km: float = 3.0, top_n: int = 5):
|
radius_km: float = 3.0, top_n: int = 5):
|
||||||
"""Top-N ЖК within radius_km that score higher than this point under selected audience.
|
"""Top-N ЖК within radius_km that score higher than this point under selected audience.
|
||||||
Useful as 'nearby alternatives'."""
|
Useful as 'nearby alternatives'. Only parcels with weighted score >= SCORE_THRESHOLDS['хорошо']
|
||||||
|
(25.0) are surfaced — below that threshold the suggestion has no meaningful quality signal."""
|
||||||
weights = AUDIENCES.get(audience, AUDIENCES["balanced"])
|
weights = AUDIENCES.get(audience, AUDIENCES["balanced"])
|
||||||
weights = {k: v for k, v in weights.items() if k != "label"}
|
weights = {k: v for k, v in weights.items() if k != "label"}
|
||||||
|
min_weighted = SCORE_THRESHOLDS["хорошо"]
|
||||||
with _conn() as c:
|
with _conn() as c:
|
||||||
rows = c.execute("""
|
rows = c.execute("""
|
||||||
SELECT s.site_id, s.name, s.developer, s.obj_class, s.lat, s.lon,
|
SELECT s.site_id, s.name, s.developer, s.obj_class, s.lat, s.lon,
|
||||||
|
|
@ -1079,6 +1085,8 @@ def smart_suggestions(lat: float, lon: float, audience: str = "balanced",
|
||||||
"leisure": r["leisure"] or 0, "economic": r["economic"] or 0,
|
"leisure": r["leisure"] or 0, "economic": r["economic"] or 0,
|
||||||
"market": r["market"] or 0}
|
"market": r["market"] or 0}
|
||||||
weighted = sum(weights.get(k,0)*v for k,v in comps.items())
|
weighted = sum(weights.get(k,0)*v for k,v in comps.items())
|
||||||
|
if weighted < min_weighted:
|
||||||
|
continue
|
||||||
out.append({
|
out.append({
|
||||||
"site_id": r["site_id"], "name": r["name"], "developer": r["developer"],
|
"site_id": r["site_id"], "name": r["name"], "developer": r["developer"],
|
||||||
"obj_class": r["obj_class"], "obj_district": r["obj_district"],
|
"obj_class": r["obj_class"], "obj_district": r["obj_district"],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue