/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $experiments = Experiment::active()->get();
     $goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray());
     $columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
     $writer = new Writer(new SplTempFileObject());
     $writer->insertOne($columns);
     foreach ($experiments as $experiment) {
         $engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
         $row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
         $results = $experiment->goals()->lists('count', 'name');
         foreach ($goals as $column) {
             $count = array_get($results, $column, 0);
             $percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
             $row[] = number_format($percentage, 2) . " % ({$count})";
         }
         $writer->insertOne($row);
     }
     $output = (string) $writer;
     if ($file = $this->argument('file')) {
         $this->info("Creating {$file}");
         File::put($file, $output);
     } else {
         $this->line($output);
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $experiments = Experiment::active()->get();
     $goals = array_unique(Goal::active()->orderBy('name')->lists('name')->toArray());
     $columns = array_merge(['Experiment', 'Visitors', 'Engagement'], array_map('ucfirst', $goals));
     $table = new Table($this->output);
     $table->setHeaders($columns);
     foreach ($experiments as $experiment) {
         $engagement = $experiment->visitors ? $experiment->engagement / $experiment->visitors * 100 : 0;
         $row = [$experiment->name, $experiment->visitors, number_format($engagement, 2) . " % (" . $experiment->engagement . ")"];
         $results = $experiment->goals()->lists('count', 'name');
         foreach ($goals as $column) {
             $count = array_get($results, $column, 0);
             $percentage = $experiment->visitors ? $count / $experiment->visitors * 100 : 0;
             $row[] = number_format($percentage, 2) . " % ({$count})";
         }
         $table->addRow($row);
     }
     $table->render();
 }