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);
|
2025-01-17 23:46:22 +01:00
|
|
|
$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
|
|
|
|
2025-01-17 23:46:22 +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)
|
2025-01-17 23:46:22 +01:00
|
|
|
]
|
|
|
|
],
|
|
|
|
"propertiesPerRegion" => [
|
|
|
|
"yAxis" => [
|
2025-01-18 17:31:31 +01:00
|
|
|
"data" => json_encode(array_column($propertiesPerRegion, 'count_properties'))
|
2025-01-17 23:46:22 +01:00
|
|
|
],
|
|
|
|
"xAxis" => [
|
2025-01-18 17:31:31 +01:00
|
|
|
"data" => json_encode(array_column($propertiesPerRegion, 'name'))
|
2025-01-17 23:46:22 +01:00
|
|
|
]
|
|
|
|
],
|
|
|
|
"extractions" => [
|
|
|
|
"series" => $propertiesGrowth,
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
2025-01-13 22:50:03 +01:00
|
|
|
return view('overview', [
|
2025-01-17 23:46:22 +01:00
|
|
|
"regions" => $regions,
|
|
|
|
"region" => $regionBase,
|
|
|
|
"diagramsOptions" => $diagramsOptions,
|
2025-01-13 22:50:03 +01:00
|
|
|
"geo" => $propertiesGeo,
|
2025-01-17 23:46:22 +01:00
|
|
|
|
|
|
|
]);
|
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'];
|
2025-01-17 23:46:22 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2025-01-17 23:46:22 +01:00
|
|
|
$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)
|
2025-01-17 23:46:22 +01:00
|
|
|
]
|
|
|
|
],
|
|
|
|
"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', [
|
2025-01-17 23:46:22 +01:00
|
|
|
'diagramsOptions' => $diagramsOptions,
|
2025-01-14 22:11:31 +01:00
|
|
|
'startDate' => $regionCapacitiesRegion['dates'][0],
|
2025-01-17 23:46:22 +01:00
|
|
|
'regions' => $regions,
|
|
|
|
'region' => $region,
|
|
|
|
'regionId' => $id,
|
2025-01-14 22:11:31 +01:00
|
|
|
'regionPropertiesCapacities' => $regionPropertiesCapacities,
|
|
|
|
'predictions' => $regionPredictions]);
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2025-01-13 17:06:54 +01:00
|
|
|
Route::get('/property/{id}', function (int $id) {
|
2024-12-18 15:14:13 +01:00
|
|
|
|
2025-01-17 23:46:22 +01:00
|
|
|
|
2025-01-18 17:31:31 +01:00
|
|
|
$regions = Api::regions()['regions'];
|
2025-01-17 23:46:22 +01:00
|
|
|
$regions[] = ['name' => 'Alle Regionen', 'id' => -1];
|
|
|
|
|
|
|
|
$base = Api::propertyBase($id);
|
2025-01-18 17:31:31 +01:00
|
|
|
$calendars = Api::propertyExtractions($id)['extractions'];
|
2024-12-19 19:22:09 +01:00
|
|
|
$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
|
|
|
|
2025-01-08 22:02:33 +01:00
|
|
|
$propertyCapacitiesMonthly = [];
|
|
|
|
$propertyCapacitiesDaily = [];
|
|
|
|
|
2025-01-17 15:13:41 +01:00
|
|
|
if($propertyCapacities){
|
|
|
|
foreach ($propertyCapacities['dates'] as $date) {
|
|
|
|
$propertyCapacitiesMonthly[] = Api::propertyCapacitiesMonthly($id, $date);
|
|
|
|
$propertyCapacitiesDaily[] = Api::propertyCapacitiesDaily($id, $date);
|
|
|
|
}
|
2025-01-08 22:02:33 +01:00
|
|
|
|
2025-01-17 15:13:41 +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];
|
|
|
|
}
|
2025-01-12 16:49:29 +01:00
|
|
|
}
|
|
|
|
|
2025-01-17 15:13:41 +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
|
|
|
}
|
2025-01-17 15:13:41 +01:00
|
|
|
}else{
|
2025-01-17 23:46:22 +01:00
|
|
|
return view('property-nodata', [
|
2025-01-18 17:31:31 +01:00
|
|
|
'base' => $base,
|
2025-01-17 23:46:22 +01:00
|
|
|
'regions' => $regions,
|
|
|
|
]);
|
2025-01-12 16:49:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// prepare data for calendar chart
|
2025-01-17 23:46:22 +01:00
|
|
|
$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];
|
|
|
|
}
|
|
|
|
|
2025-01-17 23:46:22 +01:00
|
|
|
$calendarData[] = $series;
|
2024-12-18 15:14:13 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2025-01-17 23:46:22 +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', [
|
2025-01-17 23:46:22 +01:00
|
|
|
'diagramsOptions' => $diagramsOptions,
|
2025-01-14 22:11:31 +01:00
|
|
|
'startDate' => $propertyCapacities['dates'][0],
|
2025-01-18 17:31:31 +01:00
|
|
|
'base' => $base,
|
2025-01-17 23:46:22 +01:00
|
|
|
'regions' => $regions,
|
2025-01-12 16:49:29 +01:00
|
|
|
'neighbours' => $propertyNeighbours
|
|
|
|
]);
|
|
|
|
|
2025-01-09 18:34:20 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|