parameterize routing logic - extract api key as env var; allow searching dest by address; limit the number of listings to process to prevent accidental api key usage
This commit is contained in:
parent
57f477c54d
commit
482fff689b
5 changed files with 116 additions and 89 deletions
|
|
@ -1,38 +1,31 @@
|
|||
from data_access import Listing
|
||||
from tqdm import tqdm
|
||||
from geopy.distance import geodesic
|
||||
import logging
|
||||
from rec import routing
|
||||
|
||||
|
||||
def calculate_route(listing_paths: list[str]):
|
||||
log = logging.getLogger(__name__)
|
||||
log.setLevel(logging.INFO)
|
||||
def calculate_route(
|
||||
listing_paths: list[str],
|
||||
destination_address: str,
|
||||
travel_mode: routing.TravelMode,
|
||||
):
|
||||
|
||||
listings = Listing.get_all_listings(listing_paths)
|
||||
BROCK_STREET_LAT_LONG = 51.52570434674584, -0.13956495005056113
|
||||
|
||||
# reduce listings to everything within 7 miles
|
||||
filtered_listings = []
|
||||
for listing in listings:
|
||||
miles = geodesic(BROCK_STREET_LAT_LONG,
|
||||
(listing.latitude, listing.longitude)).miles
|
||||
if listing.isRemoved:
|
||||
log.info(f"Removed-Skip: Skipping {listing.identifier} "
|
||||
"is already removed.")
|
||||
continue
|
||||
if miles > 7:
|
||||
log.info(f"Miles-Skip: Skipping {listing.identifier} as it is "
|
||||
f"{miles} miles away")
|
||||
print(f"Removed-Skip: Skipping {listing.identifier} "
|
||||
"is already removed.")
|
||||
continue
|
||||
if listing.path_routing_json().exists():
|
||||
log.info(
|
||||
(f"Path-Skip: Skipping {listing.identifier} as path routing "
|
||||
"already exists"))
|
||||
print(f"Path-Skip: Skipping {listing.identifier} as path routing "
|
||||
"already exists")
|
||||
continue
|
||||
if (listing.sqm_ocr is None or listing.sqm_ocr < 30
|
||||
or listing.sqm_ocr > 200):
|
||||
log.info((f"Floorplan-Skip: Skipping {listing.identifier} as "
|
||||
f"sqm_ocr is {listing.sqm_ocr}"))
|
||||
print((f"Floorplan-Skip: Skipping {listing.identifier} as "
|
||||
f"sqm_ocr is {listing.sqm_ocr}"))
|
||||
continue
|
||||
filtered_listings.append(listing)
|
||||
|
||||
|
|
@ -40,8 +33,11 @@ def calculate_route(listing_paths: list[str]):
|
|||
f"Filtered listings from {len(listings)} to {len(filtered_listings)}")
|
||||
|
||||
for listing in tqdm(filtered_listings):
|
||||
lat, long = BROCK_STREET_LAT_LONG
|
||||
listing.calculate_route(lat, long, recalculate=False)
|
||||
listing.calculate_route(
|
||||
destination_address,
|
||||
travel_mode,
|
||||
recalculate=False,
|
||||
)
|
||||
traveltime = listing.travel_time[0]
|
||||
duration_minutes = traveltime["duration"] / 60.0
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue