コード例 #1
0
ファイル: ListCommand.php プロジェクト: errogaht/pabtest2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $conn = DB::getConn();
     $data = $conn->fetchAll('SELECT * FROM variants');
     if (!empty($data)) {
         $result = [];
         foreach ($data as $row) {
             $result[$row['test_name']]['test_name'] = $row['test_name'];
             $result[$row['test_name']]['shows'] = 0;
             $result[$row['test_name']]['goals'] = 0;
         }
         foreach ($data as $row) {
             $result[$row['test_name']]['shows'] += $row['shows'];
             $result[$row['test_name']]['goals'] += $row['goals'];
         }
         foreach ($data as $row) {
             $result[$row['test_name']]['conversion'] = $row['goals'] / $row['shows'] * 100 . " %";
         }
         $table = new Table($output);
         $table->setHeaders(['Test name', 'Totals shows', 'Totals goals', 'Total conversion'])->setRows($result);
         $table->render();
     } else {
         $output->writeln('<error>Test list is empty</error>');
     }
 }
コード例 #2
0
ファイル: ResultCommand.php プロジェクト: errogaht/pabtest2
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('name');
     $conn = DB::getConn();
     $data = $conn->fetchAll('SELECT * FROM variants WHERE test_name = ?', [$name]);
     if (!empty($data)) {
         $result = [];
         foreach ($data as $row) {
             $result[$row['variant']]['variant'] = $row['variant'];
             $result[$row['variant']]['shows'] = $row['shows'];
             $result[$row['variant']]['goals'] = $row['goals'];
             $result[$row['variant']]['conversion'] = $row['goals'] / $row['shows'] * 100 . ' %';
         }
         $table = new Table($output);
         $table->setHeaders([[new TableCell('A\\B test results for "' . $name . '"', ['colspan' => 4])], ['Variant name', 'Shows', 'Goals', 'Conversion']])->setRows($result);
         $table->render();
     } else {
         $output->writeln('<error>Test with name "' . $name . '" not found</error>');
     }
 }
コード例 #3
0
ファイル: pabtest.php プロジェクト: errogaht/pabtest2
#!/usr/bin/env php
<?php 
/**
 * Created by PhpStorm.
 * User: Alexey Teterin
 * Email: 7018407@gmail.com
 * Date: 23.12.2015
 * Time: 8:20
 */
use errogaht\PABTest2\Console\ListCommand;
use errogaht\PABTest2\Console\ResultCommand;
use errogaht\PABTest2\DB;
use errogaht\PABTest2\PABTest2;
use Symfony\Component\Console\Application;
$files = array(__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php');
$loader = null;
foreach ($files as $file) {
    if (file_exists($file)) {
        $loader = (require $file);
        break;
    }
}
if (!$loader) {
    throw new RuntimeException('vendor/autoload.php could not be found. Did you run `php composer.phar install`?');
}
$config = (require_once __DIR__ . '/../config.php');
DB::setConfig($config['db'] ?: '');
$application = new Application();
$application->add(new ListCommand());
$application->add(new ResultCommand());
$application->run();