logger = $logger; $this->identities = $identities; $this->cache_files_path = $cfpath; } /** * @inheritDoc */ public function updateCache(EGGDatabase $db) { $years = $db->getAllYears(); $dyears = []; $result = ""; foreach ($years as $year) { $gen = new SingleYearRenderer($this->logger, $year, $this->identities, $this->cache_files_path); $cc = $gen->updateCache($db); if ($cc === null) continue; $result .= $cc; $result .= "\n\n\n"; $dyears []= $year; } $data = json_encode($dyears); $path = Utils::sharpFormat($this->cache_files_path, ['ident' => 'fullrenderer']); file_put_contents($path, $data); $this->logger->proclog("Updated cache file for full renderer"); return $result; } /** * @inheritDoc */ public function loadFromCache() { $path = Utils::sharpFormat($this->cache_files_path, ['ident' => 'fullrenderer']); if (!file_exists($path)) { $this->logger->proclog("No cache found for [fullrenderer]"); return null; } $years = json_decode(file_get_contents($path)); $result = ""; foreach ($years as $year) { $gen = new SingleYearRenderer($this->logger, $year, $this->identities, $this->cache_files_path); $cc = $gen->loadFromCache(); if ($cc === null) return null; $result .= $cc; $result .= "\n\n\n"; } return $result; } } class SingleYearRenderer implements IOutputGenerator { const DIST_X = 13; const DIST_Y = 13; const DAY_WIDTH = 11; const DAY_HEIGHT = 11; const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; const DAYS = ['M', 'T', 'W', 'T', 'F', 'S', 'S']; /** @var ILogger $logger */ private $logger; /** @var int $year */ private $year; /** @var string[] $identities */ private $identities; /** @var string $cache_files_path */ private $cache_files_path; /** * @param ILogger $logger * @param int $year * @param string[] $identities * @param string $cfpath */ public function __construct(ILogger $logger, int $year, array $identities, string $cfpath) { $this->logger = $logger; $this->year = $year; $this->identities = $identities; $this->cache_files_path = $cfpath; } /** * @inheritDoc */ public function loadFromCache() { $path = Utils::sharpFormat($this->cache_files_path, ['ident' => 'singleyear_'.$this->year]); if (!file_exists($path)) { $this->logger->proclog("No cache found for [".('singleyear_'.$this->year)."]"); return null; } return file_get_contents($path); } /** * @inheritDoc */ public function updateCache(EGGDatabase $db) { $this->logger->proclog("Generate cache file for year ".$this->year); $data = $this->generate($db); if ($data === null) { $this->logger->proclog("No data for year ".$this->year); $this->logger->proclog(""); return null; } $path = Utils::sharpFormat($this->cache_files_path, ['ident' => 'singleyear_'.$this->year]); file_put_contents($path, $data); $this->logger->proclog("Updated cache file for year ".$this->year); $this->logger->proclog(""); return $data; } /** * @param EGGDatabase $db * @return string|null * @throws Exception */ private function generate(EGGDatabase $db) { $dbdata = $db->getCommitCountOfYearByDate($this->year, $this->identities); if (Utils::array_value_max(0, $dbdata) === 0) return null; $now = new DateTime(); $date = new DateTime($this->year . '-01-01'); $ymapmax = Utils::array_value_max(1, $dbdata); $monthlist = array_fill(0, 12, [0, 0]); $exponent9 = log(0.98/((9)-1), 1/$ymapmax); $exponent5 = log(0.98/((5)-1), 1/$ymapmax); $html = ''; $html .= '