Overhaul ADSL traffic reporting/graphing

This commit is contained in:
Deon George
2013-11-14 22:50:35 +11:00
parent 158a4f9e47
commit e01d37244c
33 changed files with 891 additions and 471 deletions

View File

@@ -14,68 +14,64 @@ class Controller_Reseller_Service_Adsl extends Controller_Service {
'list'=>TRUE,
);
private function consoltraffic($svs,$date) {
$data = array();
private function consoltraffic($period) {
$result = array();
foreach ($svs as $so) {
$c = array();
foreach ($so->plugin()->get_traffic_data_monthly($date) as $metric => $ma) {
foreach ($ma as $month => $traffic) {
// Only count the service once, not for each metric.
if (! isset($c[$month])) {
if (isset($data['svs'][$month]))
$data['svs'][$month] += 1;
else
$data['svs'][$month] = 1;
$periodstart = mktime(0,0,0,date('m',$period),1,date('Y',$period)-1);
$c[$month] = 1;
}
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
->select(array('date_format(date,\'%y-%m\')','month'))
->selectsummetric()
->join('service__adsl','INNER')
->on('service__adsl.service_username','=','service_plugin_adsl_traffic.service')
->on('service__adsl.site_id','=','service_plugin_adsl_traffic.site_id')
->join('service','INNER')
->on('service__adsl.service_id','=','service.id')
->on('service__adsl.site_id','=','service.site_id')
->where_authorised($this->ao,'service.account_id')
->and_where('date','>=',date('Y-m-d',$periodstart))
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
->group_by('date_format(date,\'%Y-%m\')');
if (isset($data['data'][$metric][$month]))
$data['data'][$metric][$month] += (int)$traffic;
else
$data['data'][$metric][$month] = (int)$traffic;
}
}
}
foreach ($t->find_all() as $to)
foreach ($to->traffic_data() as $metric => $v)
$result[$metric][$to->month] = $v;
ksort($data['svs']);
foreach ($data['data'] as $metric => $details)
ksort($data['data'][$metric]);
return $data;
return $result;
}
public function action_list() {
$svs = ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('ADSL');
$highchart = HighChart::factory('Combo');
$highchart->title(sprintf('Monthly DSL traffic usage as at %s',date('Y-m-d',strtotime('yesterday'))));
$data = $this->consoltraffic($svs,time());
$c = 0;
foreach ($this->consoltraffic(time()) as $k => $details) {
$highchart->series('column','yl')
->name($k)
->data($details)
->index($c)
->order($c++*-1); // This is a kludge to get around highcharts rendering from the bottom up.
$google = GoogleChart::factory('Legacy')
->type('vertical_bar')
->title(sprintf('ADSL traffic as at %s',date('Y-m-d',strtotime('yesterday'))));
$highchart->autopie($k);
}
foreach ($data['data'] as $key => $values)
$google->sdata(array('yl'=>$key),array($key=>$values));
$google->sdata(array('yr'=>'services'),array('services'=>$data['svs']));
Block::add(array('body'=>(string)$google));
Block::factory()
->body((string)$highchart);
Block::factory()
->title('ADSL Services')
->title_icon('icon-th-list')
->body(Table::factory()
->jssort('adsl')
->data($svs)
->data(ORM::factory('Service')->where_authorised($this->ao)->list_byplugin('ADSL'))
->columns(array(
'id'=>'ID',
'name()'=>'Service',
'plugin()->ipaddress()'=>'IP Address',
'product->plugin()->adsl_supplier_plan->speed'=>'Speed',
'product->plugin()->allowance()'=>'Allowance',
'plugin()->traffic_thismonth()'=>'This Month',
'plugin()->traffic_lastmonth()'=>'Last Month',
'product->plugin()->supplier_plan->speed'=>'Speed',
'product->plugin()->allowance(array(),TRUE,TRUE,1000)'=>'Allowance',
'plugin()->traffic_month(strtotime("yesterday"),TRUE,1000)'=>'This Month',
'plugin()->traffic_month(strtotime("last month"),TRUE,1000)'=>'Last Month',
'recur_schedule'=>'Billing',
'price(TRUE,TRUE)'=>'Price',
'account->accnum()'=>'Cust ID',