fix(sf-08): add euro-1/euro-2 room_bucket for small-format rooms=2 flats

DOM.РФ API classifies euro-format flats (26-50м²) as rooms=2.
_SUPPLY_BATCH_SQL now maps:
  rooms=2 + area<35 → 'euro-1'
  rooms=2 + area<50 → 'euro-2'
before the generic rooms IN (1,2,3) branch.

Audit: 4 140 units rooms=2 + area<35 in domrf_kn_flats were inflating
the supply count for genuine 2-room apartments (median 57м²).
euro buckets have no velocity counterpart in objective_corpus_room_month
so they are filtered out of top_layouts by min_velocity.

Also extends RoomBucket Literal and room_bucket_from_flat() in
layout_signature.py with the new euro-1/euro-2 values.

Closes #271 item 8
This commit is contained in:
lekss361 2026-05-17 14:38:48 +03:00
parent df2b47d27c
commit b9259cd8ed
2 changed files with 18 additions and 5 deletions

View file

@ -143,6 +143,11 @@ _SUPPLY_BATCH_SQL = text("""
CASE CASE
WHEN f.is_studio = TRUE OR f.flat_type = 'Квартира-студия' THEN 'studio' WHEN f.is_studio = TRUE OR f.flat_type = 'Квартира-студия' THEN 'studio'
WHEN f.rooms = 0 THEN 'studio' WHEN f.rooms = 0 THEN 'studio'
-- Fix SF-08: euro-форматы DOM.РФ маркирует малогабаритные квартиры как 2-комн.
-- rooms=2 + area<35 euro-1 (студия с отдельной кухней ~26м²)
-- rooms=2 + area<50 euro-2 (~35-50м², евро-двушка)
WHEN f.rooms = 2 AND f.total_area < 35 THEN 'euro-1'
WHEN f.rooms = 2 AND f.total_area < 50 THEN 'euro-2'
WHEN f.rooms IN (1, 2, 3) THEN f.rooms::text WHEN f.rooms IN (1, 2, 3) THEN f.rooms::text
WHEN f.rooms >= 4 THEN '4+' WHEN f.rooms >= 4 THEN '4+'
ELSE '1' ELSE '1'

View file

@ -7,7 +7,7 @@ from __future__ import annotations
from typing import Literal from typing import Literal
RoomBucket = Literal["studio", "1", "2", "3", "4+"] RoomBucket = Literal["studio", "euro-1", "euro-2", "1", "2", "3", "4+"]
AreaBin = Literal["<25", "25-40", "40-60", "60-80", "80-100", "100+"] AreaBin = Literal["<25", "25-40", "40-60", "60-80", "80-100", "100+"]
@ -15,15 +15,18 @@ def room_bucket_from_flat(
rooms: int | None, rooms: int | None,
flat_type: str | None, flat_type: str | None,
is_studio: bool | None, is_studio: bool | None,
total_area: float | None = None,
) -> RoomBucket: ) -> RoomBucket:
"""Determine room_bucket из kn_flats полей. """Determine room_bucket из kn_flats полей.
Priority: Priority:
1. is_studio=True OR flat_type='Квартира-студия' "studio" 1. is_studio=True OR flat_type='Квартира-студия' "studio"
2. rooms IN (1, 2, 3) str(rooms) 2. rooms=0 (без is_studio) "studio"
3. rooms >= 4 "4+" 3. Fix SF-08: rooms=2 + area<35 "euro-1" (DOM.РФ маркирует малогабаритные как 2-комн)
4. rooms = 0 (без is_studio) "studio" 4. Fix SF-08: rooms=2 + area<50 "euro-2" (евро-двушки 35-50м²)
5. fallback на "1" (rooms is None и не studio) 5. rooms IN (1, 2, 3) str(rooms)
6. rooms >= 4 "4+"
7. fallback на "1" (rooms is None и не studio)
""" """
if is_studio is True or flat_type == "Квартира-студия": if is_studio is True or flat_type == "Квартира-студия":
return "studio" return "studio"
@ -31,6 +34,11 @@ def room_bucket_from_flat(
return "1" return "1"
if rooms == 0: if rooms == 0:
return "studio" return "studio"
if rooms == 2 and total_area is not None:
if total_area < 35.0:
return "euro-1"
if total_area < 50.0:
return "euro-2"
if rooms >= 4: if rooms >= 4:
return "4+" return "4+"
if rooms in (1, 2, 3): if rooms in (1, 2, 3):