Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.39 KB | None | 0 0
  1.         // Get the number of potentially winning campaigns         
  2.         $n = Database::getInstance()->NumRows($qr);    
  3.        
  4.         // So long as there is atleast one campaign
  5.         $winner = null;
  6.         if ($n>0)
  7.         {          
  8.  
  9.             // Get all of the winners together
  10.             $potential_winners = array();
  11.            
  12.             while($row = Database::getInstance()->FetchAssoc($qr))
  13.                 if($row['id'])
  14.                     $potential_winners[$row['id']] = $row;
  15.  
  16.             Log::o("<br/><br/>");
  17.             Log::o("POTENTIAL WINNERS: ".print_r($potential_winners,true));    
  18.             Log::o("<br/><br/>");
  19.  
  20.             $last_id = NULL;
  21.  
  22.             // Reduce all max cpcs as far as they can go
  23.             foreach($potential_winners as $id => $winner)
  24.             {
  25.  
  26.                 if($last_id == NULL || $last_id == 20)
  27.                     $winner['cost'] = 0.01;
  28.                 else
  29.                 {
  30.  
  31.                     $winner['cost'] = $potential_winners[$last_id]['max_cpc'] + 0.01;
  32.  
  33.                     if($id != 20 && $potential_winners[$last_id]['max_cpc'] == $winner['max_cpc'])
  34.                         if(strtotime($winner['date_updated']) < strtotime($potential_winners[$last_id]['date_updated']))
  35.                             $winner['cost'] = $winner['max_cpc'];
  36.  
  37.                 }
  38.  
  39.                 $potential_winners[$id] = $winner;
  40.  
  41.                 $last_id = $id;
  42.  
  43.             }
  44.  
  45.             $potential_winners = array_reverse($potential_winners, True);
  46.  
  47.             Log::o("<br/><br/>");
  48.             Log::o("POTENTIAL WINNERS POST CALCULATIONS: ".print_r($potential_winners,true));      
  49.             Log::o("<br/><br/>");
  50.  
  51.             // An equation sent down by god himelf to grace the face of the earth
  52.             // with its holy goodness. Well actually its was designed by antonia mey
  53.             // and its a linear selection method based on position ranked by max cpc               
  54.             //$linVal = 100/((($n+1)*$n)/2);
  55.            
  56.             // Quadratic modification by Steve O'Boyle
  57.             $quadVal = 100/(($n*($n+1)*(2*$n+1))/6);
  58.            
  59.             // Some vars
  60.             $count = $n;
  61.             $percentage  = 0;              
  62.             $winner = false;
  63.             $cost = 0.01;
  64.             $lastWinner=false;
  65.            
  66.             // Roll the magic dice
  67.             $roll = rand(0,100);               
  68.            
  69.             Log::o("<br/><br/>");
  70.             Log::o("roll:$roll");          
  71.             Log::o("<br/><br/>");
  72.            
  73.             // Loop through all the potential candidates
  74.  
  75.             foreach($potential_winners as $row)
  76.             {      
  77.  
  78.                 Log::o("<br /><br />".print_r($row,true));     
  79.  
  80.                 if($n > 1 && $row['domain'] == "gameschart.com")
  81.                 {
  82.                     $count--;
  83.                     continue;
  84.                 }
  85.  
  86.                 if($n == 2 || $n == 1)
  87.                     $winner = $row;
  88.  
  89.                 // Calculate a quadratic percentage
  90.                 $quad = $quadVal*$count*$count;
  91.                
  92.                 // Increment the increasing percentage
  93.                 $percentage += $quad;
  94.                
  95.                 // If this oen is the winner then happy days
  96.                 if(!$winner && $roll<$percentage)
  97.                     $winner=$row;
  98.    
  99.                 Log::oLn("ID: ".$row["id"]." Rank:$count val:$quad percentage:$percentage maxcpc:".$row["max_cpc"]);
  100.                 $count--;                      
  101.  
  102.             }  
  103.  
  104.             if($winner === False)
  105.                 $winner = reset($potential_winners);
  106.  
  107.            
  108.             Log::o("<br/><br/>");
  109.            
  110.             Log::o("THE WINNER: ".print_r($winner,true));      
  111.         }
  112.  
  113.         // Gameschart should pay nothing
  114.         if($winner['id'] == 20)
  115.             $winner['cost'] = 0.0;
  116.  
  117.         // Get the real path and domain
  118.         $sql = "SELECT game_location FROM users_portalsgames WHERE
  119.             portal_id = ".$winner['portal_id']." AND game_id = ".$game['id']."
  120.             AND NOT (
  121.                 game_location LIKE '/game/verify/id%' AND
  122.                 portal_id = 4
  123.             )
  124.             AND NOT LOWER(game_location) LIKE '%.swf'
  125.             ORDER BY num_plays DESC LIMIT 1";
  126.  
  127.         $qr = Database::getInstance()->Query($sql);
  128.         $row=Database::getInstance()->FetchAssoc($qr);
  129.  
  130.         $winner['game_location'] = $row['game_location'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement