command for stats
parent
c8e2be1beb
commit
183e5f4452
|
@ -3,10 +3,12 @@
|
|||
|
||||
use Gist\Command\CreateCommand;
|
||||
use Gist\Command\UpdateCommand;
|
||||
use Gist\Command\StatsCommand;
|
||||
|
||||
$app = require __DIR__.'/bootstrap.php';
|
||||
|
||||
$app['console']->add(new CreateCommand());
|
||||
$app['console']->add(new UpdateCommand());
|
||||
$app['console']->add(new StatsCommand());
|
||||
|
||||
$app['console']->run();
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Gist\Command;
|
||||
|
||||
use Knp\Command\Command;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use GitWrapper\GitException;
|
||||
|
||||
class StatsCommand extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('stats')
|
||||
->setDescription('Show stats about GIST')
|
||||
->setHelp(<<<EOF
|
||||
Show stats about GIST
|
||||
EOF
|
||||
);
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$gistService = $this->getSilexApplication()['gist'];
|
||||
$gists = $gistService->getGists();
|
||||
|
||||
$languages = [];
|
||||
$withEncryption = [];
|
||||
$commits = [];
|
||||
$total = 0;
|
||||
|
||||
foreach ($gists as $gist) {
|
||||
$total++;
|
||||
|
||||
if (!array_key_exists($gist->getType(), $languages)) {
|
||||
$languages[$gist->getType()] = 0;
|
||||
$withEncryption[$gist->getType()] = 0;
|
||||
$commits[$gist->getType()] = 0;
|
||||
}
|
||||
|
||||
if ($gist->getCipher()) {
|
||||
$withEncryption[$gist->getType()]++;
|
||||
}
|
||||
|
||||
$languages[$gist->getType()]++;
|
||||
try {
|
||||
$count = count($gistService->getHistory($gist));
|
||||
$commits[$gist->getType()] += $count;
|
||||
} catch(GitException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$output->writeln(['<comment>Gists statistics</comment>', '']);
|
||||
|
||||
$table = new Table($output);
|
||||
$table
|
||||
->setHeaders(array('With encryption', 'Without encryption', 'Commits', 'Total'))
|
||||
->setRows(array(
|
||||
array(
|
||||
$total - $v = array_sum($withEncryption),
|
||||
$v,
|
||||
array_sum($commits),
|
||||
$total
|
||||
),
|
||||
))
|
||||
;
|
||||
$table->render();
|
||||
|
||||
ksort($languages);
|
||||
ksort($withEncryption);
|
||||
ksort($commits);
|
||||
|
||||
$output->writeln(['', '<comment>Details by type</comment>', '']);
|
||||
|
||||
$table->setHeaders(array(
|
||||
'Type',
|
||||
'With encryption',
|
||||
'Without encryption',
|
||||
'Commits',
|
||||
'Total',
|
||||
));
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($languages as $lang => $total) {
|
||||
$totalWithoutEncyption = $total - $withEncryption[$lang];
|
||||
$totalWithEncryption = $total - $totalWithoutEncyption;
|
||||
|
||||
$rows[] = array(
|
||||
$lang,
|
||||
$totalWithEncryption,
|
||||
$totalWithoutEncyption,
|
||||
$commits[$lang],
|
||||
$total,
|
||||
);
|
||||
}
|
||||
|
||||
$table->setRows($rows);
|
||||
$table->render();
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ use GitWrapper\GitWorkingCopy;
|
|||
use GitWrapper\GitWrapper;
|
||||
use GitWrapper\GitCommand;
|
||||
use GeSHi;
|
||||
use Gist\Model\GistQuery;
|
||||
|
||||
/**
|
||||
* Class GistService
|
||||
|
@ -30,6 +31,11 @@ class GistService
|
|||
$this->geshi = $geshi;
|
||||
}
|
||||
|
||||
public function getGists()
|
||||
{
|
||||
return GistQuery::create()->find();
|
||||
}
|
||||
|
||||
public function getHistory(Gist $gist)
|
||||
{
|
||||
$command = GitCommand::getInstance('log', '--format=medium', $gist->getFile());
|
||||
|
|
Loading…
Reference in New Issue