'Alle Regionen', 'region_id' => -1]; $regionPropertyCapacities = Api::regionPropertiesCapacities(-1); $propertiesGrowth = Api::propertiesGrowth(); $propsPerRegion = Api::propertiesPerRegion(); $propsPerRegionName = []; $propsPerRegionCounts = []; $propsPerRegionId = []; foreach ($propsPerRegion as $el) { $propsPerRegionName[] = $el['name']; $propsPerRegionId[] = $el['id']; $propsPerRegionCounts[] = $el['count_properties']; } $chartOptions = [ 'colors' => Chart::colors() ]; $propertiesGeo = Api::propertiesGeo(); return view('overview', [ "regions" => $regionBase, "regionPropertiesCapacities" => $regionPropertyCapacities, "geo" => $propertiesGeo, "growth" => $propertiesGrowth, "chartOptions" => $chartOptions, "propsPerRegion" => [json_encode($propsPerRegionId), json_encode($propsPerRegionName), json_encode($propsPerRegionCounts)]]); }); 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) { $chartOptions = [ 'colors' => Chart::colors() ]; $propertyBase = Api::propertyBase($id); $calendars = Api::propertyExtractions($id); $propertyCapacities = Api::propertyCapacities($id); $propertyNeighbours = Api::propertyNeighbours($id); $regionCapacitiesRegion = Api::regionCapacities($propertyBase[0]['region_id']); $regionCapacitiesAll = Api::regionCapacities(-1); $regionCapacities = [[],[]]; $propertyCapacitiesMonthly = []; $propertyCapacitiesDaily = []; 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 ($calendars as $el) { $series = []; $calendar = json_decode($el['calendar'], 1); foreach ($calendar as $date => $status) { $series[] = [$date, $status]; } $data[] = $series; } return view('property', [ 'chartOptions' => $chartOptions, 'startDate' => $propertyCapacities['dates'][0], 'base' => $propertyBase[0], 'extractiondates' => json_encode($propertyCapacities['dates']), 'calendar' => $data, 'propertyCapacities' => $propertyCapacities, 'capacitiesMonthly' => $propertyCapacitiesMonthly, 'capacitiesDaily' => $propertyCapacitiesDaily, 'regionCapacities' => $regionCapacities, 'neighbours' => $propertyNeighbours ]); });