-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathglobal_stats.php
More file actions
executable file
·107 lines (94 loc) · 3.12 KB
/
global_stats.php
File metadata and controls
executable file
·107 lines (94 loc) · 3.12 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
$debug = $_GET['debug'];
include("config.php");
$db = mysql_connect("$host", "$database", "$dbpassword");
mysql_select_db("$database", $db);
$request = "SELECT * FROM `global_stats` ORDER BY `id` DESC LIMIT 0,500";
$result = mysql_query($request,$db);
$time_raw=array();
$hashrate_raw=array();
$workers_raw=array();
while($row = mysql_fetch_array($result))
{
$time_raw[] = (int)$row["time"]*1000;
$hashrate_raw[] = (int)$row["hashrate"]/1000;
$workers_raw[] = (int)$row["workers"];
$network_hashrate_raw[] = (float)$row["network_hashrate"];
$buffer_raw[] = (float)$row["buffer"];
}
$min_time = min($time_raw)/1000;
$request = "SELECT * FROM blocks WHERE (`timestamp` >= ({$min_time})) ORDER BY `timestamp`";
$result = mysql_query($request,$db);
$blocks_raw=array();
while($row = mysql_fetch_array($result))
{
$blocks_raw[] = (int)$row["timestamp"]*1000;
}
//echo $row["time"];
$blocks = array_reverse($blocks_raw);
$time = array_reverse($time_raw);
$hashrate = array_reverse($hashrate_raw);
$workers = array_reverse($workers_raw);
$network_rate = array_reverse($network_hashrate_raw);
$buffer = array_reverse($buffer_raw);
//for ( $i = 0; $i < sizeof($time); $i++)
//{
// $time[$i] = date("Y-m-d H:i:s", $time[$i]);
//}
function make_pair($time, $hashrate) {
return array($time, $hashrate);
}
$hasharray = array_map('make_pair', $time, $hashrate);
$datapoints = json_encode($hasharray);
function make_buffer_pair($time, $buffer) {
return array($time, $buffer);
}
$buffer_array = array_map('make_buffer_pair', $time, $buffer);
$buffer = json_encode($buffer_array);
function make_pair2($time, $workers) {
return array($time, $workers);
}
function block_array($blocks) {
return array($blocks, 5000);
}
$hasharray = array_map('make_pair2', $time, $workers);
$datapoints2 = json_encode($hasharray);
$hasharray = array_map('block_array', $blocks);
$datapoints3 = json_encode($hasharray);
$network_hashrate = end($network_rate) - (end($hashrate));
if ($_GET[debug] == 1)
{
echo "<h1>Debug enabled!</h1>";
echo "<br>";
echo "<h2>Regular array (Time & Workers):</h2>";
print_r($hasharray);
echo "<h2>JSON encoded:</h2>";
print $datapoints;
echo "<br>";
echo "<h2>Network Hashrate :</h2>".$network_hashrate." GH/s";
echo "<h2>Pool Hashrate :</h2>".(end($hashrate))." GH/s";
}
$request = "SELECT * FROM `global_stats` ORDER BY `id` DESC";
$result = mysql_query($request,$db);
$time_raw=array();
$hashrate_raw=array();
while($row = mysql_fetch_array($result))
{
$time_raw[] = (int)$row["time"]*1000;
$hashrate_raw[] = (int)$row["hashrate"]/1000;
}
$time = array_reverse($time_raw);
$hashrate = array_reverse($hashrate_raw);
$hasharray = array_map('make_pair', $time, $hashrate);
$datapoints4 = json_encode($hasharray);
if ($_GET[debug] == 1)
{
echo "<h1>Debug enabled!</h1>";
echo "<br>";
echo "<h2>Regular array (Time & Workers):</h2>";
print_r($hasharray);
echo "<h2>JSON encoded:</h2>";
print $datapoints4;
}
mysql_free_result($result);
?>