diff --git a/app/Console/Commands/Test.php b/app/Console/Commands/Test.php index 6d82be97..88f0462a 100644 --- a/app/Console/Commands/Test.php +++ b/app/Console/Commands/Test.php @@ -126,11 +126,10 @@ class Test extends Command // $r = $rep->getContinuousDays($attendance); // $r = $rep->getContinuousPoints(11); - $data = DB::select('SHOW INDEX FROM peers'); - $array = []; - foreach($data as $key => $item){ - dump($item); - } + $rep = new ExamRepository(); + $exam = Exam::query()->find(6); + $r = $rep->fetchUserAndDoAssign($exam); + dd($r); } diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index b3f68e99..a9624fe3 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -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; 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) { $donateStatus = $filters->$filter[0]; 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) { - $baseQuery->where(function (Builder $query) use ($userTable) { - $query->where('donor', 'no')->orWhereNull("$userTable.donoruntil")->orWhere("$userTable.donoruntil", '<', Carbon::now()->toDateTimeString()); + $baseQuery->where(function (Builder $query) { + $query->where('donor', 'no')->orWhere(function (Builder $query) { + $query->where('donoruntil', '!=','0000-00-00 00:00:00')->whereNotNull('donoruntil')->where('donoruntil', '<', Carbon::now()); + }); }); } else { do_log("{$exam->id} filter $filter: $donateStatus invalid.", "error"); diff --git a/include/cleanup.php b/include/cleanup.php index c79f171c..ebcb07ee 100644 --- a/include/cleanup.php +++ b/include/cleanup.php @@ -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__); if (mysql_num_rows($res) > 0) { - $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; - $examRep = new \App\Repositories\ExamRepository(); +// $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; while ($arr = mysql_fetch_assoc($res)) //loop for different users { - $A = 0; - $count = 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__); - 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++; - } - if ($count > $maxseeding_bonus) - $count = $maxseeding_bonus; - $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']); - $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) { - $all_bonus = $all_bonus * $donortimes_bonus; - $log .= ", do multiple, all_bonus: $all_bonus"; - } - do_log($log); - KPS("+",$all_bonus,$arr["userid"]); - sql_query("update users set seed_points = ifnull(seed_points, 0) + $seedPoints where id = {$arr["userid"]}"); +// $A = 0; +// $count = 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' group by torrents.id") or sqlerr(__FILE__, __LINE__); +// 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++; +// } +// if ($count > $maxseeding_bonus) +// $count = $maxseeding_bonus; +// $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']); +// $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) { +// $all_bonus = $all_bonus * $donortimes_bonus; +// $log .= ", do multiple, all_bonus: $all_bonus"; +// } +// do_log($log); + $seedBonusResult = calculate_seed_bonus($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'; @@ -316,7 +317,7 @@ function docleanup($forceAll = 0, $printProgress = false) { do_log($log); return $log; } - $ts = $row[0]; + $ts = $row[0] ?? 0; if ($ts + $autoclean_interval_two > $now && !$forceAll) { $log = 'Cleanup ends at Priority Class 1'; do_log($log . ", $ts + $autoclean_interval_two > $now"); @@ -342,7 +343,7 @@ function docleanup($forceAll = 0, $printProgress = false) { do_log($log); return $log; } - $ts = $row[0]; + $ts = $row[0] ?? 0; if ($ts + $autoclean_interval_three > $now && !$forceAll) { $log = 'Cleanup ends at Priority Class 2'; 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 $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)) { - if ($row["seeder"] == "yes") - $key = "seeders"; - else - $key = "leechers"; - $torrents[$row["torrent"]][$key] = $row["c"]; - } + /** + * move to announce request to do this + * @since 1.7.4 + */ +// $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)) { +// 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__); while ($row = mysql_fetch_assoc($res)) { $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__); while ($row = mysql_fetch_assoc($res)) { $id = $row["id"]; @@ -502,7 +508,7 @@ function docleanup($forceAll = 0, $printProgress = false) { do_log($log); return $log; } - $ts = $row[0]; + $ts = $row[0] ?? 0; if ($ts + $autoclean_interval_four > $now && !$forceAll) { $log = 'Cleanup ends at Priority Class 3'; do_log($log . ", $ts + $autoclean_interval_four > $now"); @@ -830,7 +836,7 @@ function docleanup($forceAll = 0, $printProgress = false) { do_log($log); return $log; } - $ts = $row[0]; + $ts = $row[0] ?? 0; if ($ts + $autoclean_interval_five > $now && !$forceAll) { $log = 'Cleanup ends at Priority Class 4'; do_log($log . ", $ts + $autoclean_interval_five > $now"); diff --git a/include/functions.php b/include/functions.php index d9dc5312..240bd282 100644 --- a/include/functions.php +++ b/include/functions.php @@ -5500,4 +5500,48 @@ function get_smile($num) 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; +} + ?> diff --git a/public/announce.php b/public/announce.php index 8d4b6b18..13812478 100644 --- a/public/announce.php +++ b/public/announce.php @@ -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 { $updateset[] = "visible = 'yes'"; diff --git a/public/mybonus.php b/public/mybonus.php index 71231360..bb562fb7 100644 --- a/public/mybonus.php +++ b/public/mybonus.php @@ -393,28 +393,33 @@ if ($donortimes_bonus) print("
  • ".$lang_mybonus['text_donors_always_get'].$donortimes_bonus.$lang_mybonus['text_times_of_bonus']."
  • "); print(""); - $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 = strtotime(date("Y-m-d H:i:s")); - $sectoweek = 7*24*60*60; - $A = 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__); - 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++; - } - if ($count > $maxseeding_bonus) - $count = $maxseeding_bonus; - $all_bonus = $valuetwo * atan($A / $l_bonus) + ($perseeding_bonus * $count); +// $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 = strtotime(date("Y-m-d H:i:s")); +// $sectoweek = 7*24*60*60; +// $A = 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__); +// 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++; +// } +// if ($count > $maxseeding_bonus) +// $count = $maxseeding_bonus; +// $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); print("
    ".$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).")
    ");