ConsultancyProject_2_ETL/dashboard/routes/web.php

229 lines
7.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;
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);
$regionPropertiesCapacities = Api::regionPropertiesCapacities(-1);
2024-12-18 19:52:06 +01:00
$propertiesGrowth = Api::propertiesGrowth();
2025-01-18 17:31:31 +01:00
$regions = Api::regions()['regions'];
$propertiesPerRegion = $regions;
$regions[] = ['name' => 'Alle Regionen', 'id' => -1];
$propertiesGeo = Api::propertiesGeo()['properties'];
2024-12-18 15:14:13 +01:00
2025-01-18 17:31:31 +01:00
$heatmapValues = [];
2025-01-13 22:50:03 +01:00
2025-01-18 17:31:31 +01:00
foreach ($regionPropertiesCapacities['values'] as $el) {
$heatmapValues[] = array_values($el);
}
2024-12-18 19:52:06 +01:00
$diagramsOptions = [
"shared" => [
"extractionDates" => json_encode($regionPropertiesCapacities['dates']),
"colors" => Chart::colors()
],
"heatmap" => [
"yAxis" => [
"data" => json_encode($regionPropertiesCapacities['property_ids'])
],
"series" => [
2025-01-18 17:31:31 +01:00
"data" => json_encode($heatmapValues)
]
],
"propertiesPerRegion" => [
"yAxis" => [
2025-01-18 17:31:31 +01:00
"data" => json_encode(array_column($propertiesPerRegion, 'count_properties'))
],
"xAxis" => [
2025-01-18 17:31:31 +01:00
"data" => json_encode(array_column($propertiesPerRegion, 'name'))
]
],
"extractions" => [
"series" => $propertiesGrowth,
]
];
2025-01-13 22:50:03 +01:00
return view('overview', [
"regions" => $regions,
"region" => $regionBase,
"diagramsOptions" => $diagramsOptions,
2025-01-13 22:50:03 +01:00
"geo" => $propertiesGeo,
]);
2024-12-18 15:14:13 +01:00
});
2025-01-14 22:11:31 +01:00
Route::get('/region/{id}', function (int $id) {
2025-01-18 17:31:31 +01:00
$regions = Api::regions()['regions'];
$regions[] = ['name' => 'Alle Regionen', 'id' => -1];
2025-01-18 18:41:21 +01:00
$region = $id >= 0 ? Api::regionBase($id) : ['name' => 'Alle Regionen'];
2025-01-14 22:11:31 +01:00
$regionPropertiesCapacities = Api::regionPropertiesCapacities($id);
$regionCapacitiesRegion = Api::regionCapacities($id);
$regionCapacitiesAll = Api::regionCapacities(-1);
$regionCapacitiesMonthly = [];
$regionCapacitiesDaily = [];
$regionPredictions = [];
2025-01-18 17:31:31 +01:00
$heatmapValues = [];
foreach ($regionPropertiesCapacities['values'] as $el) {
$heatmapValues[] = array_values($el);
}
2025-01-14 22:11:31 +01:00
foreach ($regionCapacitiesRegion['dates'] as $date) {
$regionCapacitiesMonthly[] = Api::regionCapacitiesMonthly($id, $date);
$regionCapacitiesDaily[] = Api::regionCapacitiesDaily($id, $date);
$regionPredictions[] = Api::regionMovingAverage($id, $date);
}
$diagramsOptions = [
"shared" => [
"extractionDates" => json_encode($regionPropertiesCapacities['dates']),
"colors" => Chart::colors()
],
"heatmap" => [
"xAxis" => [
"data" => json_encode($regionPropertiesCapacities['dates'])
],
"yAxis" => [
"data" => json_encode($regionPropertiesCapacities['property_ids'])
],
"series" => [
2025-01-18 17:31:31 +01:00
"data" => json_encode($heatmapValues)
]
],
"predictions" => [
"options" => $regionPredictions,
],
"capacityMonthly" => [
"options" => $regionCapacitiesMonthly,
],
"capacityDaily" => [
"options" => $regionCapacitiesDaily,
],
"capacity" => [
"xAxis" => [
"data" => json_encode($regionCapacitiesRegion['dates'])
],
"series" => [
"all" => [
"data" => json_encode($regionCapacitiesAll['capacities'])
],
"region" => [
"data" => json_encode($regionCapacitiesRegion['capacities'])
]
]
]
2025-01-14 22:11:31 +01:00
];
return view('region', [
'diagramsOptions' => $diagramsOptions,
2025-01-14 22:11:31 +01:00
'startDate' => $regionCapacitiesRegion['dates'][0],
'regions' => $regions,
'region' => $region,
'regionId' => $id,
2025-01-14 22:11:31 +01:00
'regionPropertiesCapacities' => $regionPropertiesCapacities,
'predictions' => $regionPredictions]);
});
Route::get('/property/{id}', function (int $id) {
2024-12-18 15:14:13 +01:00
2025-01-18 17:31:31 +01:00
$regions = Api::regions()['regions'];
$regions[] = ['name' => 'Alle Regionen', 'id' => -1];
$base = Api::propertyBase($id);
2025-01-18 17:31:31 +01:00
$calendars = Api::propertyExtractions($id)['extractions'];
$propertyCapacities = Api::propertyCapacities($id);
2025-01-18 17:31:31 +01:00
$propertyNeighbours = Api::propertyNeighbours($id)['neighbours'];
$regionCapacitiesRegion = Api::regionCapacities($base['region_id']);
2025-01-12 16:49:29 +01:00
$regionCapacitiesAll = Api::regionCapacities(-1);
$regionCapacities = [[],[]];
2025-01-09 18:34:20 +01:00
$propertyCapacitiesMonthly = [];
$propertyCapacitiesDaily = [];
if($propertyCapacities){
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];
}
2025-01-12 16:49:29 +01:00
}
foreach ($regionCapacitiesRegion['dates'] as $index => $date) {
if(in_array($date, $propertyCapacities['dates'])){
$regionCapacities[1][] = $regionCapacitiesRegion['capacities'][$index];
}
2025-01-12 16:49:29 +01:00
}
}else{
return view('property-nodata', [
2025-01-18 17:31:31 +01:00
'base' => $base,
'regions' => $regions,
]);
2025-01-12 16:49:29 +01:00
}
// prepare data for calendar chart
$calendarData = [];
2025-01-18 17:31:31 +01:00
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];
}
$calendarData[] = $series;
2024-12-18 15:14:13 +01:00
}
$diagramsOptions = [
"shared" => [
"colors" => Chart::colors(),
"extractiondates" => json_encode($propertyCapacities['dates'])
],
"calendar" => [
"series" => $calendarData
],
"capacities" => [
"xAxis" => [
"data" => json_encode($propertyCapacities['dates'])
],
"series" => [
["data" => json_encode($propertyCapacities['capacities'])],
["data" => json_encode($regionCapacities[0])],
["data" => json_encode($regionCapacities[1])],
]
],
"capacityMonthly" => [
"options" => $propertyCapacitiesMonthly,
],
"capacityDaily" => [
"options" => $propertyCapacitiesDaily,
],
];
2025-01-12 16:49:29 +01:00
return view('property', [
'diagramsOptions' => $diagramsOptions,
2025-01-14 22:11:31 +01:00
'startDate' => $propertyCapacities['dates'][0],
2025-01-18 17:31:31 +01:00
'base' => $base,
'regions' => $regions,
2025-01-12 16:49:29 +01:00
'neighbours' => $propertyNeighbours
]);
2025-01-09 18:34:20 +01:00
});