-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstats.php
294 lines (236 loc) · 7.6 KB
/
stats.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?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.php
// Generate statistics and user scorecard.
//
//-------------------------------------------------------------------//
require( 'stats_print.php' );
// Notes:
// Cases occuring during x-ray activity.
// Cases occuring during geomagnetic storm.
// Other ideas:
// Average investigation length (time, taken from reports).
// Walkthroughs might throw this off.
// Function: get_user_stats( [user_id] ) {
// Returns an array with the user's ID, name, username, number of cases associated with the user and
// number of reports the user has started.
// Array ( [USERNAME] => Array ( [id] => nn,
// [name] => "REAL NAME",
// [email] => "EMAIL ADDRESS",
// [reports_db_perm] => nn,
// [cases] => nn,
// [reports] => nn,
// [data] => nn )
function get_user_stats( $user_id="" ) {
global $db_connection;
if ( empty($user_id) ) {
$users = listusers();
}
else {
$users = get_userinfo( $user_id );
}
// Pull case_ids and investigators.
$cases = array();
$data_submitted = array();
$result = mysql_get_rows( 'reportsdb_cases', 'case_id,investigators,data_submitted', NULL, NULL, NULL, $db_connection );
while ( $row = mysql_fetch_row($result) ) {
$cases[$row[0]] = explode( ',', $row[1] );
$data_submitted[$row[0]] = array();
$data = explode( ',', $row[2] );
foreach ( $data as $key ) {
$tmp = explode( '|', $key );
if ( isset($tmp[1]) && !empty($tmp[1]) ) {
array_push( $data_submitted[$row[0]], $tmp[0] );
}
}
}
if ( !empty($user_id) ) {
// Convert the array listing from the get_userinfo() type to the listusers() type.
$users = array ( $users['username'] => array ( 'id' => $users['id'],
'name' => $users['name'],
'email' => $users['email'],
'reports_db_perm' => $users['reports_db_perm'] ) );
}
foreach ( array_keys($users) as $user ) {
// [cases]
$users[$user]['cases'] = 0;
$users[$user]['data'] = 0;
foreach ( array_keys($cases) as $case ) {
if ( in_array($users[$user]['id'], $cases[$case]) ) {
// User is on the case...
$users[$user]['cases']++;
}
// [data]
if ( in_array($users[$user]['id'], $data_submitted[$case]) ) {
$users[$user]['data']++;
}
}
// [reports]
$result = mysql_get_rows( 'reportsdb_reports', 'owner_id', 'owner_id=' . $users[$user]['id'], NULL, NULL, $db_connection );
$users[$user]['reports'] = mysql_num_rows( $result );
}
return $users;
}
// Function: get_num_users()
// Return an array with user statistics.
// $users = array( 'total_users' => nn,
// 'team-lead' => nn,
// 'administrator' => nn );
function get_num_users() {
global $LOGIN_DB_HOST, $LOGIN_DB_NAME, $LOGIN_DB_USER, $LOGIN_DB_PASS;
global $LOGIN_DB_TABLE, $LOGIN_DB_ID_COL, $LOGIN_DB_PERM_COL;
global $USER_PERMS;
$users = array( 'total_users' => 0,
'team-lead' => 0,
'administrator' => 0 );
$login_db_connection = mysql_init_connect( $LOGIN_DB_HOST, $LOGIN_DB_NAME, $LOGIN_DB_USER, $LOGIN_DB_PASS );
$result = mysql_get_rows( $LOGIN_DB_TABLE, $LOGIN_DB_ID_COL . ',' . $LOGIN_DB_PERM_COL, NULL, NULL, NULL, $login_db_connection );
$users['total_users'] = mysql_num_rows( $result );
while ( $row = mysql_fetch_row($result) ) {
if ( $row[1] == $USER_PERMS['team-lead'] ) {
$users['team-lead']++;
}
elseif ( $row[1] == $USER_PERMS['administrator'] ) {
$users['administrator']++;
}
}
// mysql_close( $login_db_connection );
return $users;
}
// Function: get_num_cases()
// Returns an array with case information.
// $cases = array ( 'total_cases' => nn,
// 'open' => nn,
// 'closed' => nn );
function get_num_cases() {
global $db_connection;
$cases = array ( 'total_cases' => 0,
'open' => 0,
'closed' => 0 );
$result = mysql_get_rows( 'reportsdb_cases', 'case_open', NULL, NULL, NULL, $db_connection );
$cases['total_cases'] = mysql_num_rows( $result );
while ( $row = mysql_fetch_row($result) ) {
if ( $row[0] == 'open' ) {
$cases['open']++;
}
elseif ( $row[0] == 'closed' ) {
$cases['closed']++;
}
}
return $cases;
}
// Function: get_num_reports()
// Returns an array with case information.
// $reports = array ( 'total_reports' => nn,
// 'published' => nn,
// 'unpublished' => nn );
function get_num_reports() {
global $db_connection;
$reports = array ( 'total_reports' => 0,
'published' => 0,
'unpublished' => 0 );
$result = mysql_get_rows( 'reportsdb_reports', 'report_state', NULL, NULL, NULL, $db_connection );
$reports['total_reports'] = mysql_num_rows( $result );
while ( $row = mysql_fetch_row($result) ) {
if ( $row[0] == 'published' ) {
$reports['published']++;
}
elseif ( $row[0] == 'unpublished' ) {
$reports['unpublished']++;
}
}
return $reports;
}
// Function: geomag_stats()
// Output array containing geomagnetic statistics.
// The status elements are not initialized ahead of time. It's easier this way,
// if there are no cases then we can just return an empty array.
function geomag_stats() {
global $db_connection;
$geomag_stats = array( 'Quiet' => 0,
'Unsettled' => 0,
'G1 Storm' => 0,
'G2 Storm' => 0,
'>G2 Storm' => 0 );
$data = mysql_get_rows( 'reportsdb_reports', 'geomag_summary', NULL, NULL, NULL, $db_connection );
if ( mysql_num_rows($data) == 0 ) {
return $geomag_stats;
}
while ( $row = mysql_fetch_row($data) ) {
if ( $row[0] == 'Very Quiet' || $row[0] == 'Quiet' ) {
$geomag_stats['Quiet']++;
}
elseif ( $row[0] == 'Semi-Quiet' || $row[0] == 'Unsettled' ) {
$geomag_stats['Unsettled']++;
}
elseif ( $row[0] == 'G1 Storm' ) {
$geomag_stats['G1 Storm']++;
}
elseif ( $row[0] == 'G2 Storm' ) {
$geomag_stats['G2 Storm']++;
}
else {
if ( preg_match('/^G[345]\s/', $row[0]) ) {
$geomag_stats['>G2 Storm']++;
}
}
}
return $geomag_stats;
}
// Function: xray_stats()
// Output array containing xray statistics.
// The status elements are not initialized ahead of time. It's easier this way,
// if there are no cases then we can just return and empty array.
function xray_stats() {
global $db_connection;
$xray_stats = array( '>X30 Class (R5)' => 0,
'X20 Class (R5)' => 0,
'X10 Class (R4)' => 0,
'X Class (R3)' => 0,
'M5 Class (R2)' => 0,
'M Class (R1)' => 0,
'C Class (Active)' => 0,
'B Class Flare (Normal)' => 0,
'<B Class (Normal)' => 0 );
$data = mysql_get_rows( 'reportsdb_reports', 'xray_summary', NULL, NULL, NULL, $db_connection );
if ( mysql_num_rows($data) == 0 ) {
return $xray_stats;
}
while ( $row = mysql_fetch_row($data) ) {
if ( $row[0] == '>X30 Class (R5)' ) {
$xray_stats['>X30 Class (R5)']++;
}
elseif ( $row[0] == 'X20 Class (R5)' ) {
$xray_stats['X20 Class (R5)']++;
}
elseif ( $row[0] == 'X10 Class (R4)' ) {
$xray_stats['X10 Class (R4)']++;
}
elseif ( $row[0] == 'X Class (R3)' ) {
$xray_stats['X Class (R3)']++;
}
elseif ( $row[0] == 'M5 Class (R2)' ) {
$xray_stats['M5 Class (R2)']++;
}
elseif ( $row[0] == 'M Class (R1)' ) {
$xray_stats['M Class (R1)']++;
}
elseif ( $row[0] == 'C Class (Active)' ) {
$xray_stats['C Class (Active)']++;
}
elseif ( $row[0] == 'B Class Flare (Normal)' ) {
$xray_stats['B Class Flare (Normal)']++;
}
elseif ( $row[0] == '<B Class (Normal)' ) {
$xray_stats['<B Class (Normal)']++;
}
}
return $xray_stats;
}
?>