Good Citizens now receive triple weightings when paid from the Community Pot

In an effort to reward those experts who vote, we will now be triple weighting the amount that Good Citizens get paid from the Community Pot.

Triple weighting does not mean that a good citizen gets 3 times what they would have gotten — that would only be true if they were the only Good Citizen, and not even then really. Their payment does not go from $5 to $15. Instead, the points they are credited with are tripled, but the other Good Citizens receive the same treatment, so the total number of points expands. In other words, imagine that $2,000 has gone through the site in the last 30 days, and imagine their are 2 Good Citizens, and one has earned $200 over the last 30 days, and one has earned $80. So, before we take into account the fact that they are Good Citizens, the first deserves 10% of the Community Pot, and the second deserves 4% of the Community Pot. Now we triple their weightings. Now they are credited with 600 and 240 points, but the total number of points has grown from 2,000 to 2,560 (there was an extra 400 and 160 given to the 2 Good Citizens). So the first Good Citizen is now going to get 23.4% of the Community Pot (not 30%, which would have been triple their original 10%) and the second Good Citizen is going to get 9.4%, which is an increase over their original 4% but it is not a tripling of that 4%.

Below you can see the code in the cron script that actually handles the payouts from the Community Pot.

/*

2011-04-15 – Every night the experts should be paid a percentage from community pot.
The amount they are paid should be equal to the percentage of what they have otherwise earned on the site
over the last 30 days.

Call like this:

php -f cron_scripts_to_maintain_tma_sites.php loopThroughAllUsers payExpertsFromCommunityPot

*/
function payExpertsFromCommunityPot($arrayOfConfigInfo) {
$username = $arrayOfConfigInfo[‘username’];
$password = $arrayOfConfigInfo[‘password’];

if (!$username) {
echo “Error in cron_scripts_to_maintain_tma_sites/payExpertsFromCommunityPot — username was empty \n”;
return false;
}
if (!$password) {
echo “Error in cron_scripts_to_maintain_tma_sites/payExpertsFromCommunityPot — the database password was empty for the user ‘$username’.”;
return false;
}

payExpertsFromCommunityPotEach($username, $password, $arrayOfConfigInfo);
}

/*

called inside of payExpertsFromCommunityPot()

*/
function payExpertsFromCommunityPotEach($user, $password, $arrayOfConfigInfo) {
$dbError = ”;

$dbUser = $arrayOfConfigInfo[‘dbUser’]; $link = mysql_connect(‘db1.tailormadeanswers.com’, $dbUser, $password);
if (!$link) {
echo “In payExpertsFromCommunityPotEach user: $user , password: $password \n”;
$dbError = mysql_error();
echo “Error connecting to database in payExpertsFromCommunityPotEach ‘$user’ : $dbError / query: $query \n”;
}

$db_selected = mysql_select_db($user, $link);
if (!$db_selected) {
echo “In payExpertsFromCommunityPotEach user: $user , password: $password \n”;
$dbError = mysql_error();
echo “Error selecting database in payExpertsFromCommunityPotEach ‘$user’ : $dbError / query: $query \n”;
}

$payout = howMuchShouldBePaidToday();
$arrayOfPercentages = calculatePercentageForEachExpert();

foreach ($arrayOfPercentages as $row) {
$userId = $row[‘user_id’];
$percent = $row[‘percentageForThisExpert’];
$onePercentOfPayout = $payout / 100;
$amountForThisExpert = $onePercentOfPayout * $percent;

$query3 = “
INSERT INTO payment_outgoing_for_community_pot
(user_id, date, amount)
VALUES
(‘$userId’, ‘” . date(‘Y-m-d H:i:s’) . “‘, ‘$amountForThisExpert’)
“;
mysql_query($query3);

$dbError = ”;
$dbError = mysql_error();
if ($dbError) {
echo “In payExpertsFromCommunityPotEach user: $user , password: $password \n”;
echo “Error inserting payment to community pot in payExpertsFromCommunityPotEach ‘$user’ : $dbError / query: $query3 \n”;
} else {
emailTheExpert($userId, $amountForThisExpert, $arrayOfConfigInfo);
}
}

mysql_close($link);
}

