From 2013d2b440b0d8f2b4ccf601fd27cfe9c449e901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2=20Diani?= Date: Sat, 11 Jan 2025 20:52:02 +0100 Subject: [PATCH] Wiederinstandsetzung Heatmap @stoffelmauro musste dazu etwas in der API anpassen. --- dashboard/app/Api.php | 10 ++++-- dashboard/resources/views/overview.blade.php | 8 ++--- dashboard/routes/web.php | 4 +-- .../data/etl_region_properties_capacities.py | 34 ++++++++----------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/dashboard/app/Api.php b/dashboard/app/Api.php index 5a45579..ca22a14 100644 --- a/dashboard/app/Api.php +++ b/dashboard/app/Api.php @@ -22,7 +22,7 @@ class Api return Cache::get($request); } - $get = Http::get($request); + $get = Http::timeout(600)->get($request); if($get->successful()){ $result = $get->json(); @@ -63,9 +63,9 @@ class Api return self::get("/property/{$id}/base"); } - public static function regionCapacities(int $id): mixed + public static function regionPropertyCapacities(int $id): mixed { - return self::get("/region/{$id}/capacities"); + return self::get("/region/{$id}/properties/capacities"); } public static function propertyCapacitiesMonthly(int $id, string $date): mixed @@ -83,6 +83,10 @@ class Api return self::get("/property/{$id}/neighbours"); } + public static function regionCapacities(int $id): mixed + { + return self::get("/region/{$id}/capacities"); + } diff --git a/dashboard/resources/views/overview.blade.php b/dashboard/resources/views/overview.blade.php index 7256173..4957555 100644 --- a/dashboard/resources/views/overview.blade.php +++ b/dashboard/resources/views/overview.blade.php @@ -58,7 +58,7 @@ const sharedOptions = { } } } -const extractionDates = {!! json_encode($growth['dates']) !!}; +const extractionDates = {!! json_encode($regionPropertiesCapacities['scrapeDates']) !!}; const chartHeatmap = document.getElementById('chart-heatmap'); const cHeatmap = echarts.init(chartHeatmap); @@ -80,7 +80,7 @@ const cHeatmapOptions = { show: false, name: 'Kurzzeitmietobjekt', type: 'category', - data: {!! json_encode($heat['property_ids']) !!}, + data: extractionDates, splitArea: { show: false }, @@ -91,7 +91,7 @@ const cHeatmapOptions = { yAxis: { show: false, type: 'category', - data: extractionDates, + data: {!! json_encode($regionPropertiesCapacities['property_ids']) !!}, splitArea: { show: true } @@ -116,7 +116,7 @@ const cHeatmapOptions = { name: 'Auslastung', type: 'heatmap', blurSize: 0, - data: {!! json_encode($heat['values']) !!}, + data: {!! json_encode($regionPropertiesCapacities['values']) !!}, label: { show: false }, diff --git a/dashboard/routes/web.php b/dashboard/routes/web.php index 6d29f63..5857ef1 100644 --- a/dashboard/routes/web.php +++ b/dashboard/routes/web.php @@ -5,7 +5,7 @@ use App\Api; Route::get('/', function () { - $regionHeat = Api::regionCapacities(1); + $regionPropertyCapacities = Api::regionPropertyCapacities(-1); $propertiesGrowth = Api::propertiesGrowth(); $propsPerRegion = Api::propertiesPerRegion(); $propsPerRegionName = []; @@ -18,7 +18,7 @@ Route::get('/', function () { $propertiesGeo = Api::propertiesGeo(); - return view('overview', ["heat" => $regionHeat, "geo" => $propertiesGeo, "growth" => $propertiesGrowth, "propsPerRegion" => [json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]); + return view('overview', ["regionPropertiesCapacities" => $regionPropertyCapacities, "geo" => $propertiesGeo, "growth" => $propertiesGrowth, "propsPerRegion" => [json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]); }); Route::get('/prop/{id}', function (int $id) { diff --git a/etl/src/data/etl_region_properties_capacities.py b/etl/src/data/etl_region_properties_capacities.py index 4cb351d..c2d564b 100644 --- a/etl/src/data/etl_region_properties_capacities.py +++ b/etl/src/data/etl_region_properties_capacities.py @@ -1,8 +1,8 @@ -import data -import polars as pl from io import StringIO -import numpy as np +import polars as pl + +import data d = data.load() @@ -26,10 +26,9 @@ def region_properties_capacities(id: int): # Merge Dataframe to generate indices df = df.join(datesDF, on='ScrapeDate') df = df.join(propIdDF, on='property_id') - # Drop now useless columns ScrapeDate and property_id - df = df[['ScrapeDate', 'calendarBody', 'date_index', 'prop_index']] + # Calculate grid values - gridData = [] + gridData = pl.DataFrame(schema=[("scrape_date", pl.String), ("property_id", pl.String), ("sum_hor", pl.Int64)]) for row in df.rows(named=True): # Return 0 for sum if calendar is null if row['calendarBody']: @@ -37,25 +36,22 @@ def region_properties_capacities(id: int): sum_hor = calDF.sum_horizontal()[0] else: sum_hor = 0 - # With Index - # gridData.append([row['prop_index'], row['date_index'], sum_hor]) - # With ScrapeDate - gridData.append([row['ScrapeDate'], row['date_index'], sum_hor]) - gridData = np.array(gridData) - # get all values to calculate Max - allValues = gridData[:, 2].astype(int) - maxValue = np.max(allValues) - gridData[:, 2] = (allValues*100)/maxValue + gridData = gridData.vstack(pl.DataFrame({"scrape_date" : row['ScrapeDate'], "property_id": str(row['property_id']), "sum_hor": sum_hor})) - # Return back to list - gridData = gridData.tolist() + # get the overall maximum sum + maxValue = gridData['sum_hor'].max() + values = [] + + for row in gridData.rows(named=True): + capacity = (row['sum_hor']*100)/maxValue + values.append((row['scrape_date'], row['property_id'], capacity)) # Cast listOfDates to datetime listOfDates = listOfDates.cast(pl.Date).to_list() - listOfPropertyIDs = listOfPropertyIDs.to_list() + listOfPropertyIDs = listOfPropertyIDs.cast(pl.String).to_list() # Create JSON - outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': gridData} + outDict = {'scrapeDates': listOfDates, 'property_ids': listOfPropertyIDs, 'values': values} return outDict \ No newline at end of file