From 03e78a41054b7e396b99b2f4c315a53397250918 Mon Sep 17 00:00:00 2001 From: mmaurostoffel <166130318+mmaurostoffel@users.noreply.github.com> Date: Sun, 5 Jan 2025 16:12:16 +0100 Subject: [PATCH] Issue 1 Beispiel 1 resolved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://gitea.fhgr.ch/stoffelmauro/ConsultancyProject_2_ETL/issues/1 Globale region capacities eingefügt: Vorsicht! lange Ladezeit --- etl/src/data/database.py | 14 ++++++++++++++ etl/src/data/etl_region_capacities.py | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) 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