Overview\n"; $sql = "SELECT system, COUNT(jobid) AS jobs, SUM(".cpuhours($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS cpuhours, SUM(".charges($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS charges, NULL AS pct_util, COUNT(DISTINCT(username)) AS users, COUNT(DISTINCT(groupname)) AS groups, COUNT(DISTINCT(account)) AS accounts FROM Jobs WHERE ( ".sysselect($_POST['system'])." ) AND ( ".dateselect($_POST['datelogic'],$_POST['start_date'],$_POST['end_date'])." ) GROUP BY system ORDER BY ".$_POST['order']." DESC"; #echo "
\n".$sql."
\n"; echo "\n"; echo "\n"; ob_flush(); flush(); $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } while ($result->fetchInto($row)) { $data=array(); $rkeys=array_keys($row); echo ""; foreach ($rkeys as $rkey) { if ( $row[$rkey]==NULL ) { $ndays=ndays($db,$row[0],$_POST['start_date'],$_POST['end_date']); if ( $ndays[1]>0 ) { $data[$rkey]=sprintf("%6.2f",100.0*$row[2]/$ndays[1]); } else { $data[$rkey]="N/A"; } } else { $data[$rkey]=$row[$rkey]; } # if a float, format appropriately if ( preg_match("/^-?\d*\.\d+$/",$data[$rkey])==1 ) { echo ""; } # if an int, format appropriately else if ( preg_match("/^-?\d+$/",$data[$rkey])==1 ) { echo ""; } # otherwise print verbatim else { echo ""; } } echo "\n"; ob_flush(); flush(); } if ( $_POST['system']=="%" ) { $sql = "SELECT 'TOTAL', COUNT(jobid) AS jobs, SUM(".cpuhours($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS cpuhours, SUM(".charges($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS charges, 'N/A' AS pct_util, COUNT(DISTINCT(username)) AS users, COUNT(DISTINCT(groupname)) AS groups, COUNT(DISTINCT(account)) AS accounts FROM Jobs WHERE system LIKE '".$_POST['system']."' AND ( ".dateselect($_POST['datelogic'],$_POST['start_date'],$_POST['end_date'])." )"; $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } while ($result->fetchInto($row)) { $rkeys=array_keys($row); echo ""; foreach ($rkeys as $rkey) { $data[$rkey]=array_shift($row); # if a float, format appropriately if ( preg_match("/^-?\d*\.\d+$/",$data[$rkey])==1 ) { echo ""; } # if an int, format appropriately else if ( preg_match("/^-?\d+$/",$data[$rkey])==1 ) { echo ""; } # otherwise print verbatim else { echo ""; } } echo "\n"; ob_flush(); flush(); } } echo "
systemjobscpuhourscharges%utilusersgroupsaccounts
".number_format(floatval($data[$rkey]),4)."
".number_format(floatval($data[$rkey]))."
".$data[$rkey]."
".number_format($data[$rkey],4)."
".number_format($data[$rkey])."
".$data[$rkey]."
\n"; # by institution # NOTE By-institution jobstats involves site-specific logic. You may # want to comment out the following statement. $inst_summary=true; if ( isset($_POST['institution']) && isset($inst_summary) && $inst_summary==true ) { echo "

Usage By Institution

\n"; if ( isset($_POST['table']) ) { $result=get_metric($db,$_POST['system'],'institution','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_table($result,'institution','usage'); } if ( isset($_POST['csv']) ) { $result=get_metric($db,$_POST['system'],'institution','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_csv($result,'institution','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); } if ( isset($_POST['xls']) ) { $result=get_metric($db,$_POST['system'],'institution','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_xls($result,'institution','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); } if ( isset($_POST['ods']) ) { $result=get_metric($db,$_POST['system'],'institution','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_ods($result,'institution','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date']); } ob_flush(); flush(); } # by account if ( isset($_POST['account']) ) { echo "

Usage By Account

\n"; if ( isset($_POST['table']) ) { $result=get_metric($db,$_POST['system'],'account','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_table($result,'account','usage'); } if ( isset($_POST['csv']) ) { $result=get_metric($db,$_POST['system'],'account','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_csv($result,'account','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); } if ( isset($_POST['xls']) ) { $result=get_metric($db,$_POST['system'],'account','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_xls($result,'account','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date']); } if ( isset($_POST['ods']) ) { $result=get_metric($db,$_POST['system'],'account','usage',$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } metric_as_ods($result,'account','usage',$_POST['system'],$_POST['start_date'],$_POST['end_date']); } ob_flush(); flush(); } # software usage if ( isset($_POST['software']) ) { echo "

Software Usage

\n"; $sql = "SELECT sw_app, COUNT(jobid) AS jobs, SUM(".cpuhours($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS cpuhours, SUM(".charges($db,$_POST['system'],$_POST['start_date'],$_POST['end_date'],$_POST['datelogic']).") AS charges, COUNT(DISTINCT(username)) AS users, COUNT(DISTINCT(groupname)) AS groups, COUNT(DISTINCT(account)) AS accounts FROM Jobs WHERE sw_app IS NOT NULL AND ( ".sysselect($_POST['system'])." ) AND ( ".dateselect($_POST['datelogic'],$_POST['start_date'],$_POST['end_date'])." ) GROUP BY sw_app ORDER BY ".$_POST['order']." DESC"; #echo "
\n".$sql."
\n"; $columns = array("package","jobs","cpuhours","charges","users","groups", "accounts"); if ( isset($_POST['table']) ) { $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } result_as_table($result,$columns); } if ( isset($_POST['csv']) ) { $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } result_as_csv($result,$columns,$_POST['system']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']); } if ( isset($_POST['xls']) ) { $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } result_as_xls($result,$columns,$_POST['system']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']); } if ( isset($_POST['ods']) ) { $result = db_query($db,$sql); if ( PEAR::isError($result) ) { echo "
".$result->getMessage()."
\n"; } result_as_ods($result,$columns,$_POST['system']."-software_usage-".$_POST['start_date']."-".$_POST['end_date']); } } db_disconnect($db); page_timer(); bookmarkable_url(); } else { begin_form("usage-summary.php"); virtual_system_chooser(); date_fields(); $orders=array("jobs","cpuhours","charges","users","groups"); checkboxes_from_array("Supplemental reports",array("institution","account","software")); $defaultorder="cpuhours"; pulldown("order","Order results by",$orders,$defaultorder); checkbox("Generate HTML tables for supplemental reports","table",1); checkbox("Generate CSV files for supplemental reports","csv"); checkbox("Generate Excel files for supplemental reports","xls"); checkbox("Generate ODF files for supplemental reports","ods"); end_form(); } page_footer(); ?>