-
Notifications
You must be signed in to change notification settings - Fork 166
/
graph.php
218 lines (178 loc) · 6.09 KB
/
graph.php
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
require_once ABSPATH . '/ezcomponents/Base/src/ezc_bootstrap.php';
function format_exponential_axis_label($x) {
$vals = explode('^', $x);
return sprintf("%.0f", pow($vals[0], $vals[1]));
}
function get_funds_graph_data()
{
$btc = array();
$fiat = array();
$query = "
SELECT
req_type, amount, curr_type, " . sql_format_date('timest') . " AS timest2
FROM
requests
WHERE
status != 'CANCEL'
ORDER BY
timest;
";
$result = do_query($query);
$btc_sum = 0;
$fiat_sum = 0;
while ($row = mysql_fetch_array($result)) {
$req_type = $row['req_type'];
$amount = $row['amount'];
$curr_type = $row['curr_type'];
$timest = $row['timest2'];
if ($req_type == 'WITHDR')
$amount = gmp_mul(-1, $amount);
if ($curr_type == 'BTC') {
$btc_sum = gmp_add($btc_sum, $amount);
$btc[$timest] = internal_to_numstr($btc_sum);
} else {
$fiat_sum = gmp_add($fiat_sum, $amount);
$fiat[$timest] = internal_to_numstr($fiat_sum);
}
}
return array($btc, $fiat);
}
function get_users_graph_data()
{
$users = array();
$query = "
SELECT " .
sql_format_date('timest') . " AS timest2
FROM
users
WHERE
uid != 1
ORDER BY
timest;
";
$result = do_query($query);
$count = 0;
while ($row = mysql_fetch_array($result)) {
$timest = $row['timest2'];
$count++;
$users[$timest] = $count;
}
return $users;
}
class customPalette extends ezcGraphPalette
{
protected $axisColor = '#000000';
protected $majorGridColor = '#000000BB';
protected $minorGridColor = '#000000EE';
protected $dataSetColor = array('#3465A410', '#2E7A0610');
protected $dataSetSymbol = ezcGraph::NO_SYMBOL;
protected $fontName = 'sans-serif';
protected $fontColor = '#000';
protected $chartBackground = '#7ad3af';
// protected $chartBorderColor = '#6ac39f';
protected $chartBorderWidth = 10;
}
function show_funds_graph($log_axis = -1, $x = 0, $y = 0)
{
global $is_logged_in, $is_admin;
if (!$is_admin) {
show_header('graph', $is_logged_in);
throw new Error("Bad Argument", "You can't view that graph type");
}
if ($log_axis == -1) $log_axis = isset($_GET['log']) ? get('log') : 1;
if (!$x) $x = isset($_GET['x']) ? get('x') : 720;
if (!$y) $y = isset($_GET['y']) ? get('y') : 500;
if (!isset($_GET['svg'])) {
show_header('graph', $is_logged_in);
echo ("<div class='content_box'>\n" .
"<h3>Funds on the Exchange</h3>\n" .
"<p>\n" .
"<iframe src='?page=graph&type=funds&x=$x&y=$y&log=$log_axis&svg' type='image/svg+xml' width='$x' height='$y' scrolling='no' frameborder='0'>\n" .
"</iframe>\n" .
"</p>\n" .
"</div>\n");
return;
}
$graph = new ezcGraphLineChart();
$graph->palette = new customPalette();
$graph->options->fillLines = 180;
$graph->options->font->maxFontSize = 12;
$graph->legend->position = ezcGraph::BOTTOM;
$graph->xAxis = new ezcGraphChartElementDateAxis();
$graph->xAxis->dateFormat = 'j M y';
$graph->xAxis->interval = 60*60*24*7*4;
if ($log_axis) {
$graph->yAxis = new ezcGraphChartElementLogarithmicalAxis();
$graph->yAxis->base = pow(10, 1/2);;
$graph->yAxis->logarithmicalFormatString = '%1$f^%2$f';
$graph->yAxis->labelCallback = "format_exponential_axis_label";
}
list ($btc, $fiat) = get_funds_graph_data();
$graph->data[CURRENCY_FULL_PLURAL] = new ezcGraphArrayDataSet($fiat);
$graph->data['Bitcoins'] = new ezcGraphArrayDataSet($btc);
$graph->renderToOutput($x, $y);
exit(); // we don't want the footer
}
function show_users_graph($x = 0, $y = 0)
{
global $is_logged_in, $is_admin;
if (!$is_admin) {
show_header('graph', $is_logged_in);
throw new Error("Bad Argument", "You can't view that graph type");
}
if (!$x) $x = isset($_GET['x']) ? get('x') : 720;
if (!$y) $y = isset($_GET['y']) ? get('y') : 500;
if (!isset($_GET['svg'])) {
show_header('graph', $is_logged_in);
echo ("<div class='content_box'>\n" .
"<h3>Users on the Exchange</h3>\n" .
"<p>\n" .
"<iframe src='?page=graph&type=users&x=$x&y=$y&svg' type='image/svg+xml' width='$x' height='$y' scrolling='no' frameborder='0'>\n" .
"</iframe>\n" .
"</p>\n" .
"</div>\n");
return;
}
$graph = new ezcGraphLineChart();
$graph->palette = new customPalette();
$graph->options->fillLines = 180;
$graph->options->font->maxFontSize = 12;
$graph->legend->position = ezcGraph::BOTTOM;
$graph->xAxis = new ezcGraphChartElementDateAxis();
$graph->xAxis->dateFormat = 'j M y';
$graph->xAxis->interval = 60*60*24*7*4;
$users = get_users_graph_data();
$graph->data['Users'] = new ezcGraphArrayDataSet($users);
$graph->renderToOutput($x, $y);
exit(); // we don't want the footer
}
function graph_main()
{
global $is_logged_in, $is_admin;
if (isset($_GET['type']))
switch(get('type')) {
case 'funds':
show_funds_graph();
break;
case 'users':
show_users_graph();
break;
default:
show_header('graph', $is_logged_in);
throw new Error("Bad Argument", "Unknown graph type");
}
else {
show_header('graph', $is_logged_in);
echo "<div class='content_box'>\n";
echo "<h3>Graphs</h3>\n";
echo "<p>Pick a graph type:</p>\n";
echo "<ul>\n";
echo "<li><a href='?page=graph&type=funds&log=0'>funds (linear axis)</a></li>\n";
echo "<li><a href='?page=graph&type=funds'>funds (log axis)</a></li>\n";
echo "<li><a href='?page=graph&type=users'>users</a></li>\n";
echo "</li></p></div>\n";
}
}
graph_main();
?>