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']; $xtics = []; foreach ($entities as $i => $entity) { $stats1[] = $entity->getvalue(); $stats2[] = $max; if ($i % 5 === 0) { $xtics[] = sprintf('"%s" %d', $entity->getDate()->format('H:i'), $i); } $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', '--xtics', sprintf('(%s)', implode(', ', $xtics)), '-t', 'Max@Hygrometry', '-m', $filename2, $filename1, ]); $process->run(); $output->writeln($process->getOutput()); $table->render(); unlink($filename1); unlink($filename2); return 0; } }