terrarium-web/src/Controller/MonitoringController.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Filesystem\Filesystem;
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
{
/**
* @Route("/", name="charts")
*/
public function charts(): Response
{
return $this->render('charts.html.twig');
}
/**
* @Route("/datas", name="datas")
*/
public function datas(
TemperatureRepository $temperatureRepository,
HygrometryRepository $hygrometryRepository,
ParameterBagInterface $params
): Response
{
$from = new \DateTime('now - 1 day');
$to = new \DateTime('now');
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'),
]);
}
}