* tsp-info parts added

This commit is contained in:
Dávid Danyi
2017-09-08 09:44:30 +02:00
parent efc6e7b0c4
commit d10ebb4931
7 changed files with 87 additions and 23 deletions

View File

@@ -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(),
]);
}

View File

@@ -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,

View File

@@ -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(),
];
}
}

View File

@@ -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);
}
}

View File

@@ -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]));
}
}

View File

@@ -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;