fix types and format

This commit is contained in:
Viktor Barzin 2025-05-18 12:27:26 +00:00
parent 91d3237516
commit b873eaf203
No known key found for this signature in database
GPG key ID: 4056458DBDBF8863
8 changed files with 117 additions and 172 deletions

View file

@ -1,5 +1,4 @@
import asyncio
import pathlib
from data_access import Listing
from tqdm.asyncio import tqdm
import multiprocessing
@ -7,25 +6,16 @@ import multiprocessing
async def detect_floorplan(listing_paths: list[str]):
listings = Listing.get_all_listings(listing_paths)
cpu_count = multiprocessing.cpu_count() / 4
cpu_count = multiprocessing.cpu_count() // 4
semaphore = asyncio.Semaphore(cpu_count)
await tqdm.gather(
*[_detect_floorplan_with_semaphore(listing, semaphore) for listing in listings]
)
await tqdm.gather(*[
_detect_floorplan_with_semaphore(listing, semaphore)
for listing in listings
])
async def _detect_floorplan_with_semaphore(
listing: Listing, semaphore: asyncio.Semaphore
):
async def _detect_floorplan_with_semaphore(listing: Listing,
semaphore: asyncio.Semaphore):
async with semaphore:
return await listing.calculate_sqm_ocr(recalculate=False)
def main():
listing_paths = sorted(list(pathlib.Path("data/rs").glob("*/listing.json")))
detect_floorplan(listing_paths)
if __name__ == "__main__":
main()