コード例 #1
0
 public function sendTestImpressions($keyImpressionsPerTest)
 {
     $impressionKeys = Di::getCache()->getKeys(ImpressionCache::getCacheKeySearchPattern());
     $impressionCache = new ImpressionCache();
     $toDrop = array();
     $dataset = array();
     $totalImpressions = 0;
     foreach ($impressionKeys as $key) {
         $featureName = ImpressionCache::getFeatureNameFromKey($key);
         $cachedImpressions = $impressionCache->getRandomImpressions($key, $keyImpressionsPerTest);
         if (empty($cachedImpressions)) {
             continue;
         }
         $toDrop[$key] = $cachedImpressions;
         $impressions = array();
         $cachedImpressionsCount = count($cachedImpressions);
         $totalImpressions += $cachedImpressionsCount;
         for ($i = 0; $i < $cachedImpressionsCount; $i++) {
             //restoring cached impressions from JSON string to PHP Array.
             $impressions[$i] = json_decode($cachedImpressions[$i], true);
         }
         //Bulk data set
         $dataset[] = array('testName' => $featureName, 'keyImpressions' => $impressions);
     }
     //Sending Impressions dataset.
     $response = $this->post($this->servicePath, $dataset);
     //Dropping impressions
     $this->dropDataset($toDrop);
     if ($response->isSuccessful()) {
         Di::getLogger()->info($totalImpressions . " Impressions sent successfuly");
         return true;
     }
     return false;
 }