123 lines
3.4 KiB
PHP
123 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class MonitoringApiController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/api/temperature", name="api_temperature")
|
|
*/
|
|
public function temperature(Request $request)
|
|
{
|
|
if ($request->isMethod('POST')) {
|
|
} else {
|
|
$labels = [];
|
|
$datasets = [];
|
|
|
|
$dateFrom = time() - 3600 * 24;
|
|
$dateTo = time();
|
|
|
|
$line = [
|
|
'label' => 'En degré celsius',
|
|
'data' => [],
|
|
'borderColor' => 'rgb(255, 205, 86)',
|
|
'backgroundColor' => 'rgb(255, 205, 86)',
|
|
'fill' => false,
|
|
];
|
|
|
|
$line2 = [
|
|
'label' => 'Valeur idéale',
|
|
'data' => [],
|
|
'borderColor' => 'rgb(200, 200, 200)',
|
|
'backgroundColor' => 'rgb(200, 200, 200)',
|
|
'fill' => false,
|
|
];
|
|
|
|
for ($u = $dateFrom; $u <= $dateTo; $u+= 600) {
|
|
$labels[] = date('H:i', $u);
|
|
$line['data'][] = mt_rand(22, 24);
|
|
$line2['data'][] = 23;
|
|
}
|
|
|
|
$datasets[] = $line;
|
|
$datasets[] = $line2;
|
|
|
|
return $this->createGraphResponse($labels, $datasets);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @Route("/api/hydrometal", name="api_hydrometal")
|
|
*/
|
|
public function hydrometal(Request $request)
|
|
{
|
|
if ($request->isMethod('POST')) {
|
|
} else {
|
|
$labels = [];
|
|
$datasets = [];
|
|
|
|
$dateFrom = time() - 3600 * 24;
|
|
$dateTo = time();
|
|
|
|
$line = [
|
|
'label' => 'Niveau d\'humidité en %',
|
|
'data' => [],
|
|
'borderColor' => 'rgb(54, 162, 235)',
|
|
'backgroundColor' => 'rgb(54, 162, 235)',
|
|
'fill' => false,
|
|
];
|
|
|
|
$line2 = [
|
|
'label' => 'Valeur idéale',
|
|
'data' => [],
|
|
'borderColor' => 'rgb(200, 200, 200)',
|
|
'backgroundColor' => 'rgb(200, 200, 200)',
|
|
'fill' => false,
|
|
];
|
|
|
|
for ($u = $dateFrom; $u <= $dateTo; $u+= 600) {
|
|
$labels[] = date('H:i', $u);
|
|
$line['data'][] = mt_rand(50, 55);
|
|
$line2['data'][] = 53;
|
|
}
|
|
|
|
$datasets[] = $line;
|
|
$datasets[] = $line2;
|
|
|
|
return $this->createGraphResponse($labels, $datasets);
|
|
}
|
|
}
|
|
|
|
protected function createGraphResponse(array $labels, array $datasets): JsonResponse
|
|
{
|
|
$config = [
|
|
'data' => [
|
|
'labels' => $labels,
|
|
'datasets' => $datasets,
|
|
],
|
|
'options' => [
|
|
'responsive' => false,
|
|
'ratio' => 10,
|
|
'maintainAspectRatio' => false,
|
|
'legend' => [
|
|
'align' => 'end',
|
|
],
|
|
'scales' => [
|
|
'yAxes' => [[
|
|
'ticks' => [
|
|
'beginAtZero' => true,
|
|
],
|
|
]],
|
|
],
|
|
],
|
|
];
|
|
|
|
return $this->json($config);
|
|
}
|
|
}
|