From d10ebb4931256f485f178fa461ae182a38a839fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Fri, 8 Sep 2017 09:44:30 +0200 Subject: [PATCH] * tsp-info parts added --- config/autoload/local.php.dist | 16 +++++++++++++- src/App/Action/TspInfoAction.php | 18 ++++++++++----- src/App/Action/TspInfoFactory.php | 3 +++ src/App/Entity/TrProgress.php | 14 ++++++------ src/App/Service/JcatInfoCollectorService.php | 23 +++++++++++++++++--- src/App/Service/LabInfoCollectorService.php | 19 +++++++++++++++- src/App/Service/TrInfoCollectorService.php | 17 ++++++++++----- 7 files changed, 87 insertions(+), 23 deletions(-) diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist index 4756589..040ee25 100644 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -15,6 +15,17 @@ return [ 'mhweb.user' => '...', 'mhweb.password' => '...', + 'team.members' => [ + 'ebalcse', + 'edvidan', + 'efersip', + 'emakazi', + 'enorsos', + 'epetfid', + 'eroroba', + 'esndkov', + ], + 'pra.baseData' => [ 'A' => [ TrInfo::UNIT_CORE => 0, @@ -70,7 +81,10 @@ return [ 'url.vacation' => 'https://rhp.common.hu.eld.ericsson.se/vacation.php?action=groupview&dm_h=2&dm_v=1&group_id=478', 'url.jcatTrFlow' => "http://jcat.tsp.eth.ericsson.se:8080/Trweb/trflow/reader.php?query=SELECT+*+FROM+trinfo+where+validationerrors+!=+''", - 'url.eurestCamera2' => 'https://auto:auto@91.82.89.112:8443/mjpg/video.mjpg', + 'url.eurestCameras' => [ + 'https://user:user@91.82.89.112/mjpg/video.mjpg', + 'https://user:user@91.82.89.112:8443/mjpg/video.mjpg', + ], 'http.proxy.enabled' => false, 'http.proxy.type' => CURLPROXY_SOCKS5, diff --git a/src/App/Action/TspInfoAction.php b/src/App/Action/TspInfoAction.php index 5ddd1ed..3d38b4b 100644 --- a/src/App/Action/TspInfoAction.php +++ b/src/App/Action/TspInfoAction.php @@ -11,9 +11,15 @@ use App\Service\VacationInfoCollectorService; use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; +use Zend\Config\Config; class TspInfoAction implements ServerMiddlewareInterface { + /** + * @var Config + */ + private $config; + /** * @var VacationInfoCollectorService */ @@ -39,12 +45,14 @@ class TspInfoAction implements ServerMiddlewareInterface */ private $jiraCollectorService; - public function __construct(VacationInfoCollectorService $vacationInfoCollectorService, + public function __construct(Config $config, + VacationInfoCollectorService $vacationInfoCollectorService, TrInfoCollectorService $trInfoCollectorService, JcatInfoCollectorService $jcatInfoCollectorService, LabInfoCollectorService $labInfoCollectorService, JiraCollectorService $jiraCollectorService) { + $this->config = $config; $this->vacationInfoCollectorService = $vacationInfoCollectorService; $this->trInfoCollectorService = $trInfoCollectorService; $this->jcatInfoCollectorService = $jcatInfoCollectorService; @@ -56,17 +64,17 @@ class TspInfoAction implements ServerMiddlewareInterface * @param ServerRequestInterface $request * @param DelegateInterface $delegate * @return JsonCorsResponse - * @todo lab temperature data */ public function process(ServerRequestInterface $request, DelegateInterface $delegate) { return new JsonCorsResponse([ + 'cameraUrls' => $this->config->get('url.eurestCameras')->toArray(), 'animGifs' => [], 'praGoals' => $this->trInfoCollectorService->getPraGoals(), - 'trProgress' => $this->trInfoCollectorService->getProgressInfo(), - 'trFlow' => $this->jcatInfoCollectorService->getTrFlow(), + 'trProgressInfo' => $this->trInfoCollectorService->getProgressInfo(), + 'trFlowErrors' => $this->jcatInfoCollectorService->getTrFlowErrors(), 'expedites' => $this->jiraCollectorService->getExpedites(), - 'vacationInfo' => $this->vacationInfoCollectorService->isVacationSoon(), + 'isVacationSoon' => $this->vacationInfoCollectorService->isVacationSoon(), 'labTemperature' => $this->labInfoCollectorService->getLabTemperatureData(), ]); } diff --git a/src/App/Action/TspInfoFactory.php b/src/App/Action/TspInfoFactory.php index 70c9234..7bb6587 100644 --- a/src/App/Action/TspInfoFactory.php +++ b/src/App/Action/TspInfoFactory.php @@ -8,11 +8,13 @@ use App\Service\LabInfoCollectorService; use App\Service\TrInfoCollectorService; use App\Service\VacationInfoCollectorService; use Interop\Container\ContainerInterface; +use Zend\Config\Config; class TspInfoFactory { public function __invoke(ContainerInterface $container) { + $appConfig = $container->get('config')['app.config']; $dataCollectorService = $container->get(VacationInfoCollectorService::class); $trInfoCollectorService = $container->get(TrInfoCollectorService::class); $jcatInfoCollectorService = $container->get(JcatInfoCollectorService::class); @@ -20,6 +22,7 @@ class TspInfoFactory $jiraInfoCollectorService = $container->get(JiraCollectorService::class); return new TspInfoAction( + new Config($appConfig), $dataCollectorService, $trInfoCollectorService, $jcatInfoCollectorService, diff --git a/src/App/Entity/TrProgress.php b/src/App/Entity/TrProgress.php index 73b4ffd..9915000 100644 --- a/src/App/Entity/TrProgress.php +++ b/src/App/Entity/TrProgress.php @@ -23,7 +23,7 @@ class TrProgress implements \JsonSerializable /** * @var int */ - private $lastProgress; + private $lastProgressInDays; /** * @return string @@ -82,18 +82,18 @@ class TrProgress implements \JsonSerializable /** * @return int */ - public function getLastProgress(): int + public function getLastProgressInDays(): int { - return $this->lastProgress; + return $this->lastProgressInDays; } /** - * @param int $lastProgress + * @param int $lastProgressInDays * @return TrProgress */ - public function setLastProgress(int $lastProgress): TrProgress + public function setLastProgressInDays(int $lastProgressInDays): TrProgress { - $this->lastProgress = $lastProgress; + $this->lastProgressInDays = $lastProgressInDays; return $this; } @@ -108,7 +108,7 @@ class TrProgress implements \JsonSerializable 'eriref' => $this->getEriref(), 'heading' => $this->getHeading(), 'prio' => $this->getPrio(), - 'lastProgress' => $this->getLastProgress(), + 'lastProgressInDays' => $this->getLastProgressInDays(), ]; } } diff --git a/src/App/Service/JcatInfoCollectorService.php b/src/App/Service/JcatInfoCollectorService.php index 5f191b1..4c10854 100644 --- a/src/App/Service/JcatInfoCollectorService.php +++ b/src/App/Service/JcatInfoCollectorService.php @@ -31,7 +31,7 @@ class JcatInfoCollectorService $this->config = $config; } - public function getTrFlow() + public function getTrFlowErrors() { /** @var Config $kanbanBoardUriParams */ $trFlowUri = $this->config->get('url.jcatTrFlow'); @@ -47,8 +47,13 @@ class JcatInfoCollectorService 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); @@ -62,9 +67,21 @@ class JcatInfoCollectorService $result = []; /** @var \DOMElement $element */ foreach ($elements as $element) { - $result[] = trim($element->nodeValue); + /** @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); + } } - return array_count_values($result); + $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/LabInfoCollectorService.php b/src/App/Service/LabInfoCollectorService.php index d1f56c5..07c3ec8 100644 --- a/src/App/Service/LabInfoCollectorService.php +++ b/src/App/Service/LabInfoCollectorService.php @@ -38,6 +38,9 @@ class LabInfoCollectorService $this->config = $config; } + /** + * @return array + */ public function getLabTemperatureData() { /** @var Config $labTemperatureUrl */ @@ -54,6 +57,10 @@ class LabInfoCollectorService return $this->parseHtml($response->getBody()); } + /** + * @param $html + * @return array + */ private function parseHtml($html): array { $cssToXpathConverter = new CssSelectorConverter(); @@ -77,10 +84,20 @@ class LabInfoCollectorService if( in_array($sensorName, array_keys($this->tempSensors)) ){ /** @var \DOMNodeList $element */ $valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode); - $thing[$this->tempSensors[$sensorName]] = $valueElement->item(0)->nodeValue; + $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/TrInfoCollectorService.php b/src/App/Service/TrInfoCollectorService.php index 6b7d52e..96c36a7 100644 --- a/src/App/Service/TrInfoCollectorService.php +++ b/src/App/Service/TrInfoCollectorService.php @@ -45,7 +45,10 @@ class TrInfoCollectorService } /** + * < 700 daily progress + * * weekly * @return array + * @todo calculate progress late stuff */ public function getProgressInfo() { @@ -105,10 +108,10 @@ class TrInfoCollectorService private function caltulatePraBaseDiff($goalCounter): array { - $praBaseData = $this->config->get('pra.baseData'); + $praBaseData = $this->config->get('pra.baseData')->toArray(); foreach ($goalCounter as $mho => &$counters) { foreach (['A', 'B', 'C'] as $prio) { - $counters[$prio] = $counters[$prio] - $praBaseData[$mho][$prio]; + $counters[$prio] = $counters[$prio] - $praBaseData[$prio][$mho]; } } return $goalCounter; @@ -116,25 +119,27 @@ class TrInfoCollectorService 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"]) - ->setLastProgress($this->getLastProgressInDay($csvRecord)) + ->setLastProgressInDays($this->getLastProgressInDay($csvRecord)) ; - $trProgressList[] = $trProgress; } usort($trProgressList, function(TrProgress $a, TrProgress $b){ - return $b->getLastProgress() <=> $a->getLastProgress(); + return $b->getLastProgressInDays() <=> $a->getLastProgressInDays(); }); return $trProgressList;