This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
chartdata.php
91 lines (77 loc) · 2.01 KB
/
chartdata.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
<?php
/**
* Bitcoin Status Page - Stats
*
* @category File
* @package BitcoinStatus
* @author Craig Watson <craig@cwatson.org>
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @link https://github.com/craigwatson/bitcoind-status
*/
if (!isset($_GET['stat'])) {
die('Need to pass stat');
}
require_once './php/config.php';
header('Content-Type: application/javascript');
switch($_GET['stat']) {
case 'connection':
$data_file = $config['stats_file'];
$min_points = $config['peercount_min_data_points'];
$headers = array('Date','Connections');
$prefixes = array('new Date(','');
$postfixes = array('*1000)','');
break;
case 'peer':
$data_file = $config['peercount_file'];
$min_points = $config['peercount_min_data_points'];
$headers = array('Date','Other','Classic','BitCoinJ','Core','Unlimited');
$prefixes = array('new Date(','','','','','');
$postfixes = array('*1000)','','','','','');
foreach ($config['peercount_extra_nodes'] as $key => $val) {
$headers[] = $val;
$prefixes[] = '';
$postfixes[] = '';
}
break;
default:
die('Invalid value passed to stat');
}
// Check for existing data
if (is_file($data_file)) {
$data = json_decode(file_get_contents($data_file), true);
} else {
$data = array();
}
// Start output
echo "var " . $_GET['stat'] . "ChartData = [\n";
// Output headers
$headernum = 0; echo "\t[";
foreach ($headers as $header) {
$headernum++;
echo "'$header'";
if ($headernum != count($headers)) {
echo ",";
}
}
echo "],\n";
// Output data rows
$rownum = 0;
foreach ($data as $row) {
$rownum++;
echo "\t[";
$cellnum = 0;
foreach ($row as $cell) {
echo $prefixes[$cellnum] . $cell . $postfixes[$cellnum];
$cellnum++;
if ($cellnum != count($row)) {
echo ",";
}
}
echo "]";
if ($rownum != count($data)) {
echo ",";
}
echo "\n";
}
// Finish output
echo "]";