Added ADSL Stat report

This commit is contained in:
Deon George 2012-05-13 09:29:44 +10:00
parent 1d2d589ff5
commit 0eecfe8abd
8 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1 @@
<td><?php echo $count; ?></td><td><?php echo $percent; ?></td>

View File

@ -0,0 +1 @@
</tr>

View File

@ -0,0 +1,4 @@
<tr class="list-data">
<td><?php echo $speed; ?></td>
<td><?php echo $count; ?></td>
<td><?php echo $percent; ?></td>

View File

@ -0,0 +1 @@
</table>

View File

@ -0,0 +1,3 @@
<table class="list-box-left">
<tr class="list-head">
<th><?php echo $name; ?></th>

View File

@ -0,0 +1 @@
<th><?php echo $name; ?></th><th>%</th>

View File

@ -0,0 +1 @@
</tr>

View File

@ -13,6 +13,7 @@
class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'autolist'=>FALSE, // @todo To Change
'adslstat'=>TRUE,
'list'=>TRUE,
'listbycheckout'=>TRUE,
'listadslbilling'=>TRUE,
@ -680,7 +681,76 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'title'=>sprintf('%s: %s',$so->id(),$so->service_name()),
'body'=>$output,
));
}
public function action_adslstat() {
$output = '';
$svs = ORM::factory('service')->list_bylistgroup('ADSL');
$stats = array();
// @todo This needs to be configurable.
$traffic = array(1000,2000,5000,10000,25000,50000,75000,100000);
$ts = 0;
foreach ($svs as $a=>$so) {
// Number of services
if (! isset($stats[$so->product->plugin()->speed]['c']))
$stats[$so->product->plugin()->speed]['c'] = 0;
$stats[$so->product->plugin()->speed]['c']++;
$ts++;
// Amount of traffic
$t = array_sum($so->plugin()->traffic_lastmonth(FALSE));
$a = 0;
foreach (array_reverse($traffic) as $i) {
if ($i < $t)
break;
$a = $i;
}
if (! isset($stats[$so->product->plugin()->speed]['d'][$a]))
$stats[$so->product->plugin()->speed]['d'][$a] = 0;
$stats[$so->product->plugin()->speed]['d'][$a]++;
}
if (count($stats)) {
$output .= View::factory($this->viewpath().'/head')
->set('name','SPEED');
$output .= View::factory($this->viewpath().'/head_data')
->set('name','#');
foreach ($traffic as $i)
$output .= View::factory($this->viewpath().'/head_data')
->set('name',$i);
$output .= View::factory($this->viewpath().'/head_data')
->set('name','Other');
$output .= View::factory($this->viewpath().'/head_end');
foreach ($stats as $speed => $details) {
$output .= View::factory($this->viewpath().'/body_head')
->set('count',$details['c'])
->set('percent',sprintf('%2.1f',$details['c']/$ts*100))
->set('speed',$speed);
foreach ($traffic as $i) {
$output .= View::factory($this->viewpath().'/body_data')
->set('count',$c=isset($details['d'][$i]) ? $details['d'][$i] : 0)
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
}
$output .= View::factory($this->viewpath().'/body_data')
->set('count',$c=isset($details['d'][0]) ? $details['d'][0] : 0)
->set('percent',sprintf('%2.1f',$c/$details['c']*100));
$output .= View::factory($this->viewpath().'/body_end');
}
$output .= View::factory($this->viewpath().'/foot');
}
Block::add(array(
'title'=>_('ADSL Traffic Summary Stats - Last Month'),
'body'=>$output,
));
}
}
?>