diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..726443c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/eplot"] + path = lib/eplot + url = https://github.com/chriswolfvision/eplot diff --git a/lib/eplot b/lib/eplot new file mode 160000 index 0000000..aa4d607 --- /dev/null +++ b/lib/eplot @@ -0,0 +1 @@ +Subproject commit aa4d607f050284c803583ba78852c845f749d67d diff --git a/package.json b/package.json index d83f768..e76b6ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "bootstrap": "^4.4.1", - "chart.js": "^2.9.3" + "chart.js": "^2.9.3", + "ervy": "^1.0.7" } } diff --git a/src/Command/ChartHygrometryCommand.php b/src/Command/ChartHygrometryCommand.php new file mode 100644 index 0000000..ab50afb --- /dev/null +++ b/src/Command/ChartHygrometryCommand.php @@ -0,0 +1,92 @@ +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; + } +} diff --git a/src/Command/ChartTemperatureCommand.php b/src/Command/ChartTemperatureCommand.php new file mode 100644 index 0000000..a834270 --- /dev/null +++ b/src/Command/ChartTemperatureCommand.php @@ -0,0 +1,103 @@ +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; + } +} diff --git a/yarn.lock b/yarn.lock index a534708..8e383b1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -bulma@^0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/bulma/-/bulma-0.8.0.tgz#ac1606431703a4761b18a4a2d5cc1fa864a2aece" - integrity sha512-nhf3rGyiZh/VM7FrSJ/5KeLlfaFkXz0nYcXriynfPH4vVpnxnqyEwaNGdNCVzHyyCA3cHgkQAMpdF/SFbFGZfA== +bootstrap@^4.4.1: + version "4.5.3" + resolved "https://registry.yarnpkg.com/bootstrap/-/bootstrap-4.5.3.tgz#c6a72b355aaf323920be800246a6e4ef30997fe6" + integrity sha512-o9ppKQioXGqhw8Z7mah6KdTYpNQY//tipnkxppWhPbiSWdD+1raYsnhwEZjkTHYbGee4cVQ0Rx65EhOY/HNLcQ== chart.js@^2.9.3: version "2.9.3" @@ -47,6 +47,11 @@ color-name@^1.0.0: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== +ervy@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/ervy/-/ervy-1.0.7.tgz#b4167707ef178484c7b84d7d6e8cca727cf7f252" + integrity sha512-LyHLPwIKxCKKtTO/qBMFzwA1BD5IjpM0AA3k6CeK9hrEn4Kbayi93G9eD/Ko4suEIjerSl7YpMmaOoL0g9OCoQ== + moment@^2.10.2: version "2.24.0" resolved "https://registry.yarnpkg.com/moment/-/moment-2.24.0.tgz#0d055d53f5052aa653c9f6eb68bb5d12bf5c2b5b"