From 992e299829a1472b52bfab8db5700a42b6a7a973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gi=C3=B2=20Diani?= Date: Sun, 12 Jan 2025 16:49:29 +0100 Subject: [PATCH] =?UTF-8?q?=C3=9Cberarbeitung=20Property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dashboard/resources/css/app.css | 2 +- dashboard/resources/views/property.blade.php | 43 +++++++++------ dashboard/routes/web.php | 55 ++++++++++++++------ etl/src/data/database.py | 1 + etl/src/data/etl_property_capacities.py | 2 +- 5 files changed, 69 insertions(+), 34 deletions(-) diff --git a/dashboard/resources/css/app.css b/dashboard/resources/css/app.css index 3299a37..c6402e0 100644 --- a/dashboard/resources/css/app.css +++ b/dashboard/resources/css/app.css @@ -139,7 +139,7 @@ body.overview main{ "chart3 chart3 chart3 chart2 chart2 chart2 chart4 chart4" } -body.property main{ +body.timeline main{ grid-template-columns: repeat(4, minmax(10%, 50%)); grid-template-rows: repeat(3, 1fr) 4em; grid-template-areas: diff --git a/dashboard/resources/views/property.blade.php b/dashboard/resources/views/property.blade.php index 4326599..5429243 100644 --- a/dashboard/resources/views/property.blade.php +++ b/dashboard/resources/views/property.blade.php @@ -1,5 +1,5 @@ @extends('base') -@section('body-class', 'property') +@section('body-class', 'timeline') @section('header') Property {{ $base['property_platform_id'] }} @@ -28,7 +28,7 @@

- Belegung am {{ json_decode($extractiondates)[0] }} + Belegung am

@@ -169,9 +169,12 @@ const chartCapacity = document.getElementById('chart-capacity'); const cCapacity = echarts.init(chartCapacity); const cCapacityOptions = { + legend: { + data: ['Auslastung Property', 'Auslastung {{ $base['region_name'] }}', 'Auslastung alle Regionen'] + }, tooltip: { trigger: 'axis', - formatter: 'Datum Scraping: {b}
Verfügbarkeit: {c} %' + valueFormatter: (value) => value.toFixed(2)+' %' }, grid: { top: 20, @@ -183,7 +186,7 @@ const cCapacityOptions = { xAxis: { type: 'category', boundaryGap: false, - data: {!! json_encode($capacities['dates']) !!}, + data: {!! json_encode($propertyCapacities['dates']) !!}, name: 'Zeitpunkt Scraping', nameLocation: 'center', nameGap: 24, @@ -202,18 +205,26 @@ const cCapacityOptions = { fontWeight: 'bold', } }, - series: [{ - name: 'Auslastung', - type: 'line', - symbolSize: 7, - data: {!! json_encode($capacities['capacities']) !!} - }, + series: [ { - name: 'Auslastung Region', - type: 'line', - symbolSize: 7, - data: {!! json_encode($capacities['capacities']) !!} - }] + name: 'Auslastung Property', + type: 'line', + symbolSize: 7, + data: {!! json_encode($propertyCapacities['capacities']) !!} + }, + { + name: 'Auslastung {{ $base['region_name'] }}', + type: 'line', + symbolSize: 7, + data: {!! json_encode($regionCapacities[0]) !!} + }, + { + name: 'Auslastung alle Regionen', + type: 'line', + symbolSize: 7, + data: {!! json_encode($regionCapacities[1]) !!} + } + ] }; cCapacity.setOption(cCapacityOptions); @@ -225,7 +236,7 @@ const h2Belegung = document.getElementById('belegung-title'); const cCalendarOptions = { timeline: { show: false, - data: {!! $extractiondates !!}, + data: {!! json_encode($propertyCapacities['dates']) !!}, axisType: 'time', }, visualMap: { diff --git a/dashboard/routes/web.php b/dashboard/routes/web.php index 5857ef1..069296d 100644 --- a/dashboard/routes/web.php +++ b/dashboard/routes/web.php @@ -24,31 +24,44 @@ Route::get('/', function () { Route::get('/prop/{id}', function (int $id) { $propertyBase = Api::propertyBase($id); - $extractions = Api::propertyExtractions($id); + $calendars = Api::propertyExtractions($id); $propertyCapacities = Api::propertyCapacities($id); $propertyNeighbours = Api::propertyNeighbours($id); - //$regionCapacities = Api::regionCapacities(-1); - $regionCapacities = []; + $regionCapacitiesRegion = Api::regionCapacities($propertyBase[0]['region_id']); + $regionCapacitiesAll = Api::regionCapacities(-1); + $regionCapacities = [[],[]]; $propertyCapacitiesMonthly = []; $propertyCapacitiesDaily = []; - foreach ($extractions as $extraction) { - $propertyCapacitiesMonthly[] = Api::propertyCapacitiesMonthly($id, $extraction['created_at']); - $propertyCapacitiesDaily[] = Api::propertyCapacitiesDaily($id, $extraction['created_at']); + foreach ($propertyCapacities['dates'] as $date) { + $propertyCapacitiesMonthly[] = Api::propertyCapacitiesMonthly($id, $date); + $propertyCapacitiesDaily[] = Api::propertyCapacitiesDaily($id, $date); } + // filter out all date, which were not scraped for the property + foreach ($regionCapacitiesAll['dates'] as $index => $date) { + if(in_array($date, $propertyCapacities['dates'])){ + $regionCapacities[0][] = $regionCapacitiesAll['capacities'][$index]; + } + } + + foreach ($regionCapacitiesRegion['dates'] as $index => $date) { + if(in_array($date, $propertyCapacities['dates'])){ + $regionCapacities[1][] = $regionCapacitiesRegion['capacities'][$index]; + } + } + + // prepare data for calendar chart $data = []; $dates = []; - foreach ($extractions as $ext) { + foreach ($calendars as $el) { $series = []; - $dates[] = $ext['created_at']; + $calendar = json_decode($el['calendar'], 1); - $extCalendar = json_decode($ext['calendar'], 1); - - foreach ($extCalendar as $date => $status) { + foreach ($calendar as $date => $status) { $series[] = [$date, $status]; } @@ -56,17 +69,27 @@ Route::get('/prop/{id}', function (int $id) { } - return view('property', ['base' => $propertyBase[0], "extractiondates" => json_encode($dates), "calendar" => $data, 'capacities' => $propertyCapacities, 'capacitiesMonthly' => $propertyCapacitiesMonthly, 'capacitiesDaily' => $propertyCapacitiesDaily, 'regionCapacities' => $regionCapacities, 'neighbours' => $propertyNeighbours]); + return view('property', [ + 'base' => $propertyBase[0], + 'extractiondates' => json_encode($propertyCapacities['dates']), + 'calendar' => $data, + 'propertyCapacities' => $propertyCapacities, + 'capacitiesMonthly' => $propertyCapacitiesMonthly, + 'capacitiesDaily' => $propertyCapacitiesDaily, + 'regionCapacities' => $regionCapacities, + 'neighbours' => $propertyNeighbours + ]); + }); Route::get('/region/{id}', function (int $id) { - $regionCapacities = Api::regionCapacities($id); + $regionCapacitiesRegion = Api::regionCapacities($id); + $regionCapacitiesAll = Api::regionCapacities(-1); + $regionCapacities = [$regionCapacitiesAll, $regionCapacitiesRegion]; - dump($regionCapacities); - - return view('region', ['capacities' => $regionCapacities]); + return view('region', ['regionCapacities' => $regionCapacities]); }); diff --git a/etl/src/data/database.py b/etl/src/data/database.py index b5f2f1b..fc1739d 100644 --- a/etl/src/data/database.py +++ b/etl/src/data/database.py @@ -400,6 +400,7 @@ class Database: p.property_platform_id, p.created_at as first_found, p.last_found, + r.id as region_id, r.name as region_name FROM consultancy_d.properties p diff --git a/etl/src/data/etl_property_capacities.py b/etl/src/data/etl_property_capacities.py index 37db5a1..e608a19 100644 --- a/etl/src/data/etl_property_capacities.py +++ b/etl/src/data/etl_property_capacities.py @@ -28,7 +28,7 @@ def property_capacities(id: int): count_days.append(len(liste)) counts = pl.DataFrame({"count_days" : count_days, "sum" : sum_hor}) - result = {"capacities": [], "dates": extractions['created_at'].cast(pl.Datetime).to_list() } + result = {"capacities": [], "dates": extractions['created_at'].cast(pl.Date).to_list() } for row in counts.rows(named=True): max_capacity = row['count_days'] * 2