ConsultancyProject_2_ETL/dashboard/routes/web.php

154 lines
4.9 KiB
PHP
Raw Normal View History

2024-12-18 10:14:56 +01:00
<?php
use Illuminate\Support\Facades\Route;
2024-12-18 15:14:13 +01:00
use App\Api;
2025-01-13 22:50:03 +01:00
use App\Chart;
2024-12-18 10:14:56 +01:00
Route::get('/', function () {
2024-12-18 15:14:13 +01:00
2025-01-12 20:55:46 +01:00
$regionBase = Api::regionBase(-1);
$regionBase[] = ['region_name' => 'Alle Regionen', 'region_id' => -1];
$regionPropertyCapacities = Api::regionPropertiesCapacities(-1);
2024-12-18 19:52:06 +01:00
$propertiesGrowth = Api::propertiesGrowth();
2024-12-18 15:14:13 +01:00
$propsPerRegion = Api::propertiesPerRegion();
$propsPerRegionName = [];
$propsPerRegionCounts = [];
$propsPerRegionId = [];
2024-12-18 15:14:13 +01:00
foreach ($propsPerRegion as $el) {
$propsPerRegionName[] = $el['name'];
$propsPerRegionId[] = $el['id'];
2024-12-18 15:14:13 +01:00
$propsPerRegionCounts[] = $el['count_properties'];
}
2025-01-13 22:50:03 +01:00
$chartOptions = [
'colors' => Chart::colors()
];
2024-12-18 19:52:06 +01:00
$propertiesGeo = Api::propertiesGeo();
2025-01-13 22:50:03 +01:00
return view('overview', [
"regions" => $regionBase,
"regionPropertiesCapacities" => $regionPropertyCapacities,
"geo" => $propertiesGeo,
"growth" => $propertiesGrowth,
"chartOptions" => $chartOptions,
"propsPerRegion" => [json_encode($propsPerRegionId), json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]);
2024-12-18 15:14:13 +01:00
});
2025-01-14 22:11:31 +01:00
Route::get('/region/{id}', function (int $id) {
$regionBaseAll = Api::regionBase(-1);
$regionBaseAll[] = ['region_name' => 'Alle Regionen', 'region_id' => -1];
$regionBaseRegion = $id >= 0 ? Api::regionBase($id) : [['region_name' => 'Alle Regionen']];
$regionPropertiesCapacities = Api::regionPropertiesCapacities($id);
$regionCapacitiesRegion = Api::regionCapacities($id);
$regionCapacitiesAll = Api::regionCapacities(-1);
$regionCapacitiesMonthly = [];
$regionCapacitiesDaily = [];
$regionPredictions = [];
foreach ($regionCapacitiesRegion['dates'] as $date) {
$regionCapacitiesMonthly[] = Api::regionCapacitiesMonthly($id, $date);
$regionCapacitiesDaily[] = Api::regionCapacitiesDaily($id, $date);
$regionPredictions[] = Api::regionMovingAverage($id, $date);
}
$chartOptions = [
'colors' => Chart::colors()
];
$regionCapacities = [
'all' => $regionCapacitiesAll,
'region' => $regionCapacitiesRegion,
'region_monthly' => $regionCapacitiesMonthly,
'region_daily' => $regionCapacitiesDaily
];
return view('region', [
'chartOptions' => $chartOptions,
'startDate' => $regionCapacitiesRegion['dates'][0],
'regions' => $regionBaseAll,
'region' => $regionBaseRegion,
'region_id' => $id,
'regionCapacities' => $regionCapacities,
'regionPropertiesCapacities' => $regionPropertiesCapacities,
'predictions' => $regionPredictions]);
});
Route::get('/property/{id}', function (int $id) {
2024-12-18 15:14:13 +01:00
2025-01-14 22:11:31 +01:00
$chartOptions = [
'colors' => Chart::colors()
];
2025-01-15 16:57:18 +01:00
$regionBaseAll = Api::regionBase(-1);
$regionBaseAll[] = ['region_name' => 'Alle Regionen', 'region_id' => -1];
2024-12-18 19:52:06 +01:00
$propertyBase = Api::propertyBase($id);
2025-01-12 16:49:29 +01:00
$calendars = Api::propertyExtractions($id);
$propertyCapacities = Api::propertyCapacities($id);
2025-01-09 18:34:20 +01:00
$propertyNeighbours = Api::propertyNeighbours($id);
2025-01-12 16:49:29 +01:00
$regionCapacitiesRegion = Api::regionCapacities($propertyBase[0]['region_id']);
$regionCapacitiesAll = Api::regionCapacities(-1);
$regionCapacities = [[],[]];
2025-01-09 18:34:20 +01:00
$propertyCapacitiesMonthly = [];
$propertyCapacitiesDaily = [];
2025-01-12 16:49:29 +01:00
foreach ($propertyCapacities['dates'] as $date) {
$propertyCapacitiesMonthly[] = Api::propertyCapacitiesMonthly($id, $date);
$propertyCapacitiesDaily[] = Api::propertyCapacitiesDaily($id, $date);
}
2025-01-12 16:49:29 +01:00
// 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
2024-12-18 15:14:13 +01:00
$data = [];
$dates = [];
2025-01-12 16:49:29 +01:00
foreach ($calendars as $el) {
2024-12-18 15:14:13 +01:00
$series = [];
2025-01-12 16:49:29 +01:00
$calendar = json_decode($el['calendar'], 1);
2024-12-18 15:14:13 +01:00
2025-01-12 16:49:29 +01:00
foreach ($calendar as $date => $status) {
2024-12-18 15:14:13 +01:00
$series[] = [$date, $status];
}
$data[] = $series;
}
2025-01-12 16:49:29 +01:00
return view('property', [
2025-01-14 22:11:31 +01:00
'chartOptions' => $chartOptions,
'startDate' => $propertyCapacities['dates'][0],
2025-01-12 16:49:29 +01:00
'base' => $propertyBase[0],
2025-01-15 16:57:18 +01:00
'regions' => $regionBaseAll,
2025-01-12 16:49:29 +01:00
'extractiondates' => json_encode($propertyCapacities['dates']),
'calendar' => $data,
'propertyCapacities' => $propertyCapacities,
'capacitiesMonthly' => $propertyCapacitiesMonthly,
'capacitiesDaily' => $propertyCapacitiesDaily,
'regionCapacities' => $regionCapacities,
'neighbours' => $propertyNeighbours
]);
2025-01-09 18:34:20 +01:00
});