init-full-0.20.4.sql
[racktables-contribs] / wattage_consumption.php
CommitLineData
fba27978
CB
1<?php
2
3//-----------------------------------------------------------------------------------
4// Wattage Consumption - written by curtisb
5//$tab['reports']['watts_per_row'] = 'Energy Per Row';
6$tab['reports']['watts_per_row'] = 'Enviromental Totals';
7$tabhandler['reports']['watts_per_row'] = 'getWattsPerRow';
8
9function getWattsPerRow ()
10{
11
12 // assertions
13 // find the needed attributes
14
15 global $nextorder;
16
17 // Was this function called with a specific row_id?
18 if (isset ($_REQUEST['row_id']))
19 {
20 assertStringArg ('row_id');
21 $row_toshow = $_REQUEST['row_id'];
22 }
23 else
24 {
25 $row_toshow = '50032';
26 }
27
28 //from renderRackspace(), interface.php:151
29 $found_racks = array();
30 $rows = array();
31 $cellfilter = getCellFilter();
32 $rackCount = 0;
33 $order = 'odd';
34 // get rackspace information
35 foreach (getRackRows() as $row_id => $row_name) {
36 $rackList = filterCellList (listCells ('rack', $row_id), $cellfilter['expression']);
37 $found_racks = array_merge($found_racks, $rackList);
38 $rows[] = array(
39 'row_id' => $row_id,
40 'row_name' => $row_name,
41 'racks' => $rackList
42 );
43 $rackCount += count($rackList);
44 }
45
46 // Main layout starts.
47 echo "<table border=0 class=objectview cellspacing=0 cellpadding=0>";
48
49 // Left portlet with list of rows.
50 echo "<tr><td class=pcleft>";
51 startPortlet ('Rack Rows (' . count ($rows) . ')');
52 echo "<table border=0 cellspacing=0 cellpadding=3 width='100%'>\n";
53 foreach ($rows as $row)
54 {
55 $row_id = $row['row_id'];
56 $row_name = $row['row_name'];
57 $rackList = $row['racks'];
58
59 echo "<tr class=row_${order}><td width='20%'></td><td class=tdleft>";
60 if (!count ($rackList))
61 {
62 echo "${row_name} (empty row)";
63 }
64 else
65 {
66 echo "<a href='" . makeHref(array('page'=>'reports', 'tab'=>'watts_per_row', 'row_id'=>$row_id)) . "'>${row_name}</a>";
67 }
68 echo "<td><tr>\n";
69 $order = $nextorder[$order];
70
71 }
72
73 echo "</td></tr>\n";
74 echo "</table><br>\n";
75 finishPortlet();
76
77 echo "</td><td class=pcright>";
78
79 // Right Portlet: Draw the racks in the selected row
80 $rowInfo = getRackRowInfo ($row_toshow);
81 $cellfilter = getCellFilter();
82 $rackList = filterCellList (listCells ('rack', $row_toshow), $cellfilter['expression']);
83
84 global $nextorder;
85 $rackwidth = getRackImageWidth() * getConfigVar ('ROW_SCALE');
86 // Maximum number of racks per row is proportionally less, but at least 1.
87 $maxPerRow = max (floor (getConfigVar ('RACKS_PER_ROW') / getConfigVar ('ROW_SCALE')), 1);
88 $rackListIdx = 0;
89 $rowTotalWattage = 0;
90 $order = 'odd';
91 startPortlet ('Racks within '. $rowInfo['name'] . ' (' . count($rackList) . ')' );
92 echo "<table border=0 cellspacing=5 align='center'><tr>";
93 foreach ($rackList as $rack)
94 {
95 $rackTotalWattage = 0;
96 // see renderRack(), interface.php:311
97 $rackData = spotEntity ('rack', $rack['id']);
98 amplifyCell ($rackData);
99 $objectChildren = getEntityRelatives ('children', 'object', $objectData['id']);
100 foreach ($rackData['mountedObjects'] as $object)
101 {
102 $objectData = spotEntity ('object', $object);
103 amplifyCell ($objectData);
104 foreach (getAttrValues ($objectData['id']) as $record)
105 {
106 if ($record['name'] == 'Wattage consuption')
107 {
108 $rackTotalWattage += $record['value'];
109 }
110 }
111 }
112 if ($rackListIdx % $maxPerRow == 0)
113 {
114 if ($rackListIdx > 0)
115 echo '</tr>';
116 echo '<tr>';
117 }
118 echo "<td align=center class=row_${order}><a href='".makeHref(array('page'=>'rack', 'rack_id'=>$rack['id']))."'>";
119 echo "<img border=0 width=${rackwidth} height=" . (getRackImageHeight ($rack['height']) * getConfigVar ('ROW_SCALE'));
120 echo " title='${rack['height']} units'";
121 echo "src='?module=image&img=minirack&rack_id=${rack['id']}'>";
122 echo "<br>${rack['name']} ($rackTotalWattage)</a></td>";
123 $order = $nextorder[$order];
124 $rackListIdx++;
125 $rowTotalWattage += $rackTotalWattage;
126 }
127
128 echo "</tr><tr><td align=center colspan=";
129 print (count($rackList));
130 echo "><br><b>The row total for attribute Wattage consuption is: $rowTotalWattage</b></td>\n";
131
132 echo "</tr></table>\n";
133 finishPortlet();
134 echo "</td></tr></table>";
135}
136
137?>