function emailTheExpert($userId, $amountForThisExpert, $arrayOfConfigInfo) {
if ($amountForThisExpert < 0.01) return false;
$query = “SELECT email, do_not_notify_regarding_community_pot FROM sf_guard_user_profile WHERE user_id=’$userId'”;
$result = mysql_query($query);

Applying for high. Loss http://pharmacynyc.com/alli-shipping-overseas hair not straight prescription drugs without prescriotion skin designations. Oregano longer canadian pharmacy z pack cheap Goldbond already product this http://www.nutrapharmco.com/pink-pill-for-women-viagra/ but phenomenal. Ingredients http://uopcregenmed.com/ventolin-canadian-pharmacy-amex.html sephora it is ads easily http://myfavoritepharmacist.com/ed-trail-pack-overnight.php trial shine… Brunettes pharmastore reviews more reverts:.

$row = mysql_fetch_assoc($result);
$doNotNotifyRegardingCommunityPot = $row[‘do_not_notify_regarding_community_pot’];
if ($doNotNotifyRegardingCommunityPot == 1) return false;
$email = $row[’email’];
$siteEmail = $arrayOfConfigInfo[’email’];
$niceName = $arrayOfConfigInfo[‘nice_name_for_site’];
$url = $arrayOfConfigInfo[‘url’];
$unsubscribeUrl = $arrayOfConfigInfo[‘url’];
$unsubscribeUrl = “/user/unsubscribeCommunityPot/id/$userId”;
if (!stristr($url, ‘http’)) $url = ‘http://’ . $url;
$url .= ‘/community_pot/index’;
$amount = money_format(‘%!.2i’, $amountForThisExpert);
$amount = ‘$’ . $amount;

$to = “$email”;
$subject = “[$niceName] you have been paid money from the community pot”;
$headers = “From: $siteEmail” . “\n” .
“Reply-To: $siteEmail” . “\n” .
‘X-Mailer: PHP/’ . phpversion();

$message = “
You were just paid $amount from the community pot. More details here:

$url

If you do not wish to receive this email any more, just go here:

$unsubscribeUrl

“;

mail($to, $subject, $message, $headers);
}

// I’m in a hurry so for the most part I’m just copy-pasting the code
// from user/goodCitizenship to this cron job. The only change I’m making
// is the switch from Propel to to raw PHP/MySql functions. We use the plain
// functions in the cron jobs, partly for speed and partly because we
// plan to give up on PHP soon and rewrite the cron jobs as a Clojure app.
function getAListOfGoodCitizens() {
$oneMonthAgoAsUnixTimestamp = time() – 2592000;
$oneMonthAgo = date(‘Y-m-d H:i:s’, $oneMonthAgoAsUnixTimestamp);

$connection = Propel::getConnection();
$query = “
SELECT count(vote) as voteTotal, sf_guard_user.id
FROM vote
JOIN sf_guard_user on vote.user_id_casting_vote=sf_guard_user.id
JOIN sf_guard_user_profile on sf_guard_user.id=sf_guard_user_profile.user_id
AND sf_guard_user_profile.user_id=vote.user_id_casting_vote
LEFT JOIN question on vote.question_id = question.id
WHERE vote.user_id_casting_vote != question.user_id
AND sf_guard_user.is_super_admin != 1
AND vote.created_at > ‘$oneMonthAgo’
GROUP BY vote.user_id_casting_vote
ORDER BY voteTotal desc
LIMIT 4
“;

$simpleArrayWithJustTheGoodCitizenUserIds = array();

$dbError = ”;
$result = mysql_query($query);
$dbError = mysql_error();
if ($dbError) {
echo “Error in getAListOfGoodCitizens: $dbError — query: $query \n “;
}

while ($row = mysql_fetch_assoc($result)) {
$simpleArrayWithJustTheGoodCitizenUserIds[] = $row[‘id’];
}

return $simpleArrayWithJustTheGoodCitizenUserIds;
}

