|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Nextcloud - ContextChat |
| 5 | + * |
| 6 | + * This file is licensed under the Affero General Public License version 3 or |
| 7 | + * later. See the COPYING file. |
| 8 | + * |
| 9 | + * @author Anupam Kumar <kyteinsky@gmail.com> |
| 10 | + * @copyright Anupam Kumar 2024 |
| 11 | + */ |
| 12 | + |
| 13 | +declare(strict_types=1); |
| 14 | +namespace OCA\ContextChat\Command; |
| 15 | + |
| 16 | +use OCA\ContextChat\Service\ActionService; |
| 17 | +use OCA\ContextChat\Service\QueueService; |
| 18 | +use OCP\AppFramework\Services\IAppConfig; |
| 19 | +use Symfony\Component\Console\Command\Command; |
| 20 | +use Symfony\Component\Console\Input\InputInterface; |
| 21 | +use Symfony\Component\Console\Output\OutputInterface; |
| 22 | + |
| 23 | +class Statistics extends Command { |
| 24 | + |
| 25 | + public function __construct( |
| 26 | + private IAppConfig $appConfig, |
| 27 | + private ActionService $actionService, |
| 28 | + private QueueService $queueService, |
| 29 | + ) { |
| 30 | + parent::__construct(); |
| 31 | + } |
| 32 | + |
| 33 | + protected function configure() { |
| 34 | + $this->setName('context_chat:stats') |
| 35 | + ->setDescription('Check ContextChat statistics'); |
| 36 | + } |
| 37 | + |
| 38 | + protected function execute(InputInterface $input, OutputInterface $output) { |
| 39 | + $output->writeln('ContextChat statistics:'); |
| 40 | + if ($this->appConfig->getAppValueInt('last_indexed_time', 0) === 0) { |
| 41 | + $output->writeln('The indexing is not complete yet.'); |
| 42 | + } else { |
| 43 | + $installedTime = $this->appConfig->getAppValueInt('installed_time', 0); |
| 44 | + $lastIndexedTime = $this->appConfig->getAppValueInt('last_indexed_time', 0); |
| 45 | + $indexTime = $lastIndexedTime - $installedTime; |
| 46 | + |
| 47 | + $output->writeln('Installed time: ' . (new \DateTime('@' . $installedTime))->format('Y-m-d H:i') . ' UTC'); |
| 48 | + $output->writeln('Index complete time: ' . (new \DateTime('@' . $lastIndexedTime))->format('Y-m-d H:i') . ' UTC'); |
| 49 | + $output->writeln('Total time taken for a complete index: ' . gmdate('H:i', $indexTime) . ' (hh:mm)'); |
| 50 | + } |
| 51 | + |
| 52 | + $queueCount = $this->queueService->count(); |
| 53 | + $output->writeln('Files in indexing queue: ' . $queueCount); |
| 54 | + |
| 55 | + $actionsCount = $this->actionService->count(); |
| 56 | + $output->writeln('Actions in queue: ' . $actionsCount); |
| 57 | + return 0; |
| 58 | + } |
| 59 | +} |
0 commit comments