-
Notifications
You must be signed in to change notification settings - Fork 9
/
hashrate.php.bak
63 lines (53 loc) · 2.31 KB
/
hashrate.php.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$includeDirectory = "/var/www/pool/www/includes/";
include($includeDirectory."requiredFunctions.php");
//Hashrate by worker
$sql = "SELECT IFNULL(sum(a.id),0) as id, p.username FROM pool_worker p LEFT JOIN ".
"((SELECT count(id) as id, username ".
"FROM shares ".
"WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ".
"GROUP BY username) ".
"UNION ".
"(SELECT count(id) as id, username ".
"FROM shares_history ".
"WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE) ".
"GROUP BY username)) a ".
"ON p.username=a.username ".
"GROUP BY username";
$result = mysql_query($sql);
while ($resultrow = mysql_fetch_object($result)) {
$hashrate = $resultrow->id;
$hashrate = round((($hashrate*4294967296)/600)/1000000, 0);
mysql_query("UPDATE pool_worker SET hashrate = $hashrate WHERE username = '$resultrow->username'");
}
//Total Hashrate (more exact than adding)
$sql = "SELECT sum(a.id) as id FROM ".
"((SELECT count(id) as id FROM shares WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)) ".
"UNION ".
"(SELECT count(id) as id FROM shares_history WHERE time > DATE_SUB(now(), INTERVAL 10 MINUTE)) ".
") a ";
$result = mysql_query($sql);
if ($resultrow = mysql_fetch_object($result)) {
$hashrate = $resultrow->id;
$hashrate = round((($hashrate*4294967296)/600)/1000000, 0);
mysql_query("UPDATE settings SET value = '$hashrate' WHERE setting='currenthashrate'");
}
//Hashrate by user
$sql = "SELECT u.id, IFNULL(sum(p.hashrate),0) as hashrate ".
"FROM webUsers u LEFT JOIN pool_worker p ".
"ON p.associatedUserId = u.id ".
"GROUP BY id";
$result = mysql_query($sql);
while ($resultrow = mysql_fetch_object($result)) {
mysql_query("UPDATE webUsers SET hashrate = $resultrow->hashrate WHERE id = $resultrow->id");
// Enable this for lots of stats for graphing
if ($resultrow->hashrate > 0) {
mysql_query("INSERT INTO userHashrates (userId, hashrate) VALUES ($resultrow->id, $resultrow->hashrate)"); // active users hashrate
}
}
mysql_query("INSERT INTO userHashrates (userId, hashrate) VALUES (0, $hashrate)"); // the pool total hashrate
$currentTime = time();
mysql_query("update settings set value='$currentTime' where setting='statstime'");
// Clean up the userHashrate table (anything older than 5 days)
mysql_query("DELETE FROM userHashrates WHERE timestamp < DATE_SUB(now(), INTERVAL 120 HOUR)");
?>