Changed join to price table to a LEFT JOIN so that I can also keep track of the Alamo restaurant operating hours with the same tables
This commit is contained in:
Executable
+50
@@ -0,0 +1,50 @@
|
||||
WITH cte AS (
|
||||
SELECT scrape_data._id,
|
||||
scrape_data.is_operational,
|
||||
scrape_data.queue_time,
|
||||
scrape_data.queue_status_message,
|
||||
scrape_data.is_open,
|
||||
scrape_data.open_time,
|
||||
scrape_data.close_time,
|
||||
scrape_data.time_stamp,
|
||||
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||
FROM knoebels."LZ_attractions_io" scrape_data
|
||||
)
|
||||
SELECT cte._id,
|
||||
poi.name,
|
||||
prices.price,
|
||||
cte.is_operational,
|
||||
cte.queue_time,
|
||||
cte.queue_status_message,
|
||||
cte.is_open,
|
||||
cte.open_time,
|
||||
cte.close_time,
|
||||
cte.time_stamp,
|
||||
rm.hand_stamp_included,
|
||||
rm.bargain_night_included,
|
||||
rm.capacity,
|
||||
rm.duration,
|
||||
poi.summary,
|
||||
poi.keywords,
|
||||
poi.default_image,
|
||||
poi.location,
|
||||
poi.featured,
|
||||
poi.wayfinding_enabled,
|
||||
poi.visible_on_map,
|
||||
poi.category,
|
||||
poi.minimum_height_requirement,
|
||||
poi.minimum_unaccompanied_height_requirement,
|
||||
poi.maximum_height_requirement,
|
||||
poi.minimum_age_requirement,
|
||||
poi.minimum_unaccompanied_age_requirement,
|
||||
poi.maximum_age_requirement,
|
||||
poi.restriction_summary
|
||||
FROM cte
|
||||
JOIN knoebels.ride_master rm ON cte._id = rm.attractions_dot_io_id
|
||||
JOIN knoebels."LZ_attractions_io_poi" poi ON cte._id = poi._id
|
||||
LEFT JOIN ( SELECT row_number() OVER (PARTITION BY ride_data_in.ride ORDER BY ride_data_in.time_stamp DESC) AS row_number,
|
||||
ride_data_in.time_stamp,
|
||||
ride_data_in.ride,
|
||||
ride_data_in.price
|
||||
FROM knoebels.ride_data_in) prices ON prices.ride = rm.ride AND prices.row_number = 1
|
||||
WHERE cte.row_number = 1;
|
||||
@@ -42,8 +42,11 @@ SELECT livedata.time_stamp
|
||||
,restriction_summary
|
||||
--FROM knoebels."LZ_attractions_io" AS livedata
|
||||
FROM livedata
|
||||
--This POI data comes from a massive JSON file hosted by attractions.io the app downloads it on first launch. Not sure how often it's updated or only as-needed
|
||||
JOIN knoebels."LZ_attractions_io_poi" AS poi ON livedata._id = poi._id
|
||||
-- This is my own "master" file for ride data, for data points not served by the attractions.io API. Handstamp inclusions/exclusions, capacity, duration, etc.
|
||||
JOIN knoebels.ride_master rm ON livedata._id = rm.attractions_dot_io_id
|
||||
-- fetch most recent price data, scraped from webpage, this can differ from the POI data used by the app
|
||||
JOIN (SELECT row_number() OVER (PARTITION BY ride ORDER BY time_stamp DESC) AS row_number, * FROM knoebels.ride_data_in) prices ON prices.ride = rm.ride and prices.row_number = 1
|
||||
--ORDER BY name, time_stamp
|
||||
--where name = 'Sklooosh'
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
WITH CTE AS (
|
||||
SELECT *,
|
||||
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||
FROM knoebels."LZ_attractions_io" scrape_data
|
||||
)
|
||||
SELECT CTE.time_stamp
|
||||
,CTE._id
|
||||
,poi.name
|
||||
,CTE.is_operational
|
||||
,CTE.is_open
|
||||
,CTE.queue_status_message
|
||||
,last_online.time_stamp AS last_online
|
||||
FROM CTE
|
||||
JOIN knoebels."LZ_attractions_io_poi" AS poi ON CTE._id = poi._id
|
||||
JOIN knoebels.ride_master rm ON CTE._id = rm.attractions_dot_io_id
|
||||
LEFT JOIN (
|
||||
SELECT *,
|
||||
row_number() OVER (PARTITION BY scrape_data._id ORDER BY scrape_data.time_stamp DESC) AS row_number
|
||||
FROM knoebels."LZ_attractions_io" scrape_data
|
||||
where is_operational = true and is_open = true
|
||||
) AS last_online
|
||||
ON CTE._id = last_online._id and last_online.row_number = 1
|
||||
WHERE CTE.row_number = 1
|
||||
AND (CTE.is_operational = false OR (CTE.queue_status_message IS NOT NULL AND CTE.queue_status_message != ''))
|
||||
ORDER BY name;
|
||||
Reference in New Issue
Block a user