Fix too many polygons issue
This commit is contained in:
@@ -604,6 +604,12 @@ class GovmapClient:
|
||||
|
||||
logger.info(f"Found {len(polygon_ids)} unique polygon IDs")
|
||||
|
||||
# Limit polygons to query (performance optimization)
|
||||
max_polygons = self.config.max_polygons_to_query
|
||||
if len(polygon_ids) > max_polygons:
|
||||
polygon_ids = list(polygon_ids)[:max_polygons]
|
||||
logger.info(f"Limited to {max_polygons} polygons for performance")
|
||||
|
||||
# Step 3: Calculate date range
|
||||
end_date = datetime.now()
|
||||
start_date = end_date - timedelta(days=years_back * 365)
|
||||
@@ -618,6 +624,12 @@ class GovmapClient:
|
||||
seen_deals = set() # For deduplication
|
||||
|
||||
for polygon_id in polygon_ids:
|
||||
# Early termination if we have enough deals
|
||||
total_collected = len(building_deals) + len(street_deals) + len(neighborhood_deals)
|
||||
if total_collected >= max_deals:
|
||||
logger.info(f"Collected {total_collected} deals, stopping polygon queries")
|
||||
break
|
||||
|
||||
try:
|
||||
# Get street deals first (higher priority)
|
||||
current_street_deals = self.get_street_deals(
|
||||
@@ -628,14 +640,17 @@ class GovmapClient:
|
||||
deal_type=deal_type,
|
||||
)
|
||||
|
||||
# Get neighborhood deals (lower priority)
|
||||
current_neighborhood_deals = self.get_neighborhood_deals(
|
||||
polygon_id,
|
||||
limit=max_deals // 4, # Allocate less to neighborhood deals
|
||||
start_date=start_date_str,
|
||||
end_date=end_date_str,
|
||||
deal_type=deal_type,
|
||||
)
|
||||
# Get neighborhood deals (lower priority) - optional for performance
|
||||
current_neighborhood_deals = []
|
||||
# Skip neighborhood deals if we have enough street deals
|
||||
if len(street_deals) < max_deals // 2:
|
||||
current_neighborhood_deals = self.get_neighborhood_deals(
|
||||
polygon_id,
|
||||
limit=max_deals // 4, # Allocate less to neighborhood deals
|
||||
start_date=start_date_str,
|
||||
end_date=end_date_str,
|
||||
deal_type=deal_type,
|
||||
)
|
||||
|
||||
# Process street deals and separate building deals
|
||||
for deal in current_street_deals:
|
||||
|
||||
@@ -55,10 +55,11 @@ def validate_coordinates(point: Tuple[float, float]) -> Tuple[float, float]:
|
||||
raise ValueError("Coordinates must be numeric values")
|
||||
|
||||
# Basic validation for Israeli coordinates (ITM projection)
|
||||
if not (0 < lon < 400000): # Rough bounds for Israeli ITM longitude
|
||||
logger.warning(f"Longitude {lon} may be outside Israeli bounds")
|
||||
if not (0 < lat < 1400000): # Rough bounds for Israeli ITM latitude
|
||||
logger.warning(f"Latitude {lat} may be outside Israeli bounds")
|
||||
# ITM bounds for Israel: X (longitude) ~150,000-300,000, Y (latitude) ~3,500,000-4,000,000
|
||||
if not (150000 <= lon <= 300000): # ITM longitude bounds for Israel
|
||||
logger.warning(f"Longitude {lon} appears to be outside Israeli ITM bounds (150,000-300,000)")
|
||||
if not (3500000 <= lat <= 4000000): # ITM latitude bounds for Israel
|
||||
logger.warning(f"Latitude {lat} appears to be outside Israeli ITM bounds (3,500,000-4,000,000)")
|
||||
|
||||
return (lon, lat)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user