<?php
/**
* SeekQuarry/Yioop --
* Open Source Pure PHP Search Engine, Crawler, and Indexer
*
* Copyright (C) 2009 - 2026 Chris Pollett chris@pollett.org
*
* LICENSE:
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* END LICENSE
*
* @author Chris Pollett chris@pollett.org
* @license https://www.gnu.org/licenses/ GPL3
* @link https://www.seekquarry.com/
* @copyright 2009 - 2026
* @filesource
*/
namespace seekquarry\yioop\views\elements;
use seekquarry\yioop as B;
use seekquarry\yioop\configs as C;
/**
* CrawlspeedElement draws the Crawl Speed Data page of one crawl, which
* Manage Crawls opens from the [Crawl Speed History] link of a running
* crawl or from the Visited/Extracted Urls counts of a crawl in its
* Crawls table.
*
* @author Chris Pollett
*/
class CrawlspeedElement extends Element
{
/**
* render draws the page: a close button that goes back to Manage
* Crawls, a heading naming the crawl, and the table of the crawl's
* speed over time. CrawlSpeedJob logs a row each
* CRAWL_SPEED_SAMPLE_INTERVAL seconds while the crawl runs, and the
* table lists the rows newest first, in the order a page goes through
* the crawl: the time; the pages the fetchers downloaded per hour,
* summed over the fetchers; the files of fetcher data waiting for the
* indexers, summed over the queue servers; the pages the indexers
* stored per hour; the count of pages indexed; and the total urls
* seen. A row logged before the downloads and the backlog were kept
* shows those two empty. On a narrow screen the table scrolls sideways
* inside its box.
*
* @param array $data the crawl's description under CRAWL_NAME, its
* rows, oldest first, under SPEED_HISTORY, and the token that
* shows a request came from this site, under the name CSRF_TOKEN
* gives
*/
public function render($data)
{
$admin_url = str_replace("&", "&", B\controllerUrl('admin', true));
?>
<div class="current-activity">
<?=$this->view->helper("close")->render($admin_url .
"a=manageCrawls&" . C\p('CSRF_TOKEN') . "=" .
$data[C\p('CSRF_TOKEN')]); ?>
<h2><?= tl('crawlspeed_element_speed_data', $data['CRAWL_NAME'])
?></h2><?php
if (empty($data['SPEED_HISTORY'])) {
?><p><?= tl('crawlstatus_view_no_speed_history',
intval(C\CRAWL_SPEED_SAMPLE_INTERVAL / C\ONE_MINUTE))
?></p><?php
} else { ?>
<div class="speed-history">
<table class="admin-table">
<tr><th><?= tl('crawlstatus_view_sample_time') ?></th>
<th><?= tl('crawlstatus_view_sample_downloaded') ?></th>
<th><?= tl('crawlstatus_view_sample_index_backlog') ?></th>
<th><?= tl('crawlstatus_view_sample_indexed_per_hour') ?></th>
<th><?= tl('crawlstatus_view_sample_indexed_count') ?></th>
<th><?= tl('crawlstatus_view_sample_seen') ?></th>
</tr><?php
foreach (array_reverse($data['SPEED_HISTORY']) as $row) {
[$time, $per_hour, $visited, $seen, $backlog,
$fetcher_rate] = array_pad($row, 6, "");
?><tr><td><?= date("Y-m-d H:i", intval($time)) ?></td>
<td><?= ($fetcher_rate === "") ? "" : intval($fetcher_rate)
?></td>
<td><?= ($backlog === "") ? "" : intval($backlog) ?></td>
<td><?= number_format(floatval($per_hour), 2, ".", "")
?></td><td><?= intval($visited) ?></td>
<td><?= intval($seen) ?></td></tr><?php
} ?>
</table>
</div><?php
} ?>
</div><?php
}
}