mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
unify bonus calculation
This commit is contained in:
@@ -126,11 +126,10 @@ class Test extends Command
|
|||||||
// $r = $rep->getContinuousDays($attendance);
|
// $r = $rep->getContinuousDays($attendance);
|
||||||
// $r = $rep->getContinuousPoints(11);
|
// $r = $rep->getContinuousPoints(11);
|
||||||
|
|
||||||
$data = DB::select('SHOW INDEX FROM peers');
|
$rep = new ExamRepository();
|
||||||
$array = [];
|
$exam = Exam::query()->find(6);
|
||||||
foreach($data as $key => $item){
|
$r = $rep->fetchUserAndDoAssign($exam);
|
||||||
dump($item);
|
dd($r);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -778,7 +778,7 @@ class ExamRepository extends BaseRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fetchUserAndDoAssign(Exam $exam): bool|int
|
public function fetchUserAndDoAssign(Exam $exam): bool|int
|
||||||
{
|
{
|
||||||
$filters = $exam->filters;
|
$filters = $exam->filters;
|
||||||
do_log("exam: {$exam->id}, filters: " . nexus_json_encode($filters));
|
do_log("exam: {$exam->id}, filters: " . nexus_json_encode($filters));
|
||||||
@@ -800,10 +800,16 @@ class ExamRepository extends BaseRepository
|
|||||||
if (!empty($filters->$filter) && count($filters->$filter) == 1) {
|
if (!empty($filters->$filter) && count($filters->$filter) == 1) {
|
||||||
$donateStatus = $filters->$filter[0];
|
$donateStatus = $filters->$filter[0];
|
||||||
if ($donateStatus == User::DONATE_YES) {
|
if ($donateStatus == User::DONATE_YES) {
|
||||||
$baseQuery->where('donor', 'yes')->where("$userTable.donoruntil", ">=", Carbon::now()->toDateTimeString());
|
$baseQuery->where(function (Builder $query) {
|
||||||
|
$query->where('donor', 'yes')->where(function (Builder $query) {
|
||||||
|
$query->where('donoruntil', '0000-00-00 00:00:00')->orWhereNull('donoruntil')->orWhere('donoruntil', '>=', Carbon::now());
|
||||||
|
});
|
||||||
|
});
|
||||||
} elseif ($donateStatus == User::DONATE_NO) {
|
} elseif ($donateStatus == User::DONATE_NO) {
|
||||||
$baseQuery->where(function (Builder $query) use ($userTable) {
|
$baseQuery->where(function (Builder $query) {
|
||||||
$query->where('donor', 'no')->orWhereNull("$userTable.donoruntil")->orWhere("$userTable.donoruntil", '<', Carbon::now()->toDateTimeString());
|
$query->where('donor', 'no')->orWhere(function (Builder $query) {
|
||||||
|
$query->where('donoruntil', '!=','0000-00-00 00:00:00')->whereNotNull('donoruntil')->where('donoruntil', '<', Carbon::now());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
do_log("{$exam->id} filter $filter: $donateStatus invalid.", "error");
|
do_log("{$exam->id} filter $filter: $donateStatus invalid.", "error");
|
||||||
|
|||||||
+52
-46
@@ -264,41 +264,42 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
$res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
|
$res = sql_query("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'") or sqlerr(__FILE__, __LINE__);
|
||||||
if (mysql_num_rows($res) > 0)
|
if (mysql_num_rows($res) > 0)
|
||||||
{
|
{
|
||||||
$sqrtof2 = sqrt(2);
|
// $sqrtof2 = sqrt(2);
|
||||||
$logofpointone = log(0.1);
|
// $logofpointone = log(0.1);
|
||||||
$valueone = $logofpointone / $tzero_bonus;
|
// $valueone = $logofpointone / $tzero_bonus;
|
||||||
$pi = 3.141592653589793;
|
// $pi = 3.141592653589793;
|
||||||
$valuetwo = $bzero_bonus * ( 2 / $pi);
|
// $valuetwo = $bzero_bonus * ( 2 / $pi);
|
||||||
$valuethree = $logofpointone / ($nzero_bonus - 1);
|
// $valuethree = $logofpointone / ($nzero_bonus - 1);
|
||||||
$timenow = TIMENOW;
|
// $timenow = TIMENOW;
|
||||||
$sectoweek = 7*24*60*60;
|
// $sectoweek = 7*24*60*60;
|
||||||
$examRep = new \App\Repositories\ExamRepository();
|
|
||||||
while ($arr = mysql_fetch_assoc($res)) //loop for different users
|
while ($arr = mysql_fetch_assoc($res)) //loop for different users
|
||||||
{
|
{
|
||||||
$A = 0;
|
// $A = 0;
|
||||||
$count = 0;
|
// $count = 0;
|
||||||
$all_bonus = 0;
|
// $all_bonus = 0;
|
||||||
$torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = {$arr['userid']} AND peers.seeder ='yes'") or sqlerr(__FILE__, __LINE__);
|
// $torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = {$arr['userid']} AND peers.seeder ='yes' group by torrents.id") or sqlerr(__FILE__, __LINE__);
|
||||||
while ($torrent = mysql_fetch_array($torrentres))
|
// while ($torrent = mysql_fetch_array($torrentres))
|
||||||
{
|
// {
|
||||||
$weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
|
// $weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
|
||||||
$gb_size = $torrent['size'] / 1073741824;
|
// $gb_size = $torrent['size'] / 1073741824;
|
||||||
$temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
|
// $temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
|
||||||
$A += $temp;
|
// $A += $temp;
|
||||||
$count++;
|
// $count++;
|
||||||
}
|
// }
|
||||||
if ($count > $maxseeding_bonus)
|
// if ($count > $maxseeding_bonus)
|
||||||
$count = $maxseeding_bonus;
|
// $count = $maxseeding_bonus;
|
||||||
$all_bonus = $seedPoints = ($valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count)) / (3600 / $autoclean_interval_one);
|
// $all_bonus = $seedPoints = ($valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count)) / (3600 / $autoclean_interval_one);
|
||||||
$is_donor = get_single_value("users","donor","WHERE id=".$arr['userid']);
|
// $is_donor = get_single_value("users","donor","WHERE id=".$arr['userid']);
|
||||||
$log = "[UPDATE_BONUS], user: {$arr['userid']}, original bonus: $all_bonus, is_donor: $is_donor, donortimes_bonus: $donortimes_bonus";
|
// $log = "[UPDATE_BONUS], user: {$arr['userid']}, original bonus: $all_bonus, is_donor: $is_donor, donortimes_bonus: $donortimes_bonus";
|
||||||
if ($is_donor == 'yes' && $donortimes_bonus > 0) {
|
// if ($is_donor == 'yes' && $donortimes_bonus > 0) {
|
||||||
$all_bonus = $all_bonus * $donortimes_bonus;
|
// $all_bonus = $all_bonus * $donortimes_bonus;
|
||||||
$log .= ", do multiple, all_bonus: $all_bonus";
|
// $log .= ", do multiple, all_bonus: $all_bonus";
|
||||||
}
|
// }
|
||||||
do_log($log);
|
// do_log($log);
|
||||||
KPS("+",$all_bonus,$arr["userid"]);
|
$seedBonusResult = calculate_seed_bonus($arr['userid']);
|
||||||
sql_query("update users set seed_points = ifnull(seed_points, 0) + $seedPoints where id = {$arr["userid"]}");
|
$all_bonus = $seedBonusResult['all_bonus'];
|
||||||
|
$seed_points = $seedBonusResult['seed_points'];
|
||||||
|
sql_query("update users set seed_points = ifnull(seed_points, 0) + $seed_points, seedbonus = seedbonus + $all_bonus where id = {$arr["userid"]}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$log = 'calculate seeding bonus';
|
$log = 'calculate seeding bonus';
|
||||||
@@ -316,7 +317,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
do_log($log);
|
do_log($log);
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
$ts = $row[0];
|
$ts = $row[0] ?? 0;
|
||||||
if ($ts + $autoclean_interval_two > $now && !$forceAll) {
|
if ($ts + $autoclean_interval_two > $now && !$forceAll) {
|
||||||
$log = 'Cleanup ends at Priority Class 1';
|
$log = 'Cleanup ends at Priority Class 1';
|
||||||
do_log($log . ", $ts + $autoclean_interval_two > $now");
|
do_log($log . ", $ts + $autoclean_interval_two > $now");
|
||||||
@@ -342,7 +343,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
do_log($log);
|
do_log($log);
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
$ts = $row[0];
|
$ts = $row[0] ?? 0;
|
||||||
if ($ts + $autoclean_interval_three > $now && !$forceAll) {
|
if ($ts + $autoclean_interval_three > $now && !$forceAll) {
|
||||||
$log = 'Cleanup ends at Priority Class 2';
|
$log = 'Cleanup ends at Priority Class 2';
|
||||||
do_log($log . ", $ts + $autoclean_interval_three > $now");
|
do_log($log . ", $ts + $autoclean_interval_three > $now");
|
||||||
@@ -353,21 +354,26 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
|
|
||||||
//4.update count of seeders, leechers, comments for torrents
|
//4.update count of seeders, leechers, comments for torrents
|
||||||
$torrents = array();
|
$torrents = array();
|
||||||
$res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
|
/**
|
||||||
while ($row = mysql_fetch_assoc($res)) {
|
* move to announce request to do this
|
||||||
if ($row["seeder"] == "yes")
|
* @since 1.7.4
|
||||||
$key = "seeders";
|
*/
|
||||||
else
|
// $res = sql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder") or sqlerr(__FILE__, __LINE__);
|
||||||
$key = "leechers";
|
// while ($row = mysql_fetch_assoc($res)) {
|
||||||
$torrents[$row["torrent"]][$key] = $row["c"];
|
// if ($row["seeder"] == "yes")
|
||||||
}
|
// $key = "seeders";
|
||||||
|
// else
|
||||||
|
// $key = "leechers";
|
||||||
|
// $torrents[$row["torrent"]][$key] = $row["c"];
|
||||||
|
// }
|
||||||
|
|
||||||
$res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
$res = sql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent") or sqlerr(__FILE__, __LINE__);
|
||||||
while ($row = mysql_fetch_assoc($res)) {
|
while ($row = mysql_fetch_assoc($res)) {
|
||||||
$torrents[$row["torrent"]]["comments"] = $row["c"];
|
$torrents[$row["torrent"]]["comments"] = $row["c"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = explode(":", "comments:leechers:seeders");
|
// $fields = explode(":", "comments:leechers:seeders");
|
||||||
|
$fields = explode(":", "comments");
|
||||||
$res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
|
$res = sql_query("SELECT id, seeders, leechers, comments FROM torrents") or sqlerr(__FILE__, __LINE__);
|
||||||
while ($row = mysql_fetch_assoc($res)) {
|
while ($row = mysql_fetch_assoc($res)) {
|
||||||
$id = $row["id"];
|
$id = $row["id"];
|
||||||
@@ -502,7 +508,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
do_log($log);
|
do_log($log);
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
$ts = $row[0];
|
$ts = $row[0] ?? 0;
|
||||||
if ($ts + $autoclean_interval_four > $now && !$forceAll) {
|
if ($ts + $autoclean_interval_four > $now && !$forceAll) {
|
||||||
$log = 'Cleanup ends at Priority Class 3';
|
$log = 'Cleanup ends at Priority Class 3';
|
||||||
do_log($log . ", $ts + $autoclean_interval_four > $now");
|
do_log($log . ", $ts + $autoclean_interval_four > $now");
|
||||||
@@ -830,7 +836,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
do_log($log);
|
do_log($log);
|
||||||
return $log;
|
return $log;
|
||||||
}
|
}
|
||||||
$ts = $row[0];
|
$ts = $row[0] ?? 0;
|
||||||
if ($ts + $autoclean_interval_five > $now && !$forceAll) {
|
if ($ts + $autoclean_interval_five > $now && !$forceAll) {
|
||||||
$log = 'Cleanup ends at Priority Class 4';
|
$log = 'Cleanup ends at Priority Class 4';
|
||||||
do_log($log . ", $ts + $autoclean_interval_five > $now");
|
do_log($log . ", $ts + $autoclean_interval_five > $now");
|
||||||
|
|||||||
@@ -5500,4 +5500,48 @@ function get_smile($num)
|
|||||||
return $all[$num] ?? null;
|
return $all[$num] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function calculate_seed_bonus($uid): array
|
||||||
|
{
|
||||||
|
global $autoclean_interval_one;
|
||||||
|
global $donortimes_bonus, $perseeding_bonus, $maxseeding_bonus, $tzero_bonus, $nzero_bonus, $bzero_bonus, $l_bonus;
|
||||||
|
|
||||||
|
$sqrtof2 = sqrt(2);
|
||||||
|
$logofpointone = log(0.1);
|
||||||
|
$valueone = $logofpointone / $tzero_bonus;
|
||||||
|
$pi = 3.141592653589793;
|
||||||
|
$valuetwo = $bzero_bonus * ( 2 / $pi);
|
||||||
|
$valuethree = $logofpointone / ($nzero_bonus - 1);
|
||||||
|
$timenow = TIMENOW;
|
||||||
|
$sectoweek = 7*24*60*60;
|
||||||
|
|
||||||
|
$A = 0;
|
||||||
|
$count = $torrent_count = 0;
|
||||||
|
|
||||||
|
$torrentres = sql_query("select torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $uid AND peers.seeder ='yes' group by torrents.id");
|
||||||
|
while ($torrent = mysql_fetch_array($torrentres))
|
||||||
|
{
|
||||||
|
$weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
|
||||||
|
$gb_size = $torrent['size'] / 1073741824;
|
||||||
|
$temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
|
||||||
|
$A += $temp;
|
||||||
|
$count++;
|
||||||
|
$torrent_count++;
|
||||||
|
}
|
||||||
|
if ($count > $maxseeding_bonus)
|
||||||
|
$count = $maxseeding_bonus;
|
||||||
|
$all_bonus = $seed_bonus = $seed_points = ($valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count)) / (3600 / $autoclean_interval_one);
|
||||||
|
$is_donor_info = \Nexus\Database\NexusDB::getOne('users', "id = $uid", "donor, donoruntil");
|
||||||
|
$is_donor_until = $is_donor_info['donoruntil'];
|
||||||
|
$is_donor = $is_donor_info['donor'] == 'yes' && ($is_donor_until === null || $is_donor_until == '0000-00-00 00:00:00' || $is_donor_until >= date('Y-m-d H:i:s'));
|
||||||
|
$is_donor = intval($is_donor);
|
||||||
|
$log = "[CALCULATE_SEED_BONUS], user: $uid, original bonus: $all_bonus, is_donor: $is_donor, donortimes_bonus: $donortimes_bonus";
|
||||||
|
if ($is_donor && $donortimes_bonus > 0) {
|
||||||
|
$all_bonus = $all_bonus * $donortimes_bonus;
|
||||||
|
$log .= ", do multiple, all_bonus: $all_bonus";
|
||||||
|
}
|
||||||
|
$result = compact('seed_points','seed_bonus', 'all_bonus', 'A', 'count', 'torrent_count');
|
||||||
|
do_log("$log, result: " . json_encode($result));
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -511,6 +511,11 @@ else
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($event) && !empty($event)) {
|
||||||
|
$updateset[] = 'seeders = ' . count_peer("torrent = $torrentid and to_go = 0");
|
||||||
|
$updateset[] = 'leechers = ' . count_peer("torrent = $torrentid and to_go > 0");
|
||||||
|
}
|
||||||
|
|
||||||
if (count($updateset)) // Update only when there is change in peer counts
|
if (count($updateset)) // Update only when there is change in peer counts
|
||||||
{
|
{
|
||||||
$updateset[] = "visible = 'yes'";
|
$updateset[] = "visible = 'yes'";
|
||||||
|
|||||||
+27
-22
@@ -393,28 +393,33 @@ if ($donortimes_bonus)
|
|||||||
print("<li>".$lang_mybonus['text_donors_always_get'].$donortimes_bonus.$lang_mybonus['text_times_of_bonus']."</li>");
|
print("<li>".$lang_mybonus['text_donors_always_get'].$donortimes_bonus.$lang_mybonus['text_times_of_bonus']."</li>");
|
||||||
print("</ul>");
|
print("</ul>");
|
||||||
|
|
||||||
$sqrtof2 = sqrt(2);
|
// $sqrtof2 = sqrt(2);
|
||||||
$logofpointone = log(0.1);
|
// $logofpointone = log(0.1);
|
||||||
$valueone = $logofpointone / $tzero_bonus;
|
// $valueone = $logofpointone / $tzero_bonus;
|
||||||
$pi = 3.141592653589793;
|
// $pi = 3.141592653589793;
|
||||||
$valuetwo = $bzero_bonus * ( 2 / $pi);
|
// $valuetwo = $bzero_bonus * ( 2 / $pi);
|
||||||
$valuethree = $logofpointone / ($nzero_bonus - 1);
|
// $valuethree = $logofpointone / ($nzero_bonus - 1);
|
||||||
$timenow = strtotime(date("Y-m-d H:i:s"));
|
// $timenow = strtotime(date("Y-m-d H:i:s"));
|
||||||
$sectoweek = 7*24*60*60;
|
// $sectoweek = 7*24*60*60;
|
||||||
$A = 0;
|
// $A = 0;
|
||||||
$count = 0;
|
// $count = 0;
|
||||||
$torrentres = sql_query("select torrents.id, torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $CURUSER[id] AND peers.seeder ='yes' GROUP BY torrents.id") or sqlerr(__FILE__, __LINE__);
|
// $torrentres = sql_query("select torrents.id, torrents.added, torrents.size, torrents.seeders from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid = $CURUSER[id] AND peers.seeder ='yes' GROUP BY torrents.id") or sqlerr(__FILE__, __LINE__);
|
||||||
while ($torrent = mysql_fetch_array($torrentres))
|
// while ($torrent = mysql_fetch_array($torrentres))
|
||||||
{
|
// {
|
||||||
$weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
|
// $weeks_alive = ($timenow - strtotime($torrent['added'])) / $sectoweek;
|
||||||
$gb_size = $torrent['size'] / 1073741824;
|
// $gb_size = $torrent['size'] / 1073741824;
|
||||||
$temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
|
// $temp = (1 - exp($valueone * $weeks_alive)) * $gb_size * (1 + $sqrtof2 * exp($valuethree * ($torrent['seeders'] - 1)));
|
||||||
$A += $temp;
|
// $A += $temp;
|
||||||
$count++;
|
// $count++;
|
||||||
}
|
// }
|
||||||
if ($count > $maxseeding_bonus)
|
// if ($count > $maxseeding_bonus)
|
||||||
$count = $maxseeding_bonus;
|
// $count = $maxseeding_bonus;
|
||||||
$all_bonus = $valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count);
|
// $all_bonus = $valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count);
|
||||||
|
|
||||||
|
$seedBonusResult = calculate_seed_bonus($CURUSER['id']);
|
||||||
|
$all_bonus = $seedBonusResult['all_bonus'];
|
||||||
|
$A = $seedBonusResult['A'];
|
||||||
|
|
||||||
$percent = $all_bonus * 100 / ($bzero_bonus + $perseeding_bonus * $maxseeding_bonus);
|
$percent = $all_bonus * 100 / ($bzero_bonus + $perseeding_bonus * $maxseeding_bonus);
|
||||||
print("<div align=\"center\">".$lang_mybonus['text_you_are_currently_getting'].round($all_bonus,3).$lang_mybonus['text_point'].add_s($all_bonus).$lang_mybonus['text_per_hour']." (A = ".round($A,1).")</div><table align=\"center\" border=\"0\" width=\"400\"><tr><td class=\"loadbarbg\" style='border: none; padding: 0px;'>");
|
print("<div align=\"center\">".$lang_mybonus['text_you_are_currently_getting'].round($all_bonus,3).$lang_mybonus['text_point'].add_s($all_bonus).$lang_mybonus['text_per_hour']." (A = ".round($A,1).")</div><table align=\"center\" border=\"0\" width=\"400\"><tr><td class=\"loadbarbg\" style='border: none; padding: 0px;'>");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user