add lights in datas

This commit is contained in:
Simon Vieille 2020-11-29 17:27:14 +01:00
parent b502120716
commit 5432c0c330
Signed by: deblan
GPG Key ID: 03383D15A1D31745
2 changed files with 30 additions and 3 deletions

View File

@ -9,6 +9,7 @@ use App\Motion\SnapshotRepository;
use Symfony\Component\HttpFoundation\Response;
use App\Repository\TemperatureRepository;
use App\Repository\HygrometryRepository;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
class MonitoringController extends AbstractController
{
@ -23,7 +24,11 @@ class MonitoringController extends AbstractController
/**
* @Route("/datas", name="datas")
*/
public function datas(TemperatureRepository $temperatureRepository, HygrometryRepository $hygrometryRepository): Response
public function datas(
TemperatureRepository $temperatureRepository,
HygrometryRepository $hygrometryRepository,
ParameterBagInterface $params
): Response
{
$from = new \DateTime('now - 1 day');
$to = new \DateTime('now');
@ -31,6 +36,8 @@ class MonitoringController extends AbstractController
return $this->render('datas.html.twig', [
'temperatures' => $temperatureRepository->findByDateRange($from, $to, 100, 'DESC'),
'hygrometries' => $hygrometryRepository->findByDateRange($from, $to, 100, 'DESC'),
'lightOnAt' => (int) $params->get('light_on_at'),
'lightOffAt' => (int) $params->get('light_off_at'),
]);
}
}

View File

@ -29,7 +29,17 @@
{% endif %}
<tr class="{{ class }}">
<td>{{ item.date.format('d/m H:i') }}</td>
<td>
{% set lightTime = item.date.format('Gi') %}
{% if lightTime >= lightOnAt and lightTime <= lightOffAt %}
🌕
{% else %}
🌑
{% endif %}
{{ item.date.format('d/m H:i') }}
</td>
<td>{{ item.value|number_format(2, ',', '') }}°</td>
</tr>
{% endfor %}
@ -64,7 +74,17 @@
{% endif %}
<tr class="{{ class }}">
<td>{{ item.date.format('d/m H:i') }}</td>
<td>
{% set lightTime = item.date.format('Gi') %}
{% if lightTime >= lightOnAt and lightTime <= lightOffAt %}
🌕
{% else %}
🌑
{% endif %}
{{ item.date.format('d/m H:i') }}
</td>
<td>{{ item.value|number_format(2, ',', '') }}%</td>
</tr>
{% endfor %}