Browse Source

Switching to PTP's BP calulation methodology and adding BP Rates page

ElectraHeart 7 years ago
parent
commit
88c1c08f5c
3 changed files with 156 additions and 33 deletions
  1. 1
    1
      design/privateheader.php
  2. 59
    32
      sections/schedule/hourly/bonus_points.php
  3. 96
    0
      sections/user/bprates.php

+ 1
- 1
design/privateheader.php View File

300
 <?  }
300
 <?  }
301
 ?>
301
 ?>
302
           <li id="bonus_points">
302
           <li id="bonus_points">
303
-            <a href="wiki.php?action=article&amp;name=bonuspoints"><?=BONUS_POINTS?></a>:
303
+            <a href="user.php?action=bprates"><?=BONUS_POINTS?></a>:
304
             <span class="stat">
304
             <span class="stat">
305
               <a href="store.php"><?=number_format(G::$LoggedUser['BonusPoints'])?></a>
305
               <a href="store.php"><?=number_format(G::$LoggedUser['BonusPoints'])?></a>
306
             </span>
306
             </span>

+ 59
- 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 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
 ?>

+ 96
- 0
sections/user/bprates.php View File

1
+<?
2
+	function bytesToGiB($bytes) {
3
+		if ($bytes > 1048576) {
4
+			$GiB = $bytes / 1073741824;
5
+		} else {
6
+			$GiB = 0;
7
+		}
8
+		return $GiB;
9
+	}
10
+
11
+	$Username = $LoggedUser['Username'];
12
+	View::show_header($Username." &gt; Bonus Rates");
13
+
14
+	$activeTorrents = array();
15
+	$DB->query("
16
+		SELECT x.timespent,
17
+				t.GroupID,
18
+				t.Media,
19
+				t.Container,
20
+				t.Codec,
21
+				t.Resolution,
22
+				t.AudioFormat,
23
+				t.Size,
24
+				t.Seeders,
25
+				t.Recorded,
26
+				us.SeedTime,
27
+				(us.SeedTime/60/60) AS hours,
28
+				(us.SeedTime/60/60/24) AS days,
29
+				tg.Name AS Album,
30
+				ag.Name AS Artist
31
+		FROM xbt_files_users AS x
32
+		LEFT JOIN torrents AS t ON t.ID=x.fid
33
+		LEFT JOIN users_seedtime AS us ON x.fid=us.TorrentID AND x.uid=us.UserID
34
+		LEFT JOIN torrents_group AS tg ON t.GroupID=tg.ID
35
+		LEFT JOIN torrents_artists AS ta ON t.GroupID=ta.GroupID
36
+		LEFT JOIN artists_group AS ag ON ta.ArtistID=ag.ArtistID
37
+		WHERE x.uid = $UserID AND x.active=1 AND x.remaining=0
38
+		GROUP BY x.fid, x.ip");
39
+	while ($result = $DB->next_record()) {
40
+		$activeTorrents[] = $result;
41
+	}
42
+	$totals = [
43
+		'torrents' => 0,
44
+		'size' => 0,
45
+		'points' => 0,
46
+	];
47
+?>
48
+<div class="thin">
49
+	<div class="header">
50
+		<h2><?=Users::format_username($UserID, false, false, false)?> &gt; Bonus Rates</h2>
51
+	</div>
52
+	<div class="main_column" style="width: 100%; margin-top: 18px">
53
+		<table class="box torrent_table cats no_grouping" id="torrent_table">
54
+			<tr class="colhead">
55
+				<td>Torrent</td>
56
+				<td>Size</td>
57
+				<td><svg width="11" height="15" fill="white" class="tooltip" alt="Seeders" title="Seeders"><polygon points="0,7 5.5,0 11,7 8,7 8,15 3,15 3,7"></polygon></svg>
58
+	          </td>
59
+				<td>Seed Time</td>
60
+				<td>BP/hour</td>
61
+			</tr>
62
+<?php foreach ($activeTorrents as $torrent) { 
63
+	$points = bytesToGiB($torrent['Size']) * ( 0.25 + ( 0.6 * log(1+$torrent['days']) / pow($torrent['Seeders'],0.6) ) );
64
+	$totals['torrents']++;
65
+	$totals['size'] = $totals['size'] + $torrent['Size'];
66
+	$totals['points'] = $totals['points'] + $points;
67
+?>
68
+			<tr id="site_style_tr">
69
+				<td><?=$torrent['Artist'].' - '.$torrent['Album'].' - '.$torrent['Recorded'].' | '.$torrent['Codec'].' / '.$torrent['Media'].' / '.$torrent['Container'].' / '.$torrent['Resolution'].' / '.$torrent['AudioFormat']; ?></td>
70
+				<td><?=Format::get_size($torrent['Size'])?></td>
71
+				<td><?php echo $torrent['Seeders']; ?></td>
72
+				<td><?php echo round($torrent['days'], 2); ?> days</td>
73
+				<td><?=round($points, 4)?></td>
74
+			</tr>
75
+<?php } ?>
76
+		</table>
77
+		<br />
78
+		<table class="box torrent_table cats no_grouping" id="torrent_table">
79
+			<tr class="colhead">
80
+				<td>Total Torrents</td>
81
+				<td>Seeding Size</td>
82
+				<td>BP/hour</td>
83
+				<td>BP/day</td>
84
+				<td>BP/month</td>
85
+			</tr>
86
+			<tr>
87
+				<td><?=$totals['torrents']?></td>
88
+				<td><?=Format::get_size($totals['size'])?></td>
89
+				<td><?=round($totals['points'], 4)?></td>
90
+				<td><?=round($totals['points']*24, 4)?></td>
91
+				<td><?=round($totals['points']*24*30, 4)?></td>
92
+			</tr>
93
+		</table>
94
+	</div>
95
+</div>
96
+<? View::show_footer(); ?>

Loading…
Cancel
Save