diff --git a/config/services.yaml b/config/services.yaml index d31efb0..71f08c6 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -10,6 +10,8 @@ parameters: temperature_trigger_max: "%env(TEMPERATURE_TRIGGER_MAX)%" hygrometry_trigger_min: "%env(HYGROMETRY_TRIGGER_MIN)%" hygrometry_trigger_max: "%env(HYGROMETRY_TRIGGER_MAX)%" + light_on_at: "%env(LIGHT_ON_AT)%" + light_off_at: "%env(LIGHT_OFF_AT)%" services: # default configuration for services in *this* file diff --git a/src/Controller/MonitoringApiController.php b/src/Controller/MonitoringApiController.php index ce99a97..bf00312 100644 --- a/src/Controller/MonitoringApiController.php +++ b/src/Controller/MonitoringApiController.php @@ -8,13 +8,18 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use App\Repository\TemperatureRepository; use App\Repository\HygrometryRepository; +use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; class MonitoringApiController extends AbstractController { /** * @Route("/api/monitoring/temperature", name="api_monitoring_temperature", methods={"GET"}) */ - public function temperature(Request $request, TemperatureRepository $repository): JsonResponse + public function temperature( + Request $request, + TemperatureRepository $repository, + ParameterBagInterface $params + ): JsonResponse { $labels = []; $datasets = []; @@ -41,17 +46,46 @@ class MonitoringApiController extends AbstractController 'fill' => false, ]; + $lightOn = [ + 'label' => 'Lumière allumée', + 'data' => [], + 'borderColor' => 'rgb(230, 217, 149)', + 'fill' => false, + ]; + + $lightOff = [ + 'label' => 'Lumière éteinte', + 'data' => [], + 'borderColor' => 'rgb(214, 214, 214)', + 'fill' => false, + ]; + + $lightOnAt = (int) $params->get('light_on_at'); + $lightOffAt = (int) $params->get('light_off_at'); + foreach ($entities as $entity) { $hour = (int) $entity->getDate()->format('H'); $labels[] = $entity->getDate()->format('H:i'); $line['data'][] = $entity->getValue(); $line2['data'][] = 27; $line3['data'][] = 23; + + $lightTime = (int) $entity->getDate()->format('gi'); + + if ($lightTime >= $lightOn && $lightTime <= $lightOff) { + $lightOn['data'][] = 5; + $lightOff['data'][] = 0; + } else { + $lightOn['data'][] = 0; + $lightOff['data'][] = 5; + } } $datasets[] = $line; $datasets[] = $line2; $datasets[] = $line3; + $datasets[] = $lightOn; + $datasets[] = $lightOff; return $this->createGraphResponse($labels, $datasets); } @@ -59,7 +93,11 @@ class MonitoringApiController extends AbstractController /** * @Route("/api/monitoring/hygrometry", name="api_monitoring_hygrometry", methods={"GET"}) */ - public function hygrometry(Request $request, HygrometryRepository $repository): JsonResponse + public function hygrometry( + Request $request, + HygrometryRepository $repository, + ParameterBagInterface $params + ): JsonResponse { $labels = []; $datasets = []; @@ -80,14 +118,41 @@ class MonitoringApiController extends AbstractController 'fill' => false, ]; + $lightOn = [ + 'label' => 'Lumière allumée', + 'data' => [], + 'borderColor' => 'rgb(230, 217, 149)', + 'fill' => false, + ]; + + $lightOff = [ + 'label' => 'Lumière éteinte', + 'data' => [], + 'borderColor' => 'rgb(214, 214, 214)', + 'fill' => false, + ]; + + $lightOnAt = (int) $params->get('light_on_at'); + $lightOffAt = (int) $params->get('light_off_at'); + foreach ($entities as $entity) { $labels[] = $entity->getDate()->format('H:i'); $line['data'][] = $entity->getValue(); $line2['data'][] = 50; + + if ($lightTime >= $lightOn && $lightTime <= $lightOff) { + $lightOn['data'][] = 5; + $lightOff['data'][] = 0; + } else { + $lightOn['data'][] = 0; + $lightOff['data'][] = 5; + } } $datasets[] = $line; $datasets[] = $line2; + $datasets[] = $lightOn; + $datasets[] = $lightOff; return $this->createGraphResponse($labels, $datasets); } diff --git a/templates/alert/hygrometry.txt.twig b/templates/alert/hygrometry.txt.twig index e058e10..fc65362 100644 --- a/templates/alert/hygrometry.txt.twig +++ b/templates/alert/hygrometry.txt.twig @@ -1,3 +1,3 @@ Date : {{ entity.date.format('d/m/Y H:i:s') }} Niveau hygrométrique : {{ entity.value }}% -Déclancheurs : min={{ min }} max={{ max }} +Déclancheurs : min={{ triggers.min }} max={{ triggers.max }} diff --git a/templates/alert/temperature.txt.twig b/templates/alert/temperature.txt.twig index 137bed5..4f57fb9 100644 --- a/templates/alert/temperature.txt.twig +++ b/templates/alert/temperature.txt.twig @@ -1,3 +1,3 @@ Date : {{ entity.date.format('d/m/Y H:i:s') }} Température : {{ entity.value }}° -Déclancheurs : min={{ min }} max={{ max }} +Déclancheurs : min={{ triggers.min }} max={{ triggers.max }}