diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index 8472c8b..150a76c 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -4,13 +4,11 @@ return [ 'dependencies' => [ 'invokables' => [], 'factories' => [ - App\Command\UpdateLabInfoCommand::class => App\Command\UpdateLabInfoFactory::class, App\Command\UpdatePageCachesCommand::class => App\Command\UpdatePageCachesFactory::class, ], ], 'console' => [ 'commands' => [ - App\Command\UpdateLabInfoCommand::class, App\Command\UpdatePageCachesCommand::class, ], ], diff --git a/config/routes.php b/config/routes.php index 48c567a..55688f9 100644 --- a/config/routes.php +++ b/config/routes.php @@ -31,6 +31,3 @@ $app->get('/api/ping', App\Action\PingAction::class, 'api.ping'); $app->get('/api/kanban', App\Action\KanbanAction::class, 'api.kanban'); $app->get('/avatars/{signum}', App\Action\AvatarAction::class, 'user.avatar'); - -$app->get('/api/tsp-info', App\Action\TspInfoAction::class, 'api.tsp-info'); -$app->get('/api/want-some-fun', App\Action\FunAction::class, 'api.fun'); diff --git a/src/App/Action/FunAction.php b/src/App/Action/FunAction.php deleted file mode 100644 index 827de34..0000000 --- a/src/App/Action/FunAction.php +++ /dev/null @@ -1,32 +0,0 @@ -tspInfoService = $tspInfoService; - } - - /** - * @param ServerRequestInterface $request - * @param DelegateInterface $delegate - * @return JsonCorsResponse - */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) - { - return new JsonCorsResponse($this->tspInfoService->getSomeFun()); - } -} diff --git a/src/App/Action/FunFactory.php b/src/App/Action/FunFactory.php deleted file mode 100644 index 05b3452..0000000 --- a/src/App/Action/FunFactory.php +++ /dev/null @@ -1,15 +0,0 @@ -get(FunService::class); - return new FunAction($funService); - } -} diff --git a/src/App/Action/TspInfoAction.php b/src/App/Action/TspInfoAction.php deleted file mode 100644 index 70b110e..0000000 --- a/src/App/Action/TspInfoAction.php +++ /dev/null @@ -1,38 +0,0 @@ -tspInfoService = $tspInfoService; - } - - /** - * @param ServerRequestInterface $request - * @param DelegateInterface $delegate - * @return JsonCorsResponse - */ - public function process(ServerRequestInterface $request, DelegateInterface $delegate) - { - return new JsonCorsResponse($this->tspInfoService->getTspInfo()); - } -} diff --git a/src/App/Action/TspInfoFactory.php b/src/App/Action/TspInfoFactory.php deleted file mode 100644 index 6bd5128..0000000 --- a/src/App/Action/TspInfoFactory.php +++ /dev/null @@ -1,21 +0,0 @@ -get(TspInfoService::class); - return new TspInfoAction($tspInfoService); - } -} diff --git a/src/App/Command/UpdateLabInfoCommand.php b/src/App/Command/UpdateLabInfoCommand.php deleted file mode 100644 index 3900570..0000000 --- a/src/App/Command/UpdateLabInfoCommand.php +++ /dev/null @@ -1,33 +0,0 @@ -labInfoService = $labInfoService; - parent::__construct(); - } - - protected function configure() - { - $this->setName('labinfo:print') - ->setDescription('Updates cache of jcat packages, streams and active nightly ci configuration'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $output->writeln($this->labInfoService->getLabTemperatureData()); - } -} diff --git a/src/App/Command/UpdateLabInfoFactory.php b/src/App/Command/UpdateLabInfoFactory.php deleted file mode 100644 index a1f5462..0000000 --- a/src/App/Command/UpdateLabInfoFactory.php +++ /dev/null @@ -1,16 +0,0 @@ -get(LabInfoCollectorService::class); - return new UpdateLabInfoCommand($labInfoService); - } -} diff --git a/src/App/Command/UpdatePageCachesCommand.php b/src/App/Command/UpdatePageCachesCommand.php index 8ba366d..0baf238 100644 --- a/src/App/Command/UpdatePageCachesCommand.php +++ b/src/App/Command/UpdatePageCachesCommand.php @@ -3,27 +3,20 @@ namespace App\Command; use App\Service\JiraCollectorService; -use App\Service\TspInfoService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class UpdatePageCachesCommand extends Command { - /** - * @var TspInfoService - */ - private $tspInfoService; /** * @var JiraCollectorService */ private $jiraCollectorService; - public function __construct(TspInfoService $tspInfoService, - JiraCollectorService $jiraCollectorService) + public function __construct(JiraCollectorService $jiraCollectorService) { - $this->tspInfoService = $tspInfoService; $this->jiraCollectorService = $jiraCollectorService; parent::__construct(); } @@ -31,12 +24,11 @@ class UpdatePageCachesCommand extends Command protected function configure() { $this->setName('cache:update') - ->setDescription('Updates page-cache data for tspInfo and kanban pages'); + ->setDescription('Updates page-cache data for kanban pages'); } protected function execute(InputInterface $input, OutputInterface $output) { - $this->tspInfoService->getTspInfo(true); $this->jiraCollectorService->getKanbanBoard(true); } } diff --git a/src/App/Command/UpdatePageCachesFactory.php b/src/App/Command/UpdatePageCachesFactory.php index b6a26aa..a6853c1 100644 --- a/src/App/Command/UpdatePageCachesFactory.php +++ b/src/App/Command/UpdatePageCachesFactory.php @@ -4,7 +4,6 @@ namespace App\Command; use App\Action\AvatarAction; use App\Service\JiraCollectorService; -use App\Service\TspInfoService; use Interop\Container\ContainerInterface; use Zend\Expressive\Router\Route; use Zend\Expressive\Router\RouterInterface; @@ -27,8 +26,7 @@ class UpdatePageCachesFactory $router = $container->get(RouterInterface::class); $router->addRoute($avatarRoute); - $tspInfoService = $container->get(TspInfoService::class); $jiraCollectorService = $container->get(JiraCollectorService::class); - return new UpdatePageCachesCommand($tspInfoService, $jiraCollectorService); + return new UpdatePageCachesCommand($jiraCollectorService); } } diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 37e2deb..f38cb06 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -51,12 +51,7 @@ class ConfigProvider Service\AvatarService::class => Service\AvatarServiceFactory::class, Service\JiraCollectorService::class => Service\JiraCollectorServiceFactory::class, - Service\LabInfoCollectorService::class => Service\LabInfoCollectorServiceFactory::class, Service\VacationInfoCollectorService::class => Service\VacationInfoCollectorServiceFactory::class, - Service\TrInfoCollectorService::class => Service\TrInfoCollectorServiceFactory::class, - Service\JcatInfoCollectorService::class => Service\JcatInfoCollectorServiceFactory::class, - Service\TspInfoService::class => Service\TspInfoServiceFactory::class, - Service\FunService::class => Service\FunServiceFactory::class, 'service.cache' => function(ContainerInterface $container): StorageInterface { $cache = new FilesytemCache(); diff --git a/src/App/Entity/TrProgress.php b/src/App/Entity/TrProgress.php deleted file mode 100644 index 9915000..0000000 --- a/src/App/Entity/TrProgress.php +++ /dev/null @@ -1,114 +0,0 @@ -eriref; - } - - /** - * @param string $eriref - * @return TrProgress - */ - public function setEriref(string $eriref): TrProgress - { - $this->eriref = $eriref; - return $this; - } - - /** - * @return string - */ - public function getHeading(): string - { - return $this->heading; - } - - /** - * @param string $heading - * @return TrProgress - */ - public function setHeading(string $heading): TrProgress - { - $this->heading = $heading; - return $this; - } - - /** - * @return string - */ - public function getPrio(): string - { - return $this->prio; - } - - /** - * @param string $prio - * @return TrProgress - */ - public function setPrio(string $prio): TrProgress - { - $this->prio = $prio; - return $this; - } - - /** - * @return int - */ - public function getLastProgressInDays(): int - { - return $this->lastProgressInDays; - } - - /** - * @param int $lastProgressInDays - * @return TrProgress - */ - public function setLastProgressInDays(int $lastProgressInDays): TrProgress - { - $this->lastProgressInDays = $lastProgressInDays; - return $this; - } - - - - /** - * @return array - */ - function jsonSerialize() - { - return [ - 'eriref' => $this->getEriref(), - 'heading' => $this->getHeading(), - 'prio' => $this->getPrio(), - 'lastProgressInDays' => $this->getLastProgressInDays(), - ]; - } -} diff --git a/src/App/Service/FunService.php b/src/App/Service/FunService.php deleted file mode 100644 index 25225e7..0000000 --- a/src/App/Service/FunService.php +++ /dev/null @@ -1,50 +0,0 @@ -cache = $cache; - $this->config = $config; - } - - /** - * @param bool $forceReload - * @return array - */ - public function getSomeFun(bool $forceReload = false): array - { - $tspInfo = $this->cache->getItem(self::CACHE_KEY); - if($forceReload || null == $tspInfo) { - $tspInfo = [ - 'cameraUrls' => $this->config->get('url.eurestCameras')->toArray(), - 'animGifs' => [], - ]; - $this->cache->setItem(self::CACHE_KEY, serialize($tspInfo)); - } else { - $tspInfo = unserialize($tspInfo); - } - return $tspInfo; - } -} diff --git a/src/App/Service/FunServiceFactory.php b/src/App/Service/FunServiceFactory.php deleted file mode 100644 index 4975bc1..0000000 --- a/src/App/Service/FunServiceFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -get('config')['app.config']; - $cache = $container->get('service.cache'); - return new FunService( - $cache, - new Config($appConfig) - ); - } -} diff --git a/src/App/Service/JcatInfoCollectorService.php b/src/App/Service/JcatInfoCollectorService.php deleted file mode 100644 index 4c10854..0000000 --- a/src/App/Service/JcatInfoCollectorService.php +++ /dev/null @@ -1,87 +0,0 @@ -httpClient = $client; - $this->config = $config; - } - - public function getTrFlowErrors() - { - /** @var Config $kanbanBoardUriParams */ - $trFlowUri = $this->config->get('url.jcatTrFlow'); - - $response = $this->httpClient - ->setUri($trFlowUri) - ->send(); - - if (!$response->isSuccess()) { - throw new \UnexpectedValueException("Bad JCAT result", $response->getStatusCode()); - } - - return $this->parseFlowHtmlResult($response->getBody()); - } - - /** - * @param string $html - * @return array - */ - private function parseFlowHtmlResult(string $html) - { - $teamMembers = $this->config->get('team.members')->toArray(); - $xmlErrorHandling = libxml_use_internal_errors(TRUE); - $domDocument = new \DOMDocument(); - $domDocument->loadHTML($html); - libxml_clear_errors(); - libxml_use_internal_errors($xmlErrorHandling); - - $documentXpath = new \DOMXPath($domDocument); - /** @var \DOMNodeList $elements */ - $elements = $documentXpath->query('//tr/td[1]'); - - $result = []; - /** @var \DOMElement $element */ - foreach ($elements as $element) { - /** @var \DOMNodeList $ownerElements */ - $ownerElements = $documentXpath->query('./td[6]', $element->parentNode); - $owner = strtolower(trim($ownerElements->item(0)->nodeValue)); - if (in_array($owner, $teamMembers)) { - $result[] = trim($element->nodeValue); - } - } - - $errorsCounted = array_count_values($result); - - return array_map(function($type, $count) { - return [ - 'label' => $type, - 'value' => $count, - ]; - }, array_keys($errorsCounted), $errorsCounted); - } -} diff --git a/src/App/Service/JcatInfoCollectorServiceFactory.php b/src/App/Service/JcatInfoCollectorServiceFactory.php deleted file mode 100644 index 97dd81c..0000000 --- a/src/App/Service/JcatInfoCollectorServiceFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -get('config'); - $httpClient = $container->get(Client::class); - $config = new Config($configArray['app.config']); - return new JcatInfoCollectorService($httpClient, $config); - } -} diff --git a/src/App/Service/LabInfoCollectorService.php b/src/App/Service/LabInfoCollectorService.php deleted file mode 100644 index 07c3ec8..0000000 --- a/src/App/Service/LabInfoCollectorService.php +++ /dev/null @@ -1,103 +0,0 @@ - 'back_left', - 'Temp 4' => 'back_middle', - 'Temp 3' => 'back_right', - ]; - - /** - * JiraClientService constructor. - * @param Client $client - * @param Config $config - */ - public function __construct(Client $client, Config $config) - { - $this->httpClient = $client; - $this->config = $config; - } - - /** - * @return array - */ - public function getLabTemperatureData() - { - /** @var Config $labTemperatureUrl */ - $labTemperatureUrl = $this->config->get('url.labTemperatureUrl'); - - $response = $this->httpClient - ->setUri($labTemperatureUrl) - ->send(); - - if(!$response->isSuccess()) { - throw new \UnexpectedValueException("Bad LAB result", $response->getStatusCode()); - } - - return $this->parseHtml($response->getBody()); - } - - /** - * @param $html - * @return array - */ - private function parseHtml($html): array - { - $cssToXpathConverter = new CssSelectorConverter(); - $xpathLabelQuery = $cssToXpathConverter->toXPath('a.sensormenu.isnotpaused'); - $xpathValueQuery = $cssToXpathConverter->toXPath('div.graphlabel2'); - - $xmlErrorHandling = libxml_use_internal_errors(TRUE); - $domDocument = new \DOMDocument(); - $domDocument->loadHTML($html); - libxml_clear_errors(); - libxml_use_internal_errors($xmlErrorHandling); - - $documentXpath = new \DOMXPath($domDocument); - /** @var \DOMNodeList $element */ - $element = $documentXpath->query($xpathLabelQuery); - - $thing = []; - /** @var \DOMElement $item */ - foreach($element as $item) { - $sensorName = trim($item->nodeValue); - if( in_array($sensorName, array_keys($this->tempSensors)) ){ - /** @var \DOMNodeList $element */ - $valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode); - $thing[$this->tempSensors[$sensorName]] = $this->getTempNumber($valueElement->item(0)->nodeValue); - } - } - - return $thing; - } - - /** - * @param string $temperatureString - * @return float - */ - private function getTempNumber(string $temperatureString): float - { - preg_match('#([0-9,]+) C#msiu', $temperatureString, $temperatureMatches); - return floatval(str_replace(",", ".", $temperatureMatches[1])); - } -} diff --git a/src/App/Service/LabInfoCollectorServiceFactory.php b/src/App/Service/LabInfoCollectorServiceFactory.php deleted file mode 100644 index 153f204..0000000 --- a/src/App/Service/LabInfoCollectorServiceFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -get('config'); - $httpClient = $container->get(Client::class); - $config = new Config($configArray['app.config']); - return new LabInfoCollectorService($httpClient, $config); - } -} diff --git a/src/App/Service/TrInfoCollectorService.php b/src/App/Service/TrInfoCollectorService.php deleted file mode 100644 index 96c36a7..0000000 --- a/src/App/Service/TrInfoCollectorService.php +++ /dev/null @@ -1,187 +0,0 @@ - self::UNIT_CORE, - 'ETH-TSPCORE' => self::UNIT_CORE, - 'XTS-TSP-SIG' => self::UNIT_SIG, - 'XTS-TSPSIGD' => self::UNIT_SIG, - 'ETH-TADE-DE' => self::UNIT_TADE, - 'ETH-TADE-MA' => self::UNIT_TADE, - ]; - - /** - * @var Config - */ - private $config; - - /** - * @var Client - */ - private $httpClient; - - /** - * JiraClientService constructor. - * @param Client $client - * @param Config $config - */ - public function __construct(Client $client, Config $config) - { - $this->httpClient = $client; - $this->config = $config; - } - - /** - * < 700 daily progress - * * weekly - * @return array - * @todo calculate progress late stuff - */ - public function getProgressInfo() - { - $user = $this->config->get('mhweb.user'); - $password = $this->config->get('mhweb.password'); - /** @var string $trProgressUri */ - $trProgressUri = $this->config->get('url.mhWebTrProgress'); - - $response = $this->httpClient - ->setAuth($user, $password) - ->setUri($trProgressUri) - ->send(); - - if (!$response->isSuccess()) { - throw new \UnexpectedValueException("Bad MHWEB result", $response->getStatusCode()); - } - - $csvResponse = $response->getBody(); - $csvReader = Reader::createFromString($csvResponse); - $csvReader->setHeaderOffset(0); - - return $this->parseProgressCsvRecords($csvReader); - } - - public function getPraGoals() - { - $user = $this->config->get('mhweb.user'); - $password = $this->config->get('mhweb.password'); - /** @var string $trProgressUri */ - $trProgressUri = $this->config->get('url.mhWebPraGoals'); - - $response = $this->httpClient - ->setAuth($user, $password) - ->setUri($trProgressUri) - ->send(); - - if (!$response->isSuccess()) { - throw new \UnexpectedValueException("Bad MHWEB result", $response->getStatusCode()); - } - - $csvResponse = $response->getBody(); - $csvReader = Reader::createFromString($csvResponse); - $csvReader->setHeaderOffset(0); - - $statement = new Statement(); - $csvRecords = $statement - ->process($csvReader); - - $goalCounter = $this->initGoalCounter(); - - foreach ($csvRecords as $record) { - $goalCounter[self::MHO_MAP[$record["mho"]]][$record["prio"]]++; - } - - return $this->caltulatePraBaseDiff($goalCounter); - } - - private function caltulatePraBaseDiff($goalCounter): array - { - $praBaseData = $this->config->get('pra.baseData')->toArray(); - foreach ($goalCounter as $mho => &$counters) { - foreach (['A', 'B', 'C'] as $prio) { - $counters[$prio] = $counters[$prio] - $praBaseData[$prio][$mho]; - } - } - return $goalCounter; - } - - private function parseProgressCsvRecords(Reader $csvReader) - { - $teamMembers = $this->config->get('team.members')->toArray(); - $statement = new Statement(); - $csvRecords = $statement - ->where(function($record) use ($teamMembers) { - return in_array(strtolower($record['owner']), $teamMembers); - }) - ->process($csvReader); - - $trProgressList = []; - foreach ($csvRecords as $csvRecord) { - $trProgress = new TrProgress(); - $trProgress->setEriref($csvRecord["eriref"]) - ->setHeading($csvRecord["heading"]) - ->setPrio($csvRecord["prio"]) - ->setLastProgressInDays($this->getLastProgressInDay($csvRecord)) - ; - $trProgressList[] = $trProgress; - } - - usort($trProgressList, function(TrProgress $a, TrProgress $b){ - return $b->getLastProgressInDays() <=> $a->getLastProgressInDays(); - }); - - return $trProgressList; - } - - /** - * @param array $csvRecord - * @return int - * @todo fix the BS with tuesday or whatever - */ - private function getLastProgressInDay(array $csvRecord): int - { - $lastProgressDate = null; - $hasNoProgressDate = false; - try { - $lastProgressDate = new \DateTime(str_replace(" - "," ", $csvRecord["lastprogressdate"])); - } catch(\Exception $e) { - $hasNoProgressDate = true; - } - try { - $lastDesignDate = new \DateTime($csvRecord["lastdesigndate"]); - if($hasNoProgressDate || $lastDesignDate > $lastProgressDate) { - $lastProgressDate = $lastDesignDate; - } - } catch (\Exception $e) { - if($hasNoProgressDate) { - return 0; - } - } - - $now = new \DateTime(); - $dateDiff = $now->diff($lastProgressDate); - return $dateDiff->days; - } - - private function initGoalCounter(): array - { - $emptyPrios = ['A' => 0, 'B' => 0, 'C' => 0]; - return [ - self::UNIT_CORE => $emptyPrios, - self::UNIT_SIG => $emptyPrios, - self::UNIT_TADE => $emptyPrios, - ]; - } -} diff --git a/src/App/Service/TrInfoCollectorServiceFactory.php b/src/App/Service/TrInfoCollectorServiceFactory.php deleted file mode 100644 index 7c88602..0000000 --- a/src/App/Service/TrInfoCollectorServiceFactory.php +++ /dev/null @@ -1,18 +0,0 @@ -get('config'); - $httpClient = $container->get(Client::class); - $config = new Config($configArray['app.config']); - return new TrInfoCollectorService($httpClient, $config); - } -} diff --git a/src/App/Service/TspInfoService.php b/src/App/Service/TspInfoService.php deleted file mode 100644 index d15e529..0000000 --- a/src/App/Service/TspInfoService.php +++ /dev/null @@ -1,81 +0,0 @@ -cache = $cache; - $this->vacationInfoCollectorService = $vacationInfoCollectorService; - $this->trInfoCollectorService = $trInfoCollectorService; - $this->jcatInfoCollectorService = $jcatInfoCollectorService; - $this->labInfoCollectorService = $labInfoCollectorService; - $this->jiraCollectorService = $jiraCollectorService; - } - - /** - * @param bool $forceReload - * @return array - */ - public function getTspInfo(bool $forceReload = false): array - { - $tspInfo = $this->cache->getItem(self::CACHE_KEY); - if($forceReload || null == $tspInfo) { - $tspInfo = [ - 'praGoals' => $this->trInfoCollectorService->getPraGoals(), - 'trProgressInfo' => $this->trInfoCollectorService->getProgressInfo(), - 'trFlowErrors' => $this->jcatInfoCollectorService->getTrFlowErrors(), - 'expedites' => $this->jiraCollectorService->getExpedites(), -// 'isVacationSoon' => $this->vacationInfoCollectorService->isVacationSoon(), -// 'labTemperature' => $this->labInfoCollectorService->getLabTemperatureData(), - ]; - $this->cache->setItem(self::CACHE_KEY, serialize($tspInfo)); - } else { - $tspInfo = unserialize($tspInfo); - } - return $tspInfo; - } -} diff --git a/src/App/Service/TspInfoServiceFactory.php b/src/App/Service/TspInfoServiceFactory.php deleted file mode 100644 index 3821903..0000000 --- a/src/App/Service/TspInfoServiceFactory.php +++ /dev/null @@ -1,28 +0,0 @@ -get('service.cache'); - $dataCollectorService = $container->get(VacationInfoCollectorService::class); - $trInfoCollectorService = $container->get(TrInfoCollectorService::class); - $jcatInfoCollectorService = $container->get(JcatInfoCollectorService::class); - $labInfoCollectorService = $container->get(LabInfoCollectorService::class); - $jiraInfoCollectorService = $container->get(JiraCollectorService::class); - return new TspInfoService( - $cache, - $dataCollectorService, - $trInfoCollectorService, - $jcatInfoCollectorService, - $labInfoCollectorService, - $jiraInfoCollectorService - ); - } -}