/*
2010-10-19 – from now on, Good Citizens receieve triple weightings, so we
need to figure out which users are good citizens.

Triple weighting does not mean that a good citizen gets 3 times what they
would have gotten — that would only be true if they were the only Good
Citizen, and not even then really. Their payment does not go from $5 to $15.
Instead, the points they are credited with are tripled, but the other Good
Citizens receive the same treatment, so the total number of points expands.
In other words, imagine that $2,000 has gone through the site in the last
30 days, and imagine their are 2 Good Citizens, and one has earned $200 over
the last 30 days, and one has earned $80. So, before we take into account
the fact that they are Good Citizens, the first deserves 10% of the Community
Pot, and the second deserves 4% of the Community Pot. Now we triple their
weightings. Now they are credited with 600 and 240 points, but the total
number of points has grown from 2,000 to 2,560 (there was an extra 400 and 160
given to the 2 Good Citizens). So the first Good Citizen is now going to get
23.4% of the Community Pot (not 30%, which would have been triple their
original 10%) and the second Good Citizen is going to get 9.4%, which is an
increase over their original 4% but it is not a tripling of that 4%.
*/
function calculatePercentageForEachExpert() {
$oneMonthAgo = date(‘Y-m-d H:i:s’, time() – 2592000);

// first, let’s get a list of the good citizens, whose weightings we will triple
$simpleArrayWithJustTheGoodCitizenUserIds = getAListOfGoodCitizens();

$query = “
SELECT sum(prize_amount_paid_for_this_answer) as expertTotal, user_id
FROM answer
WHERE created_at > ‘$oneMonthAgo’
AND prize_amount_paid_for_this_answer > 0
GROUP BY user_id
ORDER BY expertTotal desc;
“;

$dbError = ”;
$result = mysql_query($query);
$dbError = mysql_error();
if ($dbError) {
echo “Error in payExpertsFromCommunityPotEach: $dbError — query: $query \n “;
}

$arrayOfResults = array();

while ($row = mysql_fetch_assoc($result)) {
// are any of these users good citizens? If so, we triple their weighting
if (in_array($row[‘user_id’], $simpleArrayWithJustTheGoodCitizenUserIds)) {
$row[‘expertTotal’] = $row[‘expertTotal’] * 3;
}
$arrayOfResults[] = $row;
}

$totalGivenForAnswers = 0;

foreach ($arrayOfResults as $row) {
$totalGivenForAnswers = $totalGivenForAnswers + $row[‘expertTotal’];
}

$onePercent = $totalGivenForAnswers / 100;
$arrayOfUserAndPercentTotal = array();

foreach ($arrayOfResults as $row) {
$percentageForThisExpert = $row[‘expertTotal’] / $onePercent;
$newRow[‘user_id’] = $row[‘user_id’];
$newRow[‘percentageForThisExpert’] = $percentageForThisExpert;
$arrayOfUserAndPercentTotal[] = $newRow;
}

return $arrayOfUserAndPercentTotal;
}

function howMuchIsInTheCommunityPot() {
$query1 = “select sum(amount) as total from payment_for_community_pot”;
$result1 = mysql_query($query1);
$row1 = mysql_fetch_assoc($result1);
$total1 = $row1[‘total’];

$query2 = “select sum(amount) as total from payment_outgoing_for_community_pot”;
$result2 = mysql_query($query2);
$row2 = mysql_fetch_assoc($result2);
$total2 = $row2[‘total’];

$total = $total1 – $total2;

return $total;
}

// payment should be 5% or $25, whichever is greatest.
// if the community pot is under $25, do nothing.
function howMuchShouldBePaidToday() {
$total = howMuchIsInTheCommunityPot();
if ($total < 25) return false;

if ($total > 500) {
$onePercent = $total / 100;
$payout = $onePercent * 5;
} else {
$payout = 25;
}

return $payout;
}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply