protected function execute(InputInterface $input, OutputInterface $output)
 {
     $log_file = $input->getArgument('log_file');
     $date = $input->getArgument('date');
     $service = new Analyzer($log_file, $date);
     $results = $service->analyzeBookAccessTop20();
     $summary = [];
     foreach ($results as $date => $books) {
         if (!isset($summary[0])) {
             $summary[0] = '';
         }
         $summary[0] .= sprintf('"%s","","",', $date);
         $i = 1;
         foreach ($books as $book => $value) {
             if (!isset($summary[$i])) {
                 $summary[$i] = '';
             }
             $summary[$i] .= sprintf('"%s","%s","",', $book, $value);
             $i++;
         }
         if ($i != 21) {
             for (; $i < 21; $i++) {
                 $summary[$i] .= '"","","",';
             }
         }
     }
     foreach ($summary as $s) {
         $output->writeln($s);
     }
 }
Esempio n. 2
0
 /**
  * @test
  * @group analyze-book-access-top20
  * @group analyze
  **/
 public function ブックアクセス数Top20を分析する()
 {
     $log = ROOT . DS . 'data' . DS . 'top20.log.csv';
     $service = new Analyzer($log, '2014/01');
     $result = $service->analyzeBookAccessTop20();
     $this->assertArrayHasKey('2014年01月', $result);
     $this->assertEquals(20, count($result['2014年01月']));
 }