Fix: Apply outlier filtering to deals list in get_valuation_comparables
Problem: - get_valuation_comparables calculated statistics with outlier filtering - But returned a deals list that still contained outliers (e.g., ₪900K, ₪1.3M deals) - This caused inconsistency between statistics and the actual deals shown Root Cause: - calculate_deal_statistics() filters outliers internally for statistics - But the deals array returned to user was only filtered by criteria (rooms, price, etc.) - Outlier filtering was not applied to the returned deals list Solution: - Added explicit call to filter_deals_for_analysis() after filter_deals_by_criteria() - Now both statistics AND deals list use outlier-filtered data - Moved imports to top of file for better practice Changes: - nadlan_mcp/fastmcp_server.py: - Added imports: get_config, filter_deals_for_analysis - In get_valuation_comparables(): Apply outlier filtering before calculating stats - Ensures deals list and statistics are consistent Testing: - 325/326 tests pass - 1 unrelated test failure in get_market_activity_metrics (pre-existing issue) After deployment, outliers will be automatically filtered from valuation comparables. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -13,8 +13,10 @@ from typing import Any, Dict, List, Optional
|
|||||||
from mcp.server.fastmcp import FastMCP
|
from mcp.server.fastmcp import FastMCP
|
||||||
from starlette.responses import JSONResponse
|
from starlette.responses import JSONResponse
|
||||||
|
|
||||||
|
from nadlan_mcp.config import get_config
|
||||||
from nadlan_mcp.govmap import GovmapClient
|
from nadlan_mcp.govmap import GovmapClient
|
||||||
from nadlan_mcp.govmap.models import Deal
|
from nadlan_mcp.govmap.models import Deal
|
||||||
|
from nadlan_mcp.govmap.outlier_detection import filter_deals_for_analysis
|
||||||
|
|
||||||
# Configure logging
|
# Configure logging
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
@@ -791,6 +793,16 @@ def get_valuation_comparables(
|
|||||||
max_floor=max_floor,
|
max_floor=max_floor,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Apply outlier filtering to remove statistical outliers
|
||||||
|
config = get_config()
|
||||||
|
if (
|
||||||
|
config.analysis_outlier_method != "none"
|
||||||
|
and len(filtered_deals) >= config.analysis_min_deals_for_outlier_detection
|
||||||
|
):
|
||||||
|
filtered_deals, outlier_report = filter_deals_for_analysis(
|
||||||
|
filtered_deals, config, metric="price_per_sqm"
|
||||||
|
)
|
||||||
|
|
||||||
# Calculate statistics on filtered comparables
|
# Calculate statistics on filtered comparables
|
||||||
stats = client.calculate_deal_statistics(filtered_deals)
|
stats = client.calculate_deal_statistics(filtered_deals)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user