diff --git a/etl/src/data/database.py b/etl/src/data/database.py index d020dbf..4839824 100644 --- a/etl/src/data/database.py +++ b/etl/src/data/database.py @@ -416,5 +416,19 @@ class Database: properties.seed_id = {region_id} """) + def capacity_global(self): + return self.connection.sql(f""" + SELECT + JSON_EXTRACT(body, '$.content.days') as calendarBody, + strftime(extractions.created_at, '%Y-%m-%d') AS ScrapeDate, + extractions.property_id, + FROM + consultancy_d.extractions + LEFT JOIN + consultancy_d.properties ON properties.id = extractions.property_id + WHERE + type == 'calendar' + """) + diff --git a/etl/src/data/etl_region_capacities.py b/etl/src/data/etl_region_capacities.py index 01759f9..52ca0e8 100644 --- a/etl/src/data/etl_region_capacities.py +++ b/etl/src/data/etl_region_capacities.py @@ -8,7 +8,10 @@ d = data.load() def region_capacities(id: int): # Get Data - df = d.capacity_of_region(id).pl() + if id == -1: + df = d.capacity_global().pl() + else: + df = d.capacity_of_region(id).pl() # turn PropertyIDs to ints for sorting df = df.cast({"property_id": int}) @@ -57,7 +60,4 @@ def region_capacities(id: int): # Create JSON outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': gridData} - return outDict - -out = region_capacities(1) -print(out) \ No newline at end of file + return outDict \ No newline at end of file