function doTest() { global $HOST; global $TOTAL; global $HREFS; global $REQUESTS_CNT; $RESULTS = array(); $j = 0; foreach ($HREFS as $href => $name) { ++$j; $href = ensure_starts_with($href, '/'); $path = "http://{$HOST}{$href}"; $sec = Secundomer::inst(); for ($index = 0; $index <= $REQUESTS_CNT; $index++) { if ($index == 0) { //Пропустим первый вызов, на случай кеширования file_get_contents($path); continue; } $sec->start(); file_get_contents($path); $sec->stop(); ++$TOTAL; } dolog(pad_zero_left($j, 2) . '/' . count($HREFS) . " [{$path}] - " . $sec->getAverage() . ' (' . $sec->getTotalTime() . '/' . $sec->getCount() . ')'); $RESULTS[$path] = str_replace('.', ',', round($sec->getAverage(), 2)); } asort($RESULTS, SORT_DESC); $RESULTS = array_reverse($RESULTS, true); return $RESULTS; }
/** * Процесс строит скрипты для вставки ячеек в БД * * @param array $argv */ function executeProcess(array $argv) { $DM = DirManager::inst(array(__DIR__, 'output')); $customNum = $argv[1]; dolog('Processing mosaic demo, custom num={}', $customNum); /* @var $dir DirItem */ foreach ($DM->getDirContent(null, DirItemFilter::DIRS) as $dir) { if (is_inumeric($customNum) && $customNum != $dir->getName()) { continue; //---- } $imgDM = DirManager::inst($dir->getAbsPath()); $imgDI = end($imgDM->getDirContent(null, DirItemFilter::IMAGES)); $map = $imgDM->getDirItem(null, 'map', 'txt')->getFileAsProps(); $demoDM = DirManager::inst($imgDM->absDirPath(), 'demo'); $demoDM->clearDir(); dolog("Building map for: [{}].", $imgDI->getRelPath()); //CELLS BINDING $dim = $imgDM->getDirItem(null, 'settings', 'txt')->getFileAsProps(); $dim = $dim['dim']; $dim = explode('x', $dim); $cw = 1 * $dim[0]; $ch = 1 * $dim[1]; $sourceImg = SimpleImage::inst()->load($imgDI); $w = $sourceImg->getWidth(); $h = $sourceImg->getHeight(); $destImg = SimpleImage::inst()->create($w, $h, MosaicImage::BG_COLOR); dolog("Img size: [{$w} x {$h}]."); check_condition($w > 0 && !($w % $cw), 'Bad width'); check_condition($h > 0 && !($h % $ch), 'Bad height'); $totalCells = count($map); $lengtn = strlen("{$totalCells}"); //dolog("Cells cnt: [$xcells x $ycells], total: $totalCells."); //СТРОИМ КАРТИНКИ $secundomer = Secundomer::startedInst(); //$encoder = new PsGifEncoder(); for ($cellCnt = 0; $cellCnt <= $totalCells; $cellCnt++) { $name = pad_zero_left($cellCnt, $lengtn); $copyTo = $demoDM->absFilePath(null, $name, 'jpg'); if ($cellCnt > 0) { $cellParams = $map[$cellCnt]; $cellParams = explode('x', $cellParams); $xCell = $cellParams[0]; $yCell = $cellParams[1]; $x = ($xCell - 1) * $cw; $y = ($yCell - 1) * $ch; $destImg->copyFromAnother($sourceImg, $x, $y, $x, $y, $cw, $ch); } $destImg->save($copyTo); dolog("[{$totalCells}] {$copyTo}"); } //$encoder->saveToFile($demoDM->absFilePath(null, 'animation')); $secundomer->stop(); dolog('Execution time: ' . $secundomer->getTotalTime()); } }
function __construct($date) { $date = trim($date); if (!$date) { return; //Невалидная дата } $this->date = $date; //Дата - до Н.Э. (570 BC) if (ends_with($date, ' BC')) { $tmp = explode(' ', $date); $y = count($tmp) == 2 ? $tmp[0] : null; if (is_numeric($y)) { $this->y = (int) $y; $this->type = self::TYPE_BC; $this->weight = -$this->y; $this->Ymd = $date; } return; //--- } //Дальше действовать будет date_parse:) $tmp = date_parse($date); $error_count = array_get_value('error_count', $tmp, 0); $warning_count = array_get_value('warning_count', $tmp, 0); if ($error_count || $warning_count) { return; //Невалидная дата } //Валидная дата $this->y = (int) $tmp['year']; $this->m = (int) $tmp['month']; $this->d = (int) $tmp['day']; $this->hh = (int) $tmp['hour']; $this->mm = (int) $tmp['minute']; $this->ss = (int) $tmp['second']; $y = pad_zero_left($this->y, 4); $m = pad_zero_left($this->m, 2); $d = pad_zero_left($this->d, 2); $this->type = self::TYPE_VALID; $this->weight = (int) "{$y}{$m}{$d}"; $this->Ymd = "{$y}-{$m}-{$d}"; }
private function toStringImpl($type, $date) { if (isEmpty($date)) { return null; } /* @var $dateAdapter DateAdapter */ $dateAdapter = $this->getDateAdapter($date); if (!$dateAdapter) { return $date; } if ($dateAdapter->isBC()) { return $dateAdapter->y() . 'г. до н.э.'; } else { $d = $dateAdapter->d(); $m = $dateAdapter->m(); $y = $dateAdapter->y(); switch ($type) { case self::TS_MONTH_FULL: case self::TS_MONTH_SHORT: $mt = $this->decodeMonth($m, $type); return "{$d} {$mt} {$y}" . 'г.'; case self::TS_NUMBERED: $d = pad_zero_left($d, 2); $m = pad_zero_left($m, 2); return "{$d}.{$m}.{$y}" . 'г.'; } } }
private function doSolve($rebus) { $this->LOGGER->info("Обрабатываем ребус: [{$rebus}], пропускать первые символы={$this->SCIP_FIRST_CHARS}"); $this->COMBINATIONS = array(); check_condition($rebus, "Пустой ребус"); $eqCnt = substr_count($rebus, '='); check_condition($eqCnt == 1, "Знак равенства '=' встретился {$eqCnt} раз"); $this->LOGGER->info("Приведённый вид: [{$rebus}]"); $enCh = array(); $ruCh = array(); for ($i = 0; $i < ps_strlen($rebus); $i++) { //русский символ $letter = ps_charat($rebus, $i); if ($this->isRuChar($letter)) { if (!array_key_exists($letter, $ruCh)) { $ruCh[$letter] = null; } continue; } if ($this->isEnChar($letter)) { //английский символ if (!in_array($letter, $enCh)) { $enCh[] = $letter; } continue; } } $this->LOGGER->info('Русские символы: ' . print_r($ruCh, true)); $this->LOGGER->info('Английские символы: ' . print_r($enCh, true)); foreach ($ruCh as $ch => $value) { for ($i = 0; $i < strlen($this->EN); $i++) { $letter = substr($this->EN, $i, 1); if (!in_array($letter, $enCh)) { $enCh[] = $letter; $ruCh[$ch] = $letter; break; } } } $this->LOGGER->info('После привязки: '); $this->LOGGER->info('Русские символы: ' . print_r($ruCh, true)); $this->LOGGER->info('Английские символы: ' . print_r($enCh, true)); $enCharsCnt = count($enCh); check_condition($enCharsCnt > 0, 'Нет символов для перебора'); check_condition($enCharsCnt <= 10, "Слишком много переменных: {$enCharsCnt}"); $rebus = PsStrings::replaceMap($rebus, $ruCh); $this->LOGGER->info("Подготовленный ребус: [{$rebus}]"); $this->LOGGER->info("Всего символов для перебора: {$enCharsCnt}"); $this->LOGGER->info('Возможных комбинаций: ' . $this->variantsCnt($enCharsCnt)); $this->REBUS = $rebus; $this->EXPR = str_replace('=', '-', $rebus); $hasBefore = false; for ($i = 0; $i < strlen($rebus); $i++) { $char = substr($rebus, $i, 1); if ($this->isEnChar($char)) { //Символ перебора if (!$hasBefore) { $this->FIRST_CHARS[] = $char; $hasBefore = true; } } else { $hasBefore = false; } } $this->LOGGER->info('Начинаем перебор...'); $numbers = array(0 => false, 1 => false, 2 => false, 3 => false, 4 => false, 5 => false, 6 => false, 7 => false, 8 => false, 9 => false); $secundomer = Secundomer::startedInst(); for ($i = 0; $i <= 9; $i++) { $letter = reset($enCh); if ($this->isScip($i, $letter)) { continue; } $next = next($enCh); $numbers[$i] = $letter; $this->doCheckIteration($enCh, $next, $numbers); $numbers[$i] = false; } $secundomer->stop(); $parsed = DatesTools::inst()->parseSeconds(round($secundomer->getTotalTime())); $min = $parsed['mf']; $sec = pad_zero_left($parsed['s'], 2); $parsed = "{$min}:{$sec}"; $combCnt = count($this->COMBINATIONS); $this->LOGGER->info("Перебор закончен. Обработано операций: {$this->cnt}, найдено решений: {$combCnt}."); $this->LOGGER->info("Общее время обработки: {$parsed}."); return $this->COMBINATIONS; }
$sourceImg = SimpleImage::inst()->load($imgAbs); $w = $sourceImg->getWidth(); $h = $sourceImg->getHeight(); $destImg = SimpleImage::inst()->create($w, $h, MosaicImage::BG_COLOR); dolog("Img size: [{$w} x {$h}]."); check_condition($w > 0 && !($w % $cw), 'Bad width'); check_condition($h > 0 && !($h % $ch), 'Bad height'); $totalCells = count($map); $lengtn = strlen("{$totalCells}"); //dolog("Cells cnt: [$xcells x $ycells], total: $totalCells."); //СТРОИМ КАРТИНКИ $generator = new MosaicCellsGenerator($totalCells); $secundomer = Secundomer::startedInst(); //$encoder = new PsGifEncoder(); for ($cellCnt = 0; $cellCnt <= $totalCells; $cellCnt++) { $name = pad_zero_left($cellCnt, $lengtn); $copyTo = $demoDM->absFilePath(null, $name, 'jpg'); if ($cellCnt > 0) { $cellParams = $map[$cellCnt]; $cellParams = explode('x', $cellParams); $xCell = $cellParams[0]; $yCell = $cellParams[1]; $x = ($xCell - 1) * $cw; $y = ($yCell - 1) * $ch; $destImg->copyFromAnother($sourceImg, $x, $y, $x, $y, $cw, $ch); } $destImg->save($copyTo); dolog("[{$totalCells}] {$copyTo}"); } //$encoder->saveToFile($demoDM->absFilePath(null, 'animation')); $secundomer->stop();