wrongmove/crawler/4_detect_floorplan.py

22 lines
615 B
Python
Raw Normal View History

2025-05-17 22:58:35 +00:00
import asyncio
from data_access import Listing
2025-05-17 22:58:35 +00:00
from tqdm.asyncio import tqdm
import multiprocessing
2025-05-17 22:58:35 +00:00
async def detect_floorplan(listing_paths: list[str]):
listings = Listing.get_all_listings(listing_paths)
2025-05-18 12:27:26 +00:00
cpu_count = multiprocessing.cpu_count() // 4
2025-05-17 22:58:35 +00:00
semaphore = asyncio.Semaphore(cpu_count)
2025-05-31 23:50:43 +00:00
await tqdm.gather(
*[_detect_floorplan_with_semaphore(listing, semaphore) for listing in listings]
)
2025-05-17 22:58:35 +00:00
2025-05-31 23:50:43 +00:00
async def _detect_floorplan_with_semaphore(
listing: Listing, semaphore: asyncio.Semaphore
):
2025-05-17 22:58:35 +00:00
async with semaphore:
return await listing.calculate_sqm_ocr(recalculate=False)