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