Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get the number of potentially winning campaigns
- $n = Database::getInstance()->NumRows($qr);
- // So long as there is atleast one campaign
- $winner = null;
- if ($n>0)
- {
- // Get all of the winners together
- $potential_winners = array();
- while($row = Database::getInstance()->FetchAssoc($qr))
- if($row['id'])
- $potential_winners[$row['id']] = $row;
- Log::o("<br/><br/>");
- Log::o("POTENTIAL WINNERS: ".print_r($potential_winners,true));
- Log::o("<br/><br/>");
- $last_id = NULL;
- // Reduce all max cpcs as far as they can go
- foreach($potential_winners as $id => $winner)
- {
- if($last_id == NULL || $last_id == 20)
- $winner['cost'] = 0.01;
- else
- {
- $winner['cost'] = $potential_winners[$last_id]['max_cpc'] + 0.01;
- if($id != 20 && $potential_winners[$last_id]['max_cpc'] == $winner['max_cpc'])
- if(strtotime($winner['date_updated']) < strtotime($potential_winners[$last_id]['date_updated']))
- $winner['cost'] = $winner['max_cpc'];
- }
- $potential_winners[$id] = $winner;
- $last_id = $id;
- }
- $potential_winners = array_reverse($potential_winners, True);
- Log::o("<br/><br/>");
- Log::o("POTENTIAL WINNERS POST CALCULATIONS: ".print_r($potential_winners,true));
- Log::o("<br/><br/>");
- // An equation sent down by god himelf to grace the face of the earth
- // with its holy goodness. Well actually its was designed by antonia mey
- // and its a linear selection method based on position ranked by max cpc
- //$linVal = 100/((($n+1)*$n)/2);
- // Quadratic modification by Steve O'Boyle
- $quadVal = 100/(($n*($n+1)*(2*$n+1))/6);
- // Some vars
- $count = $n;
- $percentage = 0;
- $winner = false;
- $cost = 0.01;
- $lastWinner=false;
- // Roll the magic dice
- $roll = rand(0,100);
- Log::o("<br/><br/>");
- Log::o("roll:$roll");
- Log::o("<br/><br/>");
- // Loop through all the potential candidates
- foreach($potential_winners as $row)
- {
- Log::o("<br /><br />".print_r($row,true));
- if($n > 1 && $row['domain'] == "gameschart.com")
- {
- $count--;
- continue;
- }
- if($n == 2 || $n == 1)
- $winner = $row;
- // Calculate a quadratic percentage
- $quad = $quadVal*$count*$count;
- // Increment the increasing percentage
- $percentage += $quad;
- // If this oen is the winner then happy days
- if(!$winner && $roll<$percentage)
- $winner=$row;
- Log::oLn("ID: ".$row["id"]." Rank:$count val:$quad percentage:$percentage maxcpc:".$row["max_cpc"]);
- $count--;
- }
- if($winner === False)
- $winner = reset($potential_winners);
- Log::o("<br/><br/>");
- Log::o("THE WINNER: ".print_r($winner,true));
- }
- // Gameschart should pay nothing
- if($winner['id'] == 20)
- $winner['cost'] = 0.0;
- // Get the real path and domain
- $sql = "SELECT game_location FROM users_portalsgames WHERE
- portal_id = ".$winner['portal_id']." AND game_id = ".$game['id']."
- AND NOT (
- game_location LIKE '/game/verify/id%' AND
- portal_id = 4
- )
- AND NOT LOWER(game_location) LIKE '%.swf'
- ORDER BY num_plays DESC LIMIT 1";
- $qr = Database::getInstance()->Query($sql);
- $row=Database::getInstance()->FetchAssoc($qr);
- $winner['game_location'] = $row['game_location'];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement