ConsultancyProject_2_ETL/dashboard/routes/web.php

96 lines
3.0 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;
2024-12-18 10:14:56 +01:00
Route::get('/', function () {
2024-12-18 15:14:13 +01:00
$regionPropertyCapacities = Api::regionPropertyCapacities(-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 = [];
foreach ($propsPerRegion as $el) {
$propsPerRegionName[] = $el['name'];
$propsPerRegionCounts[] = $el['count_properties'];
}
2024-12-18 19:52:06 +01:00
$propertiesGeo = Api::propertiesGeo();
return view('overview', ["regionPropertiesCapacities" => $regionPropertyCapacities, "geo" => $propertiesGeo, "growth" => $propertiesGrowth, "propsPerRegion" => [json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]);
2024-12-18 15:14:13 +01:00
});
Route::get('/prop/{id}', function (int $id) {
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', [
'base' => $propertyBase[0],
'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
});
Route::get('/region/{id}', function (int $id) {
2025-01-12 16:49:29 +01:00
$regionCapacitiesRegion = Api::regionCapacities($id);
$regionCapacitiesAll = Api::regionCapacities(-1);
$regionCapacities = [$regionCapacitiesAll, $regionCapacitiesRegion];
2025-01-09 18:34:20 +01:00
2025-01-12 16:49:29 +01:00
return view('region', ['regionCapacities' => $regionCapacities]);
2025-01-09 18:34:20 +01:00
2024-12-18 10:14:56 +01:00
});