Browse Source

add lights chart

develop
Simon Vieille 3 months ago
parent
commit
e94109fd40
Signed by: deblan GPG Key ID: 03383D15A1D31745
4 changed files with 71 additions and 4 deletions
  1. +2
    -0
      config/services.yaml
  2. +67
    -2
      src/Controller/MonitoringApiController.php
  3. +1
    -1
      templates/alert/hygrometry.txt.twig
  4. +1
    -1
      templates/alert/temperature.txt.twig

+ 2
- 0
config/services.yaml View File

@ -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


+ 67
- 2
src/Controller/MonitoringApiController.php View File

@ -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);
}


+ 1
- 1
templates/alert/hygrometry.txt.twig View File

@ -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 }}

+ 1
- 1
templates/alert/temperature.txt.twig View File

@ -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 }}

Loading…
Cancel
Save