forked from szarkos/paradb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats_plot.php
210 lines (163 loc) · 5.27 KB
/
stats_plot.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
<?php
//-------------------------------------------------------------------//
//
// AGHOST Paranormal Reporting Database (ParaDB)
// Copyright (c) 2007 Stephen A. Zarkos <[email protected]>
//
// See the file COPYING for terms of use and redistribution.
//
// File: stats_plot.php
// Generate plots and stuff.
//
//-------------------------------------------------------------------//
// Function: print_geomag_plot()
// Prints geomagnetic data plot.
function print_geomag_plot() {
global $server_path;
if ( set_paradb_include_path() != 0 ) {
return ERR_UNDEF;
}
if ( !@(include_once('PEAR/Image/Graph.php')) ) {
if ( !@(include_once($server_path . 'PEAR/Image/Graph.php')) ) {
do_log( 'Error: print_geomag_plot(): Image/Graph.php not available. You may need to install the PEAR Image_Graph module: http://pear.php.net/package/Image_Graph' );
return ERR_UNDEF;
}
}
// Check if our output image is writable.
$output_dir = $server_path . '/images/stats_images/';
$output_image = $output_dir . 'geomag_stats.png';
if ( file_exists($output_image) ) {
if ( !is_writable($output_image) ) {
do_log( 'Error: print_geomag_plot(): File $output_image is not writeable.' );
return ERR_FWRITE;
}
}
else {
if ( !is_writable($output_dir) ) {
do_log( 'Error: print_geomag_plot(): Directory $output_dir is not writeable.' );
return ERR_FWRITE;
}
}
// Call geomag_stats() to get statistics from database.
$geomag_stats = geomag_stats();
$cnt = 0;
foreach ( array_keys($geomag_stats) as $status ) {
// Let's see if any of the elements are >0.
if ( $geomag_stats[$status] > 0 ) {
$cnt = 1;
break;
}
}
if ( $cnt == 0 ) {
print "<p>Sorry, no geomagnetic information available.\n</p>";
if ( file_exists($output_image) ) {
unlink( $output_image );
}
return 0;
}
return create_pie_chart( $geomag_stats, 'Geomagnetic Activity' );
}
// Function: print_xray_plot()
// Prints xray data plot.
function print_xray_plot() {
global $server_path;
if ( set_paradb_include_path() != 0 ) {
return ERR_UNDEF;
}
if ( !@(include_once('PEAR/Image/Graph.php')) ) {
if ( !@(include_once($server_path . 'PEAR/Image/Graph.php')) ) {
do_log( 'Error: print_geomag_plot(): Image/Graph.php not available. You may need to install the PEAR Image_Graph module: http://pear.php.net/package/Image_Graph' );
return ERR_UNDEF;
}
}
// Check if our output image is writable.
$output_dir = $server_path . '/images/stats_images/';
$output_image = $output_dir . 'xray_stats.png';
if ( file_exists($output_image) ) {
if ( !is_writable($output_image) ) {
do_log( 'Error: print_xray_plot(): File $output_image is not writeable.' );
return ERR_FWRITE;
}
}
else {
if ( !is_writable($output_dir) ) {
do_log( 'Error: print_xray_plot(): Directory $output_dir is not writeable.' );
return ERR_FWRITE;
}
}
// Call xray_stats() to get statistics from database.
$xray_stats = xray_stats();
$cnt = 0;
foreach ( array_keys($xray_stats) as $status ) {
// Let's see if any of the elements are >0.
if ( $xray_stats[$status] > 0 ) {
$cnt = 1;
break;
}
}
if ( $cnt == 0 ) {
print "<p>Sorry, no xray information available.</p>\n";
if ( file_exists($output_image) ) {
unlink( $output_image );
}
return 0;
}
return create_pie_chart( $xray_stats, 'Xray Activity' );
}
// Function: create_pie_chart()
function create_pie_chart( $data=array(), $title='' ) {
if ( !is_array($data) || empty($data) ) {
return 0;
}
// Create the graph.
$Graph =& Image_Graph::factory( 'graph', array(400, 300) );
$Font =& $Graph->addNew( 'font', 'LiberationMono-Regular' );
$Font->setSize( 8 );
$Graph->setFont( $Font );
// create the plotarea
$Graph->add(
Image_Graph::vertical(
Image_Graph::factory('title', array($title, 12)),
Image_Graph::horizontal(
$Plotarea = Image_Graph::factory('plotarea'),
$Legend = Image_Graph::factory('legend'),
70
),
5
)
);
$Legend->setPlotarea( $Plotarea );
// Create the 1st dataset
$Dataset =& Image_Graph::factory( 'dataset' );
foreach ( array_keys($data) as $key ) {
if ( $data[$key] != 0 ) {
$Dataset->addPoint( $key, $data[$key] );
}
}
// Create the 1st plot as smoothed area chart using the 1st dataset
$Plot =& $Plotarea->addNew( 'pie', array(&$Dataset) );
$Plotarea->hideAxis();
// Create a Y data value marker
$Marker =& $Plot->addNew( 'Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL );
// Create a pin-point marker type
$PointingMarker =& $Plot->addNew( 'Image_Graph_Marker_Pointing_Angular', array(20, &$Marker) );
// and use the marker on the 1st plot
$Plot->setMarker( $PointingMarker );
// Format value marker labels as percentage values
$Marker->setDataPreprocessor( Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%') );
$Plot->Radius = 3;
$FillArray =& Image_Graph::factory( 'Image_Graph_Fill_Array' );
$Plot->setFillStyle( $FillArray );
$FillArray->addColor( '[email protected]' );
$FillArray->addColor( '[email protected]' );
$FillArray->addColor( '[email protected]' );
$FillArray->addColor( '[email protected]' );
$FillArray->addColor( '[email protected]' );
$FillArray->addColor( '[email protected]' );
$Plot->explode( 5 );
$Plot->setStartingAngle( 90 );
// Output the Graph.
$Graph->done( array('filename' => $output_image) );
return 0;
}
?>