コード例 #1
0
ファイル: PHP_Related.test.php プロジェクト: nnnnathann/piwik
 function _test_hashStringToInt()
 {
     $tests = array(1 => 10000, 200000 => 300000, 100000001 => 100100001, 200000001 => 200211111, 'inv' => 10000, 'INV-' => 10000);
     $alreadyHashed = array();
     $c = 0;
     $collisions = 0;
     foreach ($tests as $start => $finish) {
         $prefix = false;
         if (is_string($start)) {
             $prefix = $start;
             $start = 0;
         }
         for ($i = $start; $i < $finish; $i++) {
             $value = $i;
             if (!empty($prefix)) {
                 $value = $prefix . $value;
             }
             $hash = Piwik_Common::hashStringToInt($value);
             if (isset($alreadyHashed[$hash])) {
                 $collisions++;
                 $diff = $value - $alreadyHashed[$hash];
                 $this->fail("Hash of {$value} is the same as hash of " . $alreadyHashed[$hash] . " DIFF WAS " . $diff);
             }
             $alreadyHashed[$hash] = $value;
             $c++;
         }
     }
     //		$interval = PHP_INT_MAX  / 50;
     //		foreach($alreadyHashed as $hash => $value)
     //		{
     //			$hash %
     //		}
     echo "Collision = {$collisions} - Total hashed = {$c} - Collision rate = " . round(100 * $collisions / $c, 5) . "%";
     $this->pass();
 }
コード例 #2
0
ファイル: GoalManager.php プロジェクト: nomoto-ubicast/piwik
 /**
  * Records an Ecommerce conversion in the DB. Deals with Items found in the request.
  * Will deal with 2 types of conversions: Ecommerce Order and Ecommerce Cart update (Add to cart, Update Cart etc).
  * 
  * @param array $goal
  * @param array $visitorInformation
  */
 protected function recordEcommerceGoal($goal, $visitorInformation)
 {
     // Is the transaction a Cart Update or an Ecommerce order?
     $updateWhere = array('idvisit' => $visitorInformation['idvisit'], 'idgoal' => self::IDGOAL_CART, 'buster' => 0);
     if ($this->isThereExistingCartInVisit) {
         printDebug("There is an existing cart for this visit");
     }
     if ($this->isGoalAnOrder) {
         $orderIdNumeric = Piwik_Common::hashStringToInt($this->orderId);
         $goal['idgoal'] = self::IDGOAL_ORDER;
         $goal['idorder'] = $this->orderId;
         $goal['buster'] = $orderIdNumeric;
         $goal['revenue_subtotal'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_st', false, 'float', $this->request));
         $goal['revenue_tax'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_tx', false, 'float', $this->request));
         $goal['revenue_shipping'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_sh', false, 'float', $this->request));
         $goal['revenue_discount'] = $this->getRevenue(Piwik_Common::getRequestVar('ec_dt', false, 'float', $this->request));
         $debugMessage = 'The conversion is an Ecommerce order';
     } else {
         $goal['buster'] = 0;
         $goal['idgoal'] = self::IDGOAL_CART;
         $debugMessage = 'The conversion is an Ecommerce Cart Update';
     }
     $goal['revenue'] = $this->getRevenue(Piwik_Common::getRequestVar('revenue', 0, 'float', $this->request));
     printDebug($debugMessage . ':' . var_export($goal, true));
     // INSERT or Sync items in the Cart / Order for this visit & order
     $items = $this->getEcommerceItemsFromRequest();
     if ($items === false) {
         return;
     }
     $itemsCount = 0;
     foreach ($items as $item) {
         $itemsCount += $item[self::INTERNAL_ITEM_QUANTITY];
     }
     $goal['items'] = $itemsCount;
     // If there is already a cart for this visit
     // 1) If conversion is Order, we update the cart into an Order
     // 2) If conversion is Cart Update, we update the cart
     $recorded = $this->recordGoal($goal, $this->isThereExistingCartInVisit, $updateWhere);
     if ($recorded) {
         $this->recordEcommerceItems($goal, $items);
     }
 }