Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bonus_points.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?
  2. //------------------------ Update Bonus Points -------------------------//
  3. $getUsers = $DB->query("
  4. SELECT um.ID,
  5. um.BonusPoints,
  6. COUNT(DISTINCT x.fid) AS Torrents,
  7. SUM(t.Size) AS Size,
  8. SUM(xs.seedtime) AS Seedtime,
  9. SUM(t.Seeders) AS Seeders
  10. FROM users_main AS um
  11. LEFT JOIN users_info AS i on um.ID = i.UserID
  12. LEFT JOIN xbt_files_users AS x ON um.ID=x.uid
  13. LEFT JOIN torrents AS t ON t.ID=x.fid
  14. LEFT JOIN xbt_snatched AS xs ON x.uid=xs.uid AND x.fid=xs.fid
  15. WHERE
  16. um.Enabled = '1'
  17. AND i.DisablePoints = '0'
  18. AND x.active = 1
  19. AND x.completed = 0
  20. AND x.Remaining = 0
  21. GROUP BY um.ID");
  22. if ($DB->has_results()) {
  23. $QueryPart = '';
  24. while (list($UserID, $BonusPoints, $NumTorr, $TSize, $TTime, $TSeeds) = $DB->next_record()) {
  25. $Points = (0.5 + (0.55*($NumTorr * (sqrt(($TSize/$NumTorr)/1073741824) * pow(1.5,($TTime/$NumTorr)/(24*365))))) / (max(1, sqrt(($TSeeds/$NumTorr)+4)/3)))**0.95;
  26. $Points = intval(max(min($Points, ($Points * 2) - ($BonusPoints/1440)), 0));
  27. if ($Points > 100000) $Points = 0;
  28. if ($Points > 0) {
  29. $QueryPart .= "WHEN $UserID THEN BonusPoints+$Points ";
  30. $Cache->delete_value('user_info_heavy_'.$UserID);
  31. }
  32. }
  33. $DB->query("
  34. UPDATE users_main
  35. SET BonusPoints = CASE ID "
  36. .$QueryPart.
  37. "ELSE BonusPoints END");
  38. }
  39. ?>