|
@@ -1,37 +1,64 @@
|
1
|
1
|
<?
|
2
|
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 AND x.remaining=0
|
|
32
|
+ GROUP BY x.fid, x.ip");
|
|
33
|
+
|
|
34
|
+ $totalBP = 0;
|
|
35
|
+ while ($torrent = $DB->next_record()) {
|
|
36
|
+ $points = bytesToGiB($torrent['Size']) * ( 0.25 + ( 0.6 * log(1+$torrent['days']) / pow($torrent['Seeders'],0.6) ) );
|
|
37
|
+ $totalBP = $totalBP + $points;
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ if ($totalBP > 0) {
|
|
41
|
+ $DB->query("SELECT BonusPoints, BPDems FROM users_main WHERE ID=$UserID");
|
|
42
|
+ list($BonusPoints, $BPDems) = $DB->next_record();
|
|
43
|
+ $OldBP = (float) $BonusPoints.'.'.$BPDems;
|
|
44
|
+ $NewBP = $OldBP + $totalBP;
|
|
45
|
+ $NewDems = $NewBP - floor($NewBP);
|
|
46
|
+ $NewBP = $NewBP - $NewDems;
|
|
47
|
+ $NewDems = (int) substr($NewDems, 2);
|
|
48
|
+
|
|
49
|
+ $DB->query("
|
|
50
|
+ UPDATE users_main
|
|
51
|
+ SET BonusPoints = $NewBP, BPDems = $NewDems
|
|
52
|
+ WHERE ID=$UserID");
|
|
53
|
+
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ $Cache->delete_value('user_info_heavy_'.$UserID);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+calculateBP();
|
|
63
|
+
|
37
|
64
|
?>
|