Flag hotels absent from successful scrapes as 'not_listed' + widen booking_com_id
Location-search results aren't a fixed hotel set — a sold-out hotel drops out and its last 'available' rate would remain the latest row for that date, reading as a live price and skewing market averages. On each successful per-date scrape, insert a NULL-rate 'not_listed' row for every active hotel missing from the results (skipped if the parse found nothing, which indicates scraper fault not absence). Failed/blocked scrapes write nothing, so genuinely-stale data remains distinguishable by scraped_at. Also: fix the DOW analysis to pick latest-then-filter so a not_listed latest row drops the date instead of resurfacing an older rate, and widen booking_com_id to VARCHAR(255) (some Booking slugs exceed 50 chars). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
75c2adf803
commit
ba6c000903
3 changed files with 31 additions and 5 deletions
|
|
@ -90,7 +90,7 @@ CREATE INDEX IF NOT EXISTS idx_booking_scrape_queue_pending
|
|||
|
||||
CREATE TABLE IF NOT EXISTS booking_com_hotels (
|
||||
id SERIAL PRIMARY KEY,
|
||||
booking_com_id VARCHAR(50) UNIQUE,
|
||||
booking_com_id VARCHAR(255) UNIQUE,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
booking_com_url TEXT,
|
||||
star_rating DECIMAL(2,1),
|
||||
|
|
@ -124,8 +124,9 @@ CREATE TABLE IF NOT EXISTS booking_com_rates (
|
|||
scraped_at TIMESTAMPTZ DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Widen room_type on tables created before the VARCHAR(100) → TEXT change
|
||||
-- Widen columns on tables created before the type changes
|
||||
ALTER TABLE booking_com_rates ALTER COLUMN room_type TYPE TEXT;
|
||||
ALTER TABLE booking_com_hotels ALTER COLUMN booking_com_id TYPE VARCHAR(255);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_booking_com_rates_hotel_date ON booking_com_rates(hotel_id, rate_date);
|
||||
CREATE INDEX IF NOT EXISTS idx_booking_com_rates_date ON booking_com_rates(rate_date);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue