2025-05-17 22:58:35 +00:00
|
|
|
import asyncio
|
2024-03-10 18:49:39 +00:00
|
|
|
from data_access import Listing
|
2025-05-17 22:58:35 +00:00
|
|
|
from tqdm.asyncio import tqdm
|
|
|
|
|
import multiprocessing
|
2024-03-10 18:49:39 +00:00
|
|
|
|
|
|
|
|
|
2025-05-17 22:58:35 +00:00
|
|
|
async def detect_floorplan(listing_paths: list[str]):
|
2025-05-14 21:05:59 +00:00
|
|
|
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-11 19:06:08 +00:00
|
|
|
|
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)
|