Skip to content
Snippets Groups Projects
Commit c1509fa0 authored by Thomas Lake's avatar Thomas Lake :wrench:
Browse files

Updates to shame lists

parent f3e40468
No related branches found
No related tags found
No related merge requests found
<? exec("/usr/local/bin/shame.py -a", $Shame); <? exec("/usr/local/bin/shame.py -a", $Shame);
$max=10; //SET to number of users to display
$smarty->assign('title',"The SUCS Hall of Shame"); $smarty->assign('title',"The SUCS Hall of Shame");
$o="<div style='text-align: center;'><img src=\"/images/disk.graph.php\" alt=\"pie chart of top 12 disk users\"/></div>"; //$o="<div style='text-align: center;'><img src=\"/images/disk.graph.php\" alt=\"pie chart of top 12 disk users\"/></div>";
$o.="<table align=\"center\">\n"; $o.="<table align=\"center\">\n";
$o.="\t<tr><th align=\"center\">User</th><th align=\"center\">Home Directory Size</th></tr>\n"; $o.="\t<tr><th align=\"center\">User</th><th align=\"center\">Home Directory Size</th></tr>\n";
for ( $i=1 ; $i < 13 /*(count($Shame) - 1)*/; $i++) for ( $i=1 ; $i < 13 /*(count($Shame) - 1)*/; $i++)
...@@ -10,12 +10,42 @@ ...@@ -10,12 +10,42 @@
if ($size > 0) if ($size > 0)
$o.="\t<tr><td align=\"center\">$user</td><td align=\"center\">${size}B</td></tr>\n"; $o.="\t<tr><td align=\"center\">$user</td><td align=\"center\">${size}B</td></tr>\n";
} }
exec("df -h /home",$dfraw); exec("df -m /home",$dfraw);
$dfout=explode(" ",$dfraw[1]); $dfout=explode(" ",$dfraw[1]);
$o.="\t<tr><td align=\"center\" colspan=\"2\">".$dfout[8]." used of ".$dfout[7]. " (".$dfout[9]." available)</td></tr>\n"; $o.="\t<tr><td align=\"center\" colspan=\"2\">".floor($dfout[8]/1024)."GB used of ".floor($dfout[7]/1024). "GB (".floor($dfout[10]/1024)."GB available)</td></tr>\n";
$o.="</table>\n"; $o.="</table>\n";
$o.=$Shame[count($Shame) - 1]; $o.=$Shame[count($Shame) - 1];
$o.="<br />\n"; $o.="<br />\n";
//readfile("tail.html"); //readfile("tail.html");
$smarty->assign('body', $o); $out="<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
<script type=\"text/javascript\">
google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'User');
data.addColumn('number', 'Megabytes in use');
data.addRows(".(count($Shame) - 1).");\n";
for( $i=0; $i<(count($Shame) - 3); $i++ ){
list($u,$d)=parseLine($Shame[$i+1]);
$out.="data.setValue(".($i+1).", 0, '".$u."');\n";
$out.="data.setValue(".($i+1).", 1,".$d.");\n";
}
$others=0;
for ( $i=$max; $i<count($data); $i++ ) {
list($u,$d)=parseLine($Shame[$i+1]);
$others+=$d;
}
$out.="data.setValue(0, 0, 'Free Space');\ndata.setValue(0,1,".$dfout[10]." );\n";
$out.="\t\tvar chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 500, height: 360, backgroundColor: 'none', is3D: true, title: 'Disk Usage',sliceVisibilityThreshold: 1/180});
}
</script>";
$out.="<div id='chart_div' align='center'></div>";
$smarty->assign('body', ($out.$o));
function parseLine($l){
$fields=explode("|",preg_filter("/[ ]+/","|",$l));
return array(trim($fields[2]),trim(str_replace("M","",$fields[3])));
}
?> ?>
...@@ -7,7 +7,7 @@ $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); ...@@ -7,7 +7,7 @@ $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $sucsDB->Execute("select username, sum(pages) as pages from printer where username != 'old' group by username order by sum(pages) desc"); $res = $sucsDB->Execute("select username, sum(pages) as pages from printer where username != 'old' group by username order by sum(pages) desc");
$num = $res->RecordCount(); $num = $res->RecordCount();
for ($i=0;$i<$num;$i++) { for ($i=0;$i<$num;$i++) {
$row[$i] = $res->FetchRow(); $row[$i] = $res->FetchRow();
if ($i < 12) if ($i < 12)
{ {
$item[]=$row[$i]['username']; $item[]=$row[$i]['username'];
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
* Ported from old site by tswsl1989 * Ported from old site by tswsl1989
* *
*/ */
$max=10; //Set this to number of users to display in chart
$smarty->assign('title',"Printer Statistics"); $smarty->assign('title',"Printer Statistics");
$sucsDB = NewADOConnection('postgres8'); $sucsDB = NewADOConnection('postgres8');
$sucsDB->Connect('dbname=sucs user=apache'); $sucsDB->Connect('dbname=sucs user=apache');
$sucsDB->SetFetchMode(ADODB_FETCH_ASSOC); $sucsDB->SetFetchMode(ADODB_FETCH_ASSOC);
$out="<img src=\"/images/printer.graph.php\" alt=\"pie chart of top 12 printer users\"/>"; // $out="<img src=\"/images/printer.graph.php\" alt=\"pie chart of top 12 printer users\"/>";
$table="<table border=1 cellpadding=3>\n<tr>\n<th>Username</th>\n<th>Pages</th>\n<th>Projected Monthly Usage</th>\n<th>Printed This Month</th>\n<th>What it would cost in the library</th></tr>\n"; $table="<table border=1 cellpadding=3>\n<tr>\n<th>Username</th>\n<th>Pages</th>\n<th>Projected Monthly Usage</th>\n<th>Printed This Month</th>\n<th>What it would cost in the library</th></tr>\n";
//pull in all the current users (ie not old) who have printed stuff //pull in all the current users (ie not old) who have printed stuff
...@@ -112,16 +113,39 @@ $table.="<tr align=\"center\">\n\t<th>Total</th>\n\t<th>$total</th>\n\t<th>".rou ...@@ -112,16 +113,39 @@ $table.="<tr align=\"center\">\n\t<th>Total</th>\n\t<th>$total</th>\n\t<th>".rou
$table.="</table>\n"; $table.="</table>\n";
//output the dates of the first and last prints recorded //output the dates of the first and last prints recorded
$out.="<p>First Data - ".$date['first'][weekday].", ".$date['first'][mday]." ".$date['first'][month]." ".$date['first'][year].", at ".$date['first'][hours].":".$date['first'][minutes].":".$date['first'][seconds]."<br />"; $out.="<script type=\"text/javascript\" src=\"https://www.google.com/jsapi\"></script>
$out.="Last Data - ".$date['last'][weekday].", ".$date['last'][mday]." ".$date['last'][month]." ".$date['last'][year].", at ".$date['last'][hours].":".$date['last'][minutes].":".$date['last'][seconds]."</p>"; <script type=\"text/javascript\">
google.load(\"visualization\", \"1\", {packages:[\"corechart\"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'User');
data.addColumn('number', 'Pages Printed');
data.addRows(".($max+2).");\n";
for( $i=0; $i<($max+1); $i++ ){
$out.="data.setValue(".($i).", 0, '".$data[$i]['username']."');\n";
$out.="data.setValue(".($i).", 1,".$data[$i]['pages'].");\n";
}
$others=0;
for ( $i=$max; $i<count($data); $i++ ) {
$others+=$data[$i]['pages'];
}
$out.="data.setValue(".($max+1).", 0, 'Others');\ndata.setValue(".($max+1).",1, $others);\n";
$out.="\t\tvar chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 500, height: 360, backgroundColor: 'none', is3D: true, title: 'Printer Usage'});
}
</script>";
$out.="<div id=\"chart_div\" style=\"background: none;\"></div>";
$out.="<p>First Data - ".$date['first'][weekday].", ".$date['first'][mday]." ".$date['first'][month]." ".$date['first'][year].", at ".sprintf("%02d:%02d:%02d",$date['first'][hours],$date['first'][minutes],$date['first'][seconds])."<br />";
$out.="Last Data - ".$date['last'][weekday].", ".$date['last'][mday]." ".$date['last'][month]." ".$date['last'][year].", at ".sprintf("%02d:%02d:%02d",$date['last'][hours],$date['last'][minutes],$date['last'][seconds])."</p>";
//do some silly maths to work out lots of silly things //do some silly maths to work out lots of silly things
$paperarea = round(0.21*0.297*$total,3); //area of paper $paperarea = round(0.21*0.297*$total,3); //area of paper
$paperweight = round($paperarea*.08, 3); //how much that would weigh $paperweight = round($paperarea*.08, 3); //how much that would weigh
$numtrees = round($paperweight/730.296, 6); //*very* roughly how many trees that would be $numtrees = round($paperweight/730.296, 6); //*very* roughly how many trees that would be
$cost = round(0.1*$total,2); $cost = sprintf("£%01.2f",round(0.1*$total,2));
$out.="<p>That's ".$paperarea."m<sup>2</sup> of paper, weighing ".$paperweight."kg!<br>\n"; $out.="<p>That's ".$paperarea."m<sup>2</sup> of paper, weighing ".$paperweight."kg!<br>\n";
$out.="This is equivalent to approximately ".$numtrees." trees.<br>\n"; $out.="This is equivalent to approximately ".$numtrees." trees.<br>\n";
$out.="That would have cost our members a grand total of £".$cost." if it were printed in the library.. not bad for £5!"; $out.="That would have cost our members a grand total of ".$cost." if it were printed in the library.. not bad for £5!";
//done //done
$out.="<p>Note: The number of pages is the number spooled and may be more than the actual number printed</p>"; $out.="<p>Note: The number of pages is the number spooled and may be more than the actual number printed</p>";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment