Issue 1 Beispiel 1 resolved

#1

Globale region capacities eingefügt: Vorsicht! lange Ladezeit
main
mmaurostoffel 2025-01-05 16:12:16 +01:00
parent 2a9ef9d991
commit 03e78a4105
2 changed files with 19 additions and 5 deletions

View File

@ -416,5 +416,19 @@ class Database:
properties.seed_id = {region_id} 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'
""")

View File

@ -8,7 +8,10 @@ d = data.load()
def region_capacities(id: int): def region_capacities(id: int):
# Get Data # 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 # turn PropertyIDs to ints for sorting
df = df.cast({"property_id": int}) df = df.cast({"property_id": int})
@ -57,7 +60,4 @@ def region_capacities(id: int):
# Create JSON # Create JSON
outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': gridData} outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': gridData}
return outDict return outDict
out = region_capacities(1)
print(out)