@ -0,0 +1,3 @@ | |||
[submodule "lib/eplot"] | |||
path = lib/eplot | |||
url = https://github.com/chriswolfvision/eplot |
@ -1,6 +1,7 @@ | |||
{ | |||
"dependencies": { | |||
"bootstrap": "^4.4.1", | |||
"chart.js": "^2.9.3" | |||
"chart.js": "^2.9.3", | |||
"ervy": "^1.0.7" | |||
} | |||
} |
@ -0,0 +1,92 @@ | |||
<?php | |||
namespace App\Command; | |||
use App\Repository\HygrometryRepository; | |||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |||
use Symfony\Component\Console\Helper\Table; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpKernel\KernelInterface; | |||
use Symfony\Component\Process\Process; | |||
class ChartHygrometryCommand extends ContainerAwareCommand | |||
{ | |||
protected static $defaultName = 'app:chart:hygrometry'; | |||
protected HygrometryRepository $repository; | |||
protected KernelInterface $kernel; | |||
protected ParameterBagInterface $params; | |||
public function __construct(HygrometryRepository $repository, KernelInterface $kernel, ParameterBagInterface $params) | |||
{ | |||
$this->repository = $repository; | |||
$this->kernel = $kernel; | |||
$this->params = $params; | |||
parent::__construct(); | |||
} | |||
protected function configure() | |||
{ | |||
$this | |||
->setDescription('Show a chart of hygrometry') | |||
; | |||
} | |||
protected function execute(InputInterface $input, OutputInterface $output): int | |||
{ | |||
chdir($this->getContainer()->get('kernel')->getProjectDir()); | |||
$entities = $this->repository->findByDateRange( | |||
new \DateTime('now - 1 day'), | |||
new \DateTime('now'), | |||
42, | |||
'DESC' | |||
); | |||
$entities = array_reverse($entities); | |||
$table = new Table($output); | |||
$table->setHeaders(['ID', 'Date', 'Value']); | |||
$max = (int) $this->params->get('hygrometry_trigger_max'); | |||
$stats = ['Value,Max']; | |||
foreach ($entities as $i => $entity) { | |||
$stats1[] = $entity->getvalue(); | |||
$stats2[] = $max; | |||
$table->addRow([ | |||
$i, | |||
$entity->getDate()->format('d/m/Y H:i'), | |||
$entity->getValue().'%', | |||
]); | |||
} | |||
$filename1 = tempnam('./', self::$defaultName); | |||
$filename2 = tempnam('./', self::$defaultName); | |||
file_put_contents($filename1, implode("\n", $stats1)); | |||
file_put_contents($filename2, implode("\n", $stats2)); | |||
$process = new Process([ | |||
'./lib/eplot/eplot', | |||
'-d', | |||
'-t', | |||
'Max@Hygrometry', | |||
'-m', | |||
$filename2, | |||
$filename1, | |||
]); | |||
$process->run(); | |||
$output->writeln($process->getOutput()); | |||
$table->render(); | |||
unlink($filename1); | |||
unlink($filename2); | |||
return 0; | |||
} | |||
} |
@ -0,0 +1,103 @@ | |||
<?php | |||
namespace App\Command; | |||
use App\Repository\TemperatureRepository; | |||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | |||
use Symfony\Component\Console\Helper\Table; | |||
use Symfony\Component\Console\Input\InputInterface; | |||
use Symfony\Component\Console\Output\OutputInterface; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpKernel\KernelInterface; | |||
use Symfony\Component\Process\Process; | |||
class ChartTemperatureCommand extends ContainerAwareCommand | |||
{ | |||
protected static $defaultName = 'app:chart:temperature'; | |||
protected TemperatureRepository $repository; | |||
protected KernelInterface $kernel; | |||
protected ParameterBagInterface $params; | |||
public function __construct(TemperatureRepository $repository, KernelInterface $kernel, ParameterBagInterface $params) | |||
{ | |||
$this->repository = $repository; | |||
$this->kernel = $kernel; | |||
$this->params = $params; | |||
parent::__construct(); | |||
} | |||
protected function configure() | |||
{ | |||
$this | |||
->setDescription('Show a chart of temperature') | |||
; | |||
} | |||
protected function execute(InputInterface $input, OutputInterface $output): int | |||
{ | |||
chdir($this->getContainer()->get('kernel')->getProjectDir()); | |||
$entities = $this->repository->findByDateRange( | |||
new \DateTime('now - 1 day'), | |||
new \DateTime('now'), | |||
42, | |||
'DESC' | |||
); | |||
$entities = array_reverse($entities); | |||
$table = new Table($output); | |||
$table->setHeaders(['ID', 'Date', 'Value']); | |||
$perfect = (int) $this->params->get('temperature_trigger_max'); | |||
$min = (int) $this->params->get('temperature_trigger_min'); | |||
$stats = ['Value,Perfect,Min']; | |||
foreach ($entities as $i => $entity) { | |||
$stats1[] = $entity->getvalue(); | |||
$stats2[] = (float) 27; | |||
$stats3[] = (float) $min; | |||
$table->addRow([ | |||
$i, | |||
$entity->getDate()->format('d/m/Y H:i'), | |||
$entity->getValue().'°', | |||
]); | |||
} | |||
$filename1 = tempnam('./', self::$defaultName); | |||
$filename2 = tempnam('./', self::$defaultName); | |||
$filename3 = tempnam('./', self::$defaultName); | |||
file_put_contents($filename1, implode("\n", $stats1)); | |||
file_put_contents($filename2, implode("\n", $stats2)); | |||
file_put_contents($filename3, implode("\n", $stats3)); | |||
$process = new Process([ | |||
'./lib/eplot/eplot', | |||
'-d', | |||
'-r', | |||
'[0:45][10:35]', | |||
'-t', | |||
'Perfect@Min@Temperature', | |||
'-m', | |||
basename($filename2), | |||
basename($filename3), | |||
basename($filename1), | |||
]); | |||
$process->run(); | |||
$graph = $process->getOutput(); | |||
$output->writeln($graph); | |||
$table->render(); | |||
unlink($filename1); | |||
unlink($filename2); | |||
unlink($filename3); | |||
return 0; | |||
} | |||
} |