/**
  * Persist logs to database on a defined period basis
  */
 private function persistLogs()
 {
     if (time() - $this->startTime > self::PERSISTENCE_PERIOD) {
         foreach ($this->logs as $topic => $data) {
             $log = new Log();
             $log->setTopic($topic);
             if (is_numeric($data[0])) {
                 $log->setValue(round(array_sum($data) / count($data), 2));
             } else {
                 $countValues = array_count_values($data);
                 arsort($countValues);
                 $log->setValue(key($countValues));
                 $countValues = [];
             }
             $this->getEntityManager()->persist($log);
         }
         $this->flush();
         $this->logs = [];
         $this->startTime = time();
     }
 }