Skip to content

Commit

Permalink
Add previous row information for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
skybluesofa committed Feb 4, 2024
1 parent 1071146 commit 9100a3a
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 31 deletions.
46 changes: 36 additions & 10 deletions app/Http/Controllers/TemperatureBlanketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
use App\Facades\TemperatureBlanketConfig;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;

class TemperatureBlanketController extends Controller
{
protected ?Carbon $date;

protected $weatherData;
protected array $weatherData = [
'previous_row' => null,
'current_row' => null,
];

public function __construct(Request $request)
{
Expand All @@ -27,19 +29,26 @@ public function show()
return $this->getJsonOutput();
}

protected function getWeatherData(): Collection
protected function getWeatherData(): array
{
$cachedWeatherData = OpenMeteo::get($this->date);

$yesterday = $this->date->clone()->subDay(1);
$tomorrow = $this->date->clone()->addDay(1);
$displayData = [
$this->weatherData['current_row'] = collect([
$yesterday->format('Y-m-d') => $cachedWeatherData[$yesterday->format('Y-m-d')] ?? null,
$this->date->format('Y-m-d') => $cachedWeatherData[$this->date->format('Y-m-d')] ?? null,
$tomorrow->format('Y-m-d') => $cachedWeatherData[$tomorrow->format('Y-m-d')] ?? null,
];
]);

$this->weatherData = collect($displayData);
$yesterdayPreviousRowDate = $yesterday->clone()->subDay(TemperatureBlanketConfig::get('columns'));
$todayPreviousRowDate = $this->date->clone()->subDay(TemperatureBlanketConfig::get('columns'));
$tomorrowPreviousRowDate = $tomorrow->clone()->subDay(TemperatureBlanketConfig::get('columns'));
$this->weatherData['previous_row'] = collect([
$yesterdayPreviousRowDate->format('Y-m-d') => $cachedWeatherData[$yesterdayPreviousRowDate->format('Y-m-d')] ?? null,
$todayPreviousRowDate->format('Y-m-d') => $cachedWeatherData[$todayPreviousRowDate->format('Y-m-d')] ?? null,
$tomorrowPreviousRowDate->format('Y-m-d') => $cachedWeatherData[$tomorrowPreviousRowDate->format('Y-m-d')] ?? null,
]);

return $this->weatherData;
}
Expand All @@ -56,24 +65,41 @@ protected function getJsonOutput()
'rows' => [
'previous' => [
'date' => $this->date->clone()->subDays(TemperatureBlanketConfig::get('columns')),
'cells' => [
'previous' => [
'date' => $this->date->clone()->subDays(TemperatureBlanketConfig::get('columns'))->subDay(1),
'weather' => $this->weatherData['previous_row']->first() ?? null,
'show' => true,
],
'current' => [
'date' => $this->date->clone()->subDays(TemperatureBlanketConfig::get('columns')),
'weather' => $this->weatherData['previous_row']->nth(2, 1)->first() ?? null,
'show' => true,
],
'next' => [
'date' => $this->date->clone()->subDays(TemperatureBlanketConfig::get('columns'))->addDay(1),
'weather' => $this->weatherData['previous_row']->last() ?? null,
'show' => true,
],
],
],
'current' => [
'date' => $this->date,
'cells' => [
'previous' => [
'date' => $this->date->clone()->subDay(1),
'weather' => $this->weatherData->first() ?? null,
'weather' => $this->weatherData['current_row']->first() ?? null,
'show' => true,
],
'current' => [
'date' => $this->date,
'weather' => $this->weatherData->nth(2, 1)->first() ?? null,
'weather' => $this->weatherData['current_row']->nth(2, 1)->first() ?? null,
'show' => true,
],
'next' => [
'date' => $this->date->clone()->addDay(1),
'weather' => $this->weatherData->last() ?? null,
'show' => is_array($this->weatherData->last() ?? null),
'weather' => $this->weatherData['current_row']->last() ?? null,
'show' => is_array($this->weatherData['current_row']->last() ?? null),
],
],
],
Expand Down
3 changes: 3 additions & 0 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/avg.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
@endphp

<div class="min-h-24 p-1 rounded text-white" style="background:{{ $hex }}">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $hex }}">
{{ $color }}<br>{{ $avgTemp }}&deg;
</div>
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/daylight.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
@endphp

<div class="min-h-24 p-1 rounded text-white" style="background:{{ $hex }}">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $hex }}">
{{ $color }}<br>{{ $hours }} hrs
</div>
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/generic.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="min-h-24 p-1 rounded text-white" style="background:{{ $cellDesign }};">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $cellDesign }};">
<br>
</div>
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/high.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
@endphp

<div class="min-h-24 p-1 rounded text-white" style="background:{{ $hex }};">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $hex }};">
{{ $color }}<br>{{ $highTemp }}&deg;
</div>
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/low.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
@endphp

<div class="min-h-24 p-1 rounded text-white" style="background:{{ $hex }};">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $hex }};">
{{ $color }}<br>{{ $lowTemp }}&deg;
</div>
2 changes: 1 addition & 1 deletion resources/views/c2c/grid/cell/precip.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
}
@endphp

<div class="min-h-24 p-1 rounded text-white" style="background:{{ $hex }}">
<div class="min-h-24 p-1 rounded text-stone-200" style="background:{{ $hex }}">
{{ $color }}<br>{{ $precipitation }}" {{ $title }}
</div>
43 changes: 28 additions & 15 deletions resources/views/c2c/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<title>{{ (new Carbon\Carbon())->format('Y') }} Temperature Blanket</title>

<link rel="icon" href="favicon.svg">
<link rel="mask-icon" href="favicon.svg" color="#fff">
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="antialiased bg-stone-800">
Expand All @@ -18,21 +20,20 @@
</h2>
</div>

<div class="grid grid-cols-3 gap-4 p-8 pt-32">
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['previous']['date'],
])
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['current']['date'],
])
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['next']['date'],
])
<div class="grid grid-cols-3 gap-4 p-8 pt-32 pl-20">
@foreach ($info['rows']['previous']['cells'] as $position => $positionInformation)
<div class="grid grid-cols-4 gap-1 @if ($position!='current') opacity-50 @else opacity-75 @endif">
@foreach (end($info['meta']['design']) as $cellDesign)
@include('c2c.grid.cell', [
'cellDesign' => $cellDesign,
'positionInformation' => $positionInformation,
'colorInformation' => $info['meta']['colors'],
])
@endforeach
</div>
@endforeach
@foreach ($info['rows']['current']['cells'] as $position => $positionInformation)
<div class="grid grid-cols-4 gap-1">
<div class="grid grid-cols-4 gap-1 @if ($position!='current') opacity-75 @else bg-stone-700 bg-opacity-50 outline outline-stone-700/50 outline-4 @endif">
@foreach ($info['meta']['design'] as $rows)
@foreach ($rows as $cellDesign)
@include('c2c.grid.cell', [
Expand All @@ -43,7 +44,19 @@
@endforeach
@endforeach
</div>
@endforeach
@endforeach
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['previous']['date'],
])
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['current']['date'],
])
@include('c2c.grid.cell.metadata', [
'meta' => $info['meta'],
'date' => $info['rows']['current']['cells']['next']['date'],
])
</div>

<div class="text-stone-500 fixed bottom-4 left-0 right-0 text-sm text-center">Data cached on {{ $info['meta']['cachedDate'] }}</div>
Expand Down

0 comments on commit 9100a3a

Please sign in to comment.