fix: playtomic pagination stale-page exit + calculator test assertions

Playtomic tenants API recycles results past its internal limit —
stop after 3 consecutive pages with zero new unique IDs.

Calculator tests: replace hardcoded default values (6 courts, specific
sqm/capex) with DEFAULTS references so tests don't break when
defaults change.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Deeman
2026-02-22 20:06:48 +01:00
parent 2db66efe77
commit c25e20f83a
2 changed files with 47 additions and 28 deletions

View File

@@ -26,6 +26,7 @@ PLAYTOMIC_TENANTS_URL = "https://api.playtomic.io/v1/tenants"
THROTTLE_SECONDS = 2
PAGE_SIZE = 20
MAX_PAGES_PER_BBOX = 500 # safety bound — prevents infinite pagination
MAX_STALE_PAGES = 3 # stop after N consecutive pages with zero new results
# Target markets: Spain, UK/Ireland, Germany, France
BBOXES = [
@@ -51,6 +52,7 @@ def extract(
seen_ids: set[str] = set()
for bbox in BBOXES:
stale_pages = 0
for page in range(MAX_PAGES_PER_BBOX):
params = {
"sport_ids": "PADEL",
@@ -94,6 +96,15 @@ def extract(
if len(tenants) < PAGE_SIZE:
break
# API recycles results past its internal limit — stop early
if new_count == 0:
stale_pages += 1
if stale_pages >= MAX_STALE_PAGES:
logger.info("stopping bbox after %d stale pages", stale_pages)
break
else:
stale_pages = 0
time.sleep(THROTTLE_SECONDS)
payload = json.dumps({"tenants": all_tenants, "count": len(all_tenants)}).encode()