Fix max_persons extraction: read from span text not block_id segment 2

Old Stocks block_id has 0 in position 2 (not the persons count) so all
its rates were stored as max_persons=0 and deprioritised in the matrix.

Now reads max_persons from the visible 'Max persons: N' span (matching
the original scrapy spider), with aria-label/title fallback. block_id
segment 2 is unreliable across different hotel layouts.

Also treat max_persons=0 as unknown in the matrix ORDER BY priority.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-10 01:22:51 +00:00
parent 52455328e7
commit 8ccc0e272d
2 changed files with 20 additions and 6 deletions

View file

@ -779,7 +779,7 @@ async def get_competitor_matrix(
AND h.is_active = TRUE
AND r.rate_date >= :from_date AND r.rate_date <= :to_date
ORDER BY r.hotel_id, r.rate_date,
CASE WHEN r.max_persons IS NULL OR r.max_persons = 2 THEN 0 ELSE 1 END,
CASE WHEN r.max_persons IS NULL OR r.max_persons = 0 OR r.max_persons = 2 THEN 0 ELSE 1 END,
r.scraped_at DESC, r.rate_gross ASC NULLS LAST
"""),
{'from_date': start, 'to_date': end}
@ -820,7 +820,7 @@ async def get_competitor_matrix(
AND r.availability_status = 'available'
AND r.rate_gross IS NOT NULL
ORDER BY r.hotel_id, r.rate_date,
CASE WHEN r.max_persons IS NULL OR r.max_persons = 2 THEN 0 ELSE 1 END,
CASE WHEN r.max_persons IS NULL OR r.max_persons = 0 OR r.max_persons = 2 THEN 0 ELSE 1 END,
r.scraped_at DESC, r.rate_gross ASC NULLS LAST
"""),
{'from_date': start, 'to_date': end}