From dd84ca230a63480ba84a65d8596bfa8f6047d7c1 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Fri, 10 Jul 2026 00:31:08 +0000 Subject: [PATCH] Fix own hotel excluded from scrape and 1-person rates hidden in matrix Include tier=own in get_active_hotels() so the own hotel Booking.com listing is scraped alongside competitors. Change matrix max_persons filter from hard WHERE to ORDER BY priority so hotels with only 1-person rates (e.g. Old Stocks) still show up rather than being silently excluded. Co-Authored-By: Claude Sonnet 4.6 --- backend/api/competitors.py | 10 ++++++---- backend/services/booking_scraper.py | 8 ++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/backend/api/competitors.py b/backend/api/competitors.py index d0a3ab2..b441f9b 100644 --- a/backend/api/competitors.py +++ b/backend/api/competitors.py @@ -778,8 +778,9 @@ async def get_competitor_matrix( WHERE {tier_filter} AND h.is_active = TRUE AND r.rate_date >= :from_date AND r.rate_date <= :to_date - AND (r.max_persons IS NULL OR r.max_persons = 2) - ORDER BY r.hotel_id, r.rate_date, r.scraped_at DESC, r.rate_gross ASC NULLS LAST + 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, + r.scraped_at DESC, r.rate_gross ASC NULLS LAST """), {'from_date': start, 'to_date': end} ) @@ -818,8 +819,9 @@ async def get_competitor_matrix( AND r.rate_date >= :from_date AND r.rate_date <= :to_date AND r.availability_status = 'available' AND r.rate_gross IS NOT NULL - AND (r.max_persons IS NULL OR r.max_persons = 2) - ORDER BY r.hotel_id, r.rate_date, r.scraped_at DESC, r.rate_gross ASC NULLS LAST + 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, + r.scraped_at DESC, r.rate_gross ASC NULLS LAST """), {'from_date': start, 'to_date': end} ) diff --git a/backend/services/booking_scraper.py b/backend/services/booking_scraper.py index ad8d3dd..1d498ca 100644 --- a/backend/services/booking_scraper.py +++ b/backend/services/booking_scraper.py @@ -295,16 +295,16 @@ def cleanup_stale_batches(db: Session, max_age_minutes: int = 60): def get_active_hotels(db: Session) -> List[Dict[str, Any]]: - """Return competitor hotels with a booking_com_url (for hotel-page scraping). - Own and market hotels are excluded — market were auto-discovered from search results; - own hotel rates come from the Newbook API, not Booking.com scraping.""" + """Return own + competitor hotels with a booking_com_url (for hotel-page scraping). + Market hotels are excluded — they are auto-discovered from search results and not + individually monitored. Own hotel IS included so its Booking.com listing is tracked.""" rows = db.execute( text(""" SELECT id, booking_com_id, name, booking_com_url FROM booking_com_hotels WHERE is_active = TRUE AND booking_com_url IS NOT NULL - AND tier = 'competitor' + AND tier IN ('own', 'competitor') ORDER BY display_order, id """) ).fetchall()