Пример #1
0
 public function board_statistics($output, $shortname = null)
 {
     $boards = $this->radix_coll->getAll();
     $available = $this->board_stats->getAvailableStats();
     while (true) {
         // Obtain all of the statistics already stored on the database to check for update frequency.
         $stats = $this->dc->qb()->select('board_id, name, timestamp')->from($this->dc->p('plugin_fu_board_statistics'), 'bs')->orderBy('timestamp', 'desc')->execute()->fetchAll();
         // Obtain the list of all statistics enabled.
         $avail = [];
         foreach ($available as $k => $a) {
             // get only the non-realtime ones
             if (isset($available['frequency'])) {
                 $avail[] = $k;
             }
         }
         foreach ($boards as $board) {
             if (!is_null($shortname) && $shortname != $board->shortname) {
                 continue;
             }
             // Update all statistics for the specified board or current board.
             $output->writeln($board->shortname . ' (' . $board->id . ')');
             foreach ($available as $k => $a) {
                 $output->writeln('  ' . $k . ' ');
                 $found = false;
                 $skip = false;
                 foreach ($stats as $r) {
                     // Determine if the statistics already exists or that the information is outdated.
                     if ($r['board_id'] == $board->id && $r['name'] == $k) {
                         // This statistics report has run once already.
                         $found = true;
                         if (!isset($a['frequency'])) {
                             $skip = true;
                             continue;
                         }
                         // This statistics report has not reached its frequency EOL.
                         if (time() - $r['timestamp'] <= $a['frequency']) {
                             $skip = true;
                             continue;
                         }
                         break;
                     }
                 }
                 // racing conditions with our cron.
                 if ($found === false) {
                     $this->board_stats->saveStat($board->id, $k, time() + 600, '');
                 }
                 // We were able to obtain a LOCK on the statistics report and has already reached the
                 // targeted frequency time.
                 if ($skip === false) {
                     $output->writeln('* Processing...');
                     $process = 'process' . $a['function'];
                     $result = $this->board_stats->{$process}($board);
                     // Save the statistics report in a JSON array.
                     $this->board_stats->saveStat($board->id, $k, time(), $result);
                 }
             }
         }
         sleep(10);
     }
 }
Пример #2
0
    public function radix_statistics($report = null)
    {
        // Load Statistics Model
        if (is_null($report)) {
            $stats = $this->board_stats->getAvailableStats();
            // Set template variables required to build the HTML.
            $this->builder->getProps()->addTitle(_i('Statistics'));
            $this->param_manager->setParam('section_title', _i('Statistics'));
            ob_start();
            ?>

            <div style="margin: 20px auto; width:960px;">
                <nav style="margin-top:20px;">
                    <ul>
                        <?php 
            foreach ($stats as $key => $stat) {
                ?>
                            <li>
                                <a href="<?php 
                echo $this->uri->create([$this->radix->shortname, 'statistics', $key]);
                ?>
"
                                   title="<?php 
                echo htmlspecialchars($stat['name']);
                ?>
"><?php 
                echo $stat['name'];
                ?>
</a>
                            </li>
                        <?php 
            }
            ?>
                    </ul>
                </nav>
            </div>

            <?php 
            $string = ob_get_clean();
            $partial = $this->builder->createPartial('body', 'plugin');
            $partial->getParamManager()->setParam('content', $string);
            return new Response($this->builder->build());
        } else {
            $stats = $this->board_stats->checkAvailableStats($report, $this->radix);
            if (!is_array($stats)) {
                return $this->error(_i('Statistic currently not available.'));
            }
            $this->builder->getProps()->addTitle(_i('Statistics') . ': ' . $stats['info']['name']);
            if (isset($stats['info']['frequency'])) {
                $last_updated = time() - $stats['timestamp'];
                if ($last_updated < 0) {
                    $last_updated = _i('now!');
                } elseif ($last_updated < 60) {
                    $last_updated = $last_updated . ' ' . _i('seconds');
                } elseif ($last_updated < 3600) {
                    $last_updated = floor($last_updated / 60) . ' ' . _i('minutes');
                } elseif ($last_updated < 86400) {
                    $last_updated = floor($last_updated / 3600) . ' ' . _i('hours');
                } else {
                    $last_updated = floor($last_updated / 86400) . ' ' . _i('days');
                }
                $section_title = sprintf(_i('Statistics: %s (Last Updated: %s ago)'), $stats['info']['name'], $last_updated);
            } else {
                $section_title = sprintf(_i('Statistics: %s'), $stats['info']['name']);
            }
            $this->param_manager->setParam('section_title', $section_title);
            $data = $stats['data'];
            $info = $stats['info'];
            ob_start();
            ?>
            <link href="<?php 
            echo $this->plugin->getAssetManager()->getAssetLink('style.css');
            ?>
" rel="stylesheet"
                  type="text/css"/>
            <div style="margin: 20px auto; width:960px;">
                <?php 
            include __DIR__ . '/../../views/' . $stats['info']['interface'] . '.php';
            ?>
            </div>
            <?php 
            $string = ob_get_clean();
            $partial = $this->builder->createPartial('body', 'plugin');
            $partial->getParamManager()->setParam('content', $string);
            return new Response($this->builder->build());
        }
    }