-
Notifications
You must be signed in to change notification settings - Fork 23
/
dmnvotesrrdxport.script.inc.php
executable file
·90 lines (76 loc) · 2.38 KB
/
dmnvotesrrdxport.script.inc.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
<?php
/*
This file is part of Dash Ninja.
https://github.com/elbereth/dashninja-ctl
Dash Ninja is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Dash Ninja is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Dash Ninja. If not, see <http://www.gnu.org/licenses/>.
*/
DEFINE('DMN_VERSION','1.0.1');
xecho('dmnvotesrrdxport v'.DMN_VERSION."\n");
function do_xport( $start, $end, $step, $filename, $testnet = false ) {
if ($testnet) {
$testnet = "testnet";
}
else {
$testnet = '';
}
xecho("RRD DB xport ($start to $end step $step $testnet): ");
$xport = rrd_xport( array( "-s", $start, "-e", $end, "--step", $step,
"DEF:a=mnvotes2$testnet.rrd:Yea:MAX",
"DEF:b=mnvotes2$testnet.rrd:Nay:MAX",
"DEF:c=mnvotes2$testnet.rrd:Abstain:MAX",
'XPORT:a:Yea',
'XPORT:b:Nay',
'XPORT:c:Abstain'
)
);
if ($xport === false) {
echo "Failed!\n";
return false;
}
else {
echo "OK\n";
foreach($xport["data"] as $key1 => $data1) {
foreach($xport["data"][$key1]["data"] as $key2 => $data2) {
if (is_nan($data2)) {
$xport["data"][$key1]["data"][$key2] = false;
} else {
$xport["data"][$key1]["data"][$key2] = intval(round($data2));
}
}
}
}
xecho("JSON Encoding output: ");
$json = json_encode($xport);
if ($json !== false) {
echo "OK (".strlen($json)." bytes)\n";
xecho("Writing to file: ");
if (file_put_contents($filename,$json) !== false) {
echo "OK\n";
return true;
}
else {
echo "Error\n";
return false;
}
}
else {
echo "Error\n";
return false;
}
}
do_xport( "now-3h", "now", "600", "mnvotes-main-3h.json" );
do_xport( "now-24h", "now", "3600", "mnvotes-main-24h.json" );
do_xport( "now-7d", "now", "43200", "mnvotes-main-7d.json" );
do_xport( "now-3h", "now", "600", "mnvotes-test-3h.json", true );
do_xport( "now-24h", "now", "3600", "mnvotes-test-24h.json", true );
do_xport( "now-7d", "now", "43200", "mnvotes-test-7d.json", true );
?>