Browse Source

Updating BP formula to match PTP's

ElectraHeart 7 years ago
parent
commit
53fc9945e7
1 changed files with 58 additions and 32 deletions
  1. 58
    32
      sections/schedule/hourly/bonus_points.php

+ 58
- 32
sections/schedule/hourly/bonus_points.php View File

1
 <?
1
 <?
2
 //------------------------ Update Bonus Points -------------------------//
2
 //------------------------ Update Bonus Points -------------------------//
3
 
3
 
4
-$getUsers = $DB->query("
5
-  SELECT um.ID,
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, $NumTorr, $TSize, $TTime, $TSeeds) = $DB->next_record()) {
25
-    $Points = intval((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
-    if ($Points > 100000) $Points = 0;
27
-    $QueryPart .= "WHEN $UserID THEN BonusPoints+$Points ";
28
-    $Cache->delete_value('user_info_heavy_'.$UserID);
29
-  }
30
-
31
-  $DB->query("
32
-    UPDATE users_main
33
-    SET BonusPoints = CASE ID "
34
-    .$QueryPart.
35
-    "ELSE BonusPoints END");
4
+function bytesToGiB($bytes) {
5
+	if ($bytes > 1048576) {
6
+		$GiB = $bytes / 1073741824;
7
+	} else {
8
+		$GiB = 0;
9
+	}
10
+	return $GiB;
36
 }
11
 }
12
+
13
+function calculateBP() {
14
+	global $DB;
15
+	global $Cache;
16
+
17
+	$getUsers = $DB->query("SELECT DISTINCT(uid) AS uid FROM xbt_files_users");
18
+	if ($DB->has_results()) {
19
+		$users = array();
20
+		while ($result = $DB->next_record()) {
21
+			$users[] = $result['uid'];
22
+		}
23
+		foreach($users as $UserID) {
24
+			$DB->query("
25
+				SELECT t.Size,
26
+						t.Seeders,
27
+						(us.SeedTime/60/60/24) AS days
28
+				FROM xbt_files_users AS x
29
+				LEFT JOIN torrents AS t ON t.ID=x.fid
30
+				LEFT JOIN users_seedtime AS us ON x.fid=us.TorrentID AND x.uid=us.UserID
31
+				WHERE x.uid = $UserID AND x.active=1");
32
+
33
+			$totalBP = 0;
34
+			while ($torrent = $DB->next_record()) {
35
+				$points = bytesToGiB($torrent['Size']) * ( 0.25 + ( 0.6 * log(1+$torrent['days']) / pow($torrent['Seeders'],0.6) ) );
36
+				$totalBP = $totalBP + $points;
37
+			}
38
+
39
+			if ($totalBP > 0) {
40
+				$DB->query("SELECT BonusPoints, BPDems FROM users_main WHERE ID=$UserID");
41
+				list($BonusPoints, $BPDems) = $DB->next_record();
42
+				$OldBP = (float) $BonusPoints.'.'.$BPDems;
43
+				$NewBP = $OldBP + $totalBP;
44
+				$NewDems = $NewBP - floor($NewBP);
45
+				$NewBP = $NewBP - $NewDems;
46
+				$NewDems = (int) substr($NewDems, 2);
47
+
48
+				$DB->query("
49
+					UPDATE users_main
50
+					SET BonusPoints = $NewBP, BPDems = $NewDems
51
+					WHERE ID=$UserID");
52
+
53
+			}
54
+
55
+		    $Cache->delete_value('user_info_heavy_'.$UserID);
56
+		}
57
+
58
+	}
59
+}
60
+
61
+calculateBP();
62
+
37
 ?>
63
 ?>

Loading…
Cancel
Save