Beispiel #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $start = microtime(true);
     $stats = Stats::getInstance();
     $output->writeln('ConfigFile ' . $stats->getConfigFile());
     $output->writeln('Database ' . $stats->getDataBaseFile());
     $output->writeln('Config ' . print_r($stats->getConfig(), true));
     $output->writeln('ProjectDir ' . $stats->getProjectDir());
     foreach ($stats->getModels() as $model) {
         for ($i = 0; $i < self::RECORDS; $i++) {
             $data = array('data' => '#' . intval((microtime(true) - $start) * 10000000000.0), 'count' => rand(1, 10), 'date' => intval(date('U')) + 86400 * rand(-5, 5));
             $stats->getConn()->exec($model->getInsert($data));
         }
     }
     $output->writeln('Done!');
 }
Beispiel #2
0
<?php

require_once __DIR__ . '/../../vendor/autoload.php';
$stats = \JLaso\SimpleStats\Stats::getInstance();
$scatterGraph = new \JLaso\SimpleStats\Graph\Scatter();
$barGraph = new \JLaso\SimpleStats\Graph\Bar();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Example of Simple Stats</h1>
<div>
    <?php 
$scatterGraph->draw('Example scatter', 'clicks,ips', array(0, 99999999999), 600, 480);
?>
</div>
<div>
    <a href="../click.php?data=click_link&redirect=plain-php/<?php 
echo basename(__FILE__);
?>
">Click</a>
    <span>&nbsp;count [<?php 
echo $stats->getCountByData('ips', $stats->getUserIP());
?>
]</span>
</div>
<div>
Beispiel #3
0
// in order to check live changes
exec('rm -rf ' . CACHE_DIR . '/*');
$loader = new Twig_Loader_Filesystem(__DIR__);
$twig = new Twig_Environment($loader, array('cache' => CACHE_DIR));
// TWIG FUNCTIONS TO HANDLE STATS GRAPHICS SIMPLY
$twig->addFunction(new Twig_SimpleFunction('statsGraph', function ($graphName, $title, $event, $range, $width, $height) {
    $graph = null;
    switch (strtolower(trim($graphName))) {
        case 'scatter':
            $graph = new \JLaso\SimpleStats\Graph\Scatter();
            break;
        case 'bar':
            $graph = new \JLaso\SimpleStats\Graph\Bar();
            break;
        default:
            return "Graph {$graph} not recognized in statsGraph twig function";
    }
    $file = uniqid($graphName . '-') . '.svg';
    $graph->draw($title, $event, $range, $width, $height, CACHE_DIR . '/' . $file);
    return '<img src="cache/' . $file . '" alt="' . $title . '">';
}, array('pre_escape' => 'html', 'is_safe' => array('html'))));
$twig->addFunction(new Twig_SimpleFunction('statsCount', function ($event, $data) {
    return \JLaso\SimpleStats\Stats::getInstance()->getCountByData($event, $data);
}));
$twig->addFunction(new Twig_SimpleFunction('userIP', function () {
    return \JLaso\SimpleStats\Stats::getInstance()->getUserIP();
}));
$twig->addFunction(new Twig_SimpleFunction('home', function () {
    return basename(__FILE__);
}));
echo $twig->render('demo.html.twig');