-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathglobaldb_stats.php
578 lines (473 loc) · 17 KB
/
globaldb_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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
<?php
/*
* globaldb_stats.php
*
* A home page for generating/viewing/exporting global database stats
*
*/
include_once 'checkinstance.php';
if ( ( $_SESSION['userlevel'] != 4 ) &&
( $_SESSION['userlevel'] != 5 ) ) // global admins only
{
header('Location: index.php');
exit();
}
include 'config.php';
include 'current_db_list.php';
include 'lib/utility.php';
$v1user = "us3php";
$v2user = "lims3_admin";
$v1pass = $configs[ 'us3php' ][ 'password' ];
$v2pass = $configs[ 'limsadmin' ][ 'password' ];
$global_db = 'uslims3_global';
// Specific DB setup for functions in this file
$conn1 = mysqli_connect( $dbhost, $v1user, $v1pass, $dbname )
or die("Could not connect to $dbhost, $dbname \n");
$conn2 = mysqli_connect( $dbhost, $v2user, $v2pass, $global_db )
or die("Could not connect to $dbhost, $global_db\n");
// Make sure output buffering is off and cleared for this page
while (ob_get_level())
ob_end_flush();
if (ob_get_length() === false)
ob_start();
$cluster_list = array(
'ls5.tacc.utexas.edu' => 'lonestar5',
'stampede2.tacc.xsede.org' => 'stampede2',
'comet.sdsc.edu' => 'comet',
'juwels.fz-juelich.de' => 'juwels',
'uslims.uleth.ca' => 'demeler3'
);
// Figure out which clusters were selected
$selected_clusters = array();
if ( $_POST )
{
foreach ( $_POST as $key => $value )
{
// HTML translates the periods into underscores
$key = implode( '.', explode( '_', $key ) );
if ( array_key_exists( $key, $cluster_list ) )
$selected_clusters[$key] = $cluster_list[$key];
}
}
else
$selected_clusters = $cluster_list;
// Start displaying page
$page_title = 'Global DB Statistics';
$js = 'js/export.js';
include 'header.php';
?>
<!-- Begin page content -->
<div id='content'>
<h1 class="title">Global DB Statistics</h1>
<!-- Place page content here -->
<?php
// Generate global data or view/export report
if (isset($_POST['generate']))
generate();
else if ( isset($_POST['by_quarter']) )
by_quarter();
// Menu and general stuff
$start_year_menu = start_year_menu();
// Develop cluster checkboxes
$cluster_boxes = '';
foreach ( $cluster_list as $key => $value )
{
$checked = ( array_key_exists( $key, $selected_clusters ) )
? " checked='checked'" : "" ;
$cluster_boxes .= " <tr><td><input type='checkbox' name='$key' \n" .
" $checked />$key</td></tr>\n";
}
$count_boxes = count( $cluster_list ) + 1;
echo <<<HTML
<form action="{$_SERVER['PHP_SELF']}" method='post'>
<fieldset>
<label>Select from the following information</label>
<table cellspacing='10' cellpadding='0' class='noborder'>
<tr><th>Starting year for report:</th>
<td>$start_year_menu</td>
</tr>
<tr><th rowspan='$count_boxes'>Clusters to include:</th></tr>
$cluster_boxes
<tr><th rowspan='2'>Actions:</th>
<td><input type='submit' name='generate' value='Generate Global DB' />
(Just do this once.)</td>
</tr>
<tr><td><input type='submit' name='by_quarter' value='Quarterly Report' /></td>
</tr>
</table>
</fieldset>
</form>
HTML;
?>
</div>
<?php
include 'footer.php';
exit();
// Function to create a starting year dropdown list box
function start_year_menu()
{
$earliest_year = 2011;
$current_year = date( 'Y' );
// Keep previously-selected year, if possible
if ( isset( $_POST['start_year'] ) )
$start_year = $_POST['start_year'];
else
$start_year = $current_year - 1;
$menu = "<select name='start_year' size='1'>\n";
for ( $year = $earliest_year; $year <= $current_year; $year++ )
{
$selected = ( $year == $start_year ) ? " selected='selected'" : "";
$menu .= " <option value='$year'$selected>$year</option>\n";
}
$menu .= "</select>\n";
return $menu;
}
/*
* Function to copy selected db information from different individual lims
* tables into a temporary global database
*/
function generate()
{
global $dblist;
global $conn1, $conn2;
global $dbhost;
// We probably need more time for this one
set_time_limit(600);
$global_db = 'uslims3_global';
// Delete existing records from global DB
$query = "DELETE FROM submissions ";
mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
$query = "DELETE FROM investigators ";
mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
echo "<pre>\n";
// Now get info from each database and add it
foreach ( $dblist as $db )
{
echo "Using $db.";
$query = "SELECT q.HPCAnalysisRequestID, startTime, endTime, " .
"CPUTime, clusterName, CPUCount, " .
"i.personID AS investigatorID, s.personID AS submitterID, " .
"CONCAT(i.lname, ', ', i.fname) AS investigatorName, " .
"CONCAT(s.lname, ', ', s.fname) AS submitterName " .
"FROM HPCAnalysisRequest q, HPCAnalysisResult r, " .
"people i, people s " .
"WHERE q.HPCAnalysisRequestID = r.HPCAnalysisRequestID " .
"AND investigatorGUID = i.personGUID " .
"AND submitterGUID = s.personGUID " .
"AND clusterName IS NOT NULL "; // These are canceled jobs
mysqli_select_db( $conn1, $db )
or die("Could not select database $db on $dbhost.");
$result = mysqli_query( $conn1, $query )
or die("Query failed : $query\n" . mysqli_error($conn1));
echo ".";
ob_flush();
flush();
// Now update the global database
while ( $row = mysqli_fetch_array($result) )
{
// Make variables
foreach ($row as $key => $value )
{
$$key = $value;
}
$investigatorName = preg_replace( "/D\'/", "D", $investigatorName );
$submitterName = preg_replace( "/D\'/", "D", $submitterName );
$query = "INSERT INTO submissions " .
"SET HPCAnalysis_ID = $HPCAnalysisRequestID, " .
"db = '$db', " .
"DateTime = '$startTime', " .
"EndDateTime = '$endTime', " .
"CPUTime = '$CPUTime', " .
"Cluster_Name = '$clusterName', " .
"CPU_Number = $CPUCount, " .
"InvestigatorID = $investigatorID, " .
"Investigator_Name = '$investigatorName', " .
"SubmitterID = $submitterID, " .
"Submitter_Name = '$submitterName' ";
mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
}
echo ".";
ob_flush();
flush();
// Now a table of investigator statistics
$query = "SELECT personID, " .
"CONCAT(lname, ', ', fname) AS investigatorName, " .
"email, signup, lastLogin, userlevel " .
"FROM people " .
"ORDER BY lname, fname ";
mysqli_select_db( $conn1, $db )
or die("Could not select database $db on $dbhost, $db.");
$result = mysqli_query( $conn1, $query )
or die("Query failed : $query\n" . mysqli_error($conn1));
echo ".";
ob_flush();
flush();
// Now the global database
while ( $row = mysqli_fetch_array($result) )
{
// Make variables
foreach ($row as $key => $value )
{
$$key = $value;
}
$investigatorName = preg_replace( "/D\'/", "D", $investigatorName );
$query = "INSERT INTO investigators " .
"SET InvestigatorID = $personID, " .
"Investigator_Name = '$investigatorName', " .
"db = '$db', " .
"Email = '$email', " .
"Signup = '$signup', " .
"LastLogin = '$lastLogin', " .
"Userlevel = '$userlevel' ";
mysqli_query( $conn1, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
echo ".";
ob_flush();
flush();
}
echo "\n";
}
echo "</pre>\n";
}
/*
* Produces a table with quarterly statistics report information
* on individual cluster usage. Uses HPC result tables
* across all databases
* Be sure to use the generate() function first, to create a global
* database with all the information we need.
*
*/
function by_quarter()
{
global $conn2, $dbhost;
global $page_title;
global $selected_clusters;
$end_year = date( 'Y' );
// Keep selected year, if possible
if ( isset( $_POST['start_year'] ) )
$start_year = $_POST['start_year'];
else
$start_year = $end_year - 1;
$cluster_comma_list = "'" . implode( "', '", array_keys( $selected_clusters ) ) . "'";
$quarters = array( '', '1st', '2nd', '3rd', '4th' );
$super_tot = 0;
$column_count = count( $selected_clusters ) + 5;
echo <<<HTML
<table cellpadding='10' cellspacing='0' class='style1'>
<thead>
<tr><th colspan='$column_count'>Cluster Usage Report ($start_year - $end_year)</th></tr>
</thead>
<tfoot>
<tr><td colspan='$column_count'><input type='button' value='Export'
onclick='export_file();' />
</td></tr>
</tfoot>
<tbody>
HTML;
// For export file
$export = array();
$counter = 0;
for ( $year = $start_year; $year <= $end_year; $year++ )
{
// Column headings
echo " <tr style='background-color:#9CC4E4;'><th>Quarter/<br />\n" .
" $year</th>\n";
$export[$counter]['Quarter'] = $year;
foreach ( $selected_clusters as $cluster => $shortname )
{
echo " <th>$shortname</th>\n";
$export[$counter][$shortname] = '';
}
// The last few columns
echo <<<HTML
<th>Total</th>
<th>#Investigators</th>
<th>#Submitters</th>
<th>#Jobs</th>
</tr>
HTML;
$export[$counter]['Total'] = '';
$export[$counter]['Investigators'] = '';
$export[$counter]['Submitters'] = '';
$export[$counter]['Jobs'] = '';
$counter++;
$grand_tot = 0;
for ( $quarter = 1; $quarter <= 4; $quarter++)
{
switch ( $quarter )
{
case 1 :
$start = "$year-01-01";
$end = "$year-03-31";
break;
case 2 :
$start = "$year-04-01";
$end = "$year-06-30";
break;
case 3 :
$start = "$year-07-01";
$end = "$year-09-30";
break;
case 4 :
$start = "$year-10-01";
$end = "$year-12-31";
break;
default :
break;
}
// Start a row
$quarter_sum = 0;
echo " <tr><th>{$quarters[$quarter]}</th>\n";
$export[$counter]['Quarter'] = $quarters[$quarter];
foreach ( $selected_clusters as $cluster => $shortname )
{
// CPUTime is in seconds, so 60 * 60 = hours
$query = "SELECT SUM(CPUTime*CPU_Number)/3600.0 " .
"FROM submissions " .
"WHERE Cluster_Name = '$cluster' " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
list($time) = mysqli_fetch_array($result);
$time = ( $time == NULL ) ? 0 : $time;
$quarter_sum += $time;
echo " <td>" . round($time, 1) . "</td>\n";
$export[$counter][$shortname] = round($time, 1);
}
// Now let's get investigator and submitter stats
$query = "SELECT COUNT(DISTINCT Investigator_Name), " .
"COUNT(DISTINCT Submitter_Name), " .
"COUNT(DISTINCT HPCAnalysis_ID) " .
"FROM submissions " .
"WHERE Cluster_Name IN ( $cluster_comma_list ) " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
$grand_tot += $quarter_sum;
$quarter_sum_rounded = round( $quarter_sum, 1 );
list($inv_count, $sub_count, $job_count) = mysqli_fetch_array($result);
echo <<<HTML
<td>$quarter_sum_rounded</td>
<td>$inv_count</td>
<td>$sub_count</td>
<td>$job_count</td>
</tr>
HTML;
$export[$counter]['Total'] = $quarter_sum_rounded;
$export[$counter]['Investigators'] = $inv_count;
$export[$counter]['Submitters'] = $sub_count;
$export[$counter]['Jobs'] = $job_count;
$counter++;
}
// In this case it's probably easier just to do another query for totals
$start = "$year-01-01";
$end = "$year-12-31";
echo " <tr><th>Tot</th>\n";
$export[$counter]['Quarter'] = 'Tot';
foreach ( $selected_clusters as $cluster => $shortname)
{
// CPUTime is in seconds, so 60 * 60 = hours
$query = "SELECT SUM(CPUTime*CPU_Number)/3600.0 " .
"FROM submissions " .
"WHERE Cluster_Name = '$cluster' " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
list($time) = mysqli_fetch_array($result);
$time = ( $time == NULL ) ? 0 : $time;
echo " <th>" . round($time, 1) . "</th>\n";
$export[$counter][$shortname] = round($time, 1);
}
// Now let's get investigator and submitter stats
$query = "SELECT COUNT(DISTINCT Investigator_Name), " .
"COUNT(DISTINCT Submitter_Name), " .
"COUNT(DISTINCT HPCAnalysis_ID) " .
"FROM submissions " .
"WHERE Cluster_Name IN ( $cluster_comma_list ) " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
list($inv_count, $sub_count, $job_count) = mysqli_fetch_array($result);
$grand_tot_rounded = round( $grand_tot, 1 );
echo <<<HTML
<th>$grand_tot_rounded</th>
<th>$inv_count</th>
<th>$sub_count</th>
<th>$job_count</th>
</tr>
HTML;
$export[$counter]['Total'] = $grand_tot_rounded;
$export[$counter]['Investigators'] = $inv_count;
$export[$counter]['Submitters'] = $sub_count;
$export[$counter]['Jobs'] = $job_count;
$super_tot += $grand_tot;
$counter++;
}
// Now let's get a super-grant total from all years
$start = "$start_year-01-01";
$end = "$end_year-12-31";
echo " <tr><th>All</th>\n";
$export[$counter]['Quarter'] = 'All';
foreach ( $selected_clusters as $cluster => $shortname )
{
// CPUTime is in seconds, so 60 * 60 = hours
$query = "SELECT SUM(CPUTime*CPU_Number)/3600.0 " .
"FROM submissions " .
"WHERE Cluster_Name = '$cluster' " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
list($time) = mysqli_fetch_array($result);
$time = ( $time == NULL ) ? 0 : $time;
echo " <th>" . round($time, 1) . "</th>\n";
$export[$counter][$shortname] = round($time, 1);
}
// Now let's get investigator and submitter stats
$query = "SELECT COUNT(DISTINCT Investigator_Name), " .
"COUNT(DISTINCT Submitter_Name), " .
"COUNT(DISTINCT HPCAnalysis_ID) " .
"FROM submissions " .
"WHERE Cluster_Name IN ( $cluster_comma_list ) " .
"AND DateTime >= '$start 00:00:00' " .
"AND DateTime <= '$end 23:59:59' ";
$result = mysqli_query( $conn2, $query )
or die("Query failed : $query\n" . mysqli_error($conn2));
list($inv_count, $sub_count, $job_count) = mysqli_fetch_array($result);
$super_tot_rounded = round( $super_tot, 1 );
echo <<<HTML
<th>$super_tot_rounded</th>
<th>$inv_count</th>
<th>$sub_count</th>
<th>$job_count</th>
</tr>
HTML;
echo "</tbody>\n" .
"</table>\n";
$export[$counter]['Total'] = $super_tot_rounded;
$export[$counter]['Investigators'] = $inv_count;
$export[$counter]['Submitters'] = $sub_count;
$export[$counter]['Jobs'] = $job_count;
$notes = <<<HTML
<h4>Notes:</h4>
<ul><li>Time is in CPU - Hours</li>
<li>The totals at the bottom of the investigators and submitters columns
don’t necessarily add up to the total of the numbers in the
columns. This is because the total is the number of unique individuals.
In other words, some people might have submitted jobs in more than
one quarter, but the total would only count them once.</li>
</ul>
HTML;
echo $notes;
//$export[$counter]['Notes'] = strip_tags( $notes );
$_SESSION['exporttitle'] = $page_title;
$_SESSION['exportfile'] = $export;
}
?>