- Belegung am {{ json_decode($extractiondates)[0] }} + Belegung am
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 28cd988..b8f322f 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