Refactor codebase following Clean Code principles and add 229 tests
- Extract helpers to reduce function sizes (listing_tasks, app.py, query.py, listing_fetcher) - Replace nonlocal mutations with _PipelineState dataclass in listing_tasks - Fix bugs: isinstance→equality check in repository, verify_exp for OIDC tokens - Consolidate duplicate filter methods in listing_repository - Move hardcoded config to env vars with backward-compatible defaults - Simplify CLI decorator to auto-build QueryParameters - Add deprecation docstring to data_access.py - Test count: 158 → 387 (all passing)
This commit is contained in:
parent
7e05b3c971
commit
150342bb9e
48 changed files with 5029 additions and 990 deletions
|
|
@ -6,6 +6,11 @@ from rec import routing
|
|||
from models import Listing
|
||||
|
||||
|
||||
def _parse_duration(duration_str: str) -> int:
|
||||
"""Parse a duration string like '123s' to integer seconds."""
|
||||
return int(duration_str.rstrip("s"))
|
||||
|
||||
|
||||
async def calculate_route(
|
||||
repository: ListingRepository,
|
||||
destination_address: str,
|
||||
|
|
@ -18,9 +23,9 @@ async def calculate_route(
|
|||
if limit is not None:
|
||||
listings = listings[:limit]
|
||||
|
||||
destimation_mode = DestinationMode(destination_address, travel_mode)
|
||||
destination_mode = DestinationMode(destination_address, travel_mode)
|
||||
updated_listings = await tqdm.gather(
|
||||
*[update_routing_info(listing, destimation_mode) for listing in listings],
|
||||
*[update_routing_info(listing, destination_mode) for listing in listings],
|
||||
total=len(listings),
|
||||
desc="Updating routing info",
|
||||
)
|
||||
|
|
@ -46,12 +51,12 @@ async def update_routing_info(
|
|||
|
||||
routes: list[Route] = []
|
||||
for route_data in routes_data["routes"]:
|
||||
duration_s = int(route_data["duration"].split("s")[0])
|
||||
duration_s = _parse_duration(route_data["duration"])
|
||||
route = Route(
|
||||
legs=[
|
||||
RouteLegStep(
|
||||
distance_meters=step_data["distanceMeters"],
|
||||
duration_s=int(step_data["staticDuration"].split("s")[0]),
|
||||
duration_s=_parse_duration(step_data["staticDuration"]),
|
||||
travel_mode=routing.TravelMode(step_data["travelMode"]),
|
||||
)
|
||||
for step_data in route_data["legs"][0]["steps"]
|
||||
|
|
@ -63,4 +68,4 @@ async def update_routing_info(
|
|||
listing.routing_info_json = listing.serialize_routing_info(
|
||||
{**listing.routing_info, **{destination_mode: routes}}
|
||||
)
|
||||
return listing
|
||||
return listing
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue