Overhaul ADSL traffic reporting/graphing
This commit is contained in:
@@ -21,13 +21,22 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
||||
'plan'=>array('model'=>'Service_Plugin_Adsl','foreign_key'=>'service_username','far_key'=>'service'),
|
||||
);
|
||||
|
||||
private $metrics = array(
|
||||
'up_peak',
|
||||
'up_offpeak',
|
||||
'down_peak',
|
||||
'down_offpeak',
|
||||
'peer',
|
||||
'internal',
|
||||
public static $metrics = array(
|
||||
'down_peak'=>'base_down_peak',
|
||||
'down_offpeak'=>'base_down_offpeak',
|
||||
'up_peak'=>'base_up_peak',
|
||||
'up_offpeak'=>'base_up_offpeak',
|
||||
'peer'=>'base_down_peak',
|
||||
'internal'=>'base_down_offpeak',
|
||||
);
|
||||
|
||||
private $_friendly = array(
|
||||
'base_up_peak'=>'UP Peak',
|
||||
'base_up_offpeak'=>'UP Offpeak',
|
||||
'base_down_peak'=>'DOWN Peak',
|
||||
'base_down_offpeak'=>'DOWN Offpeak',
|
||||
'base_peer'=>'Peer',
|
||||
'base_internal'=>'Internal',
|
||||
);
|
||||
|
||||
public function rules() {
|
||||
@@ -39,12 +48,16 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function friendly($name) {
|
||||
return isset($this->_friendly[$name]) ? $this->_friendly[$name] : $name;
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// If all our values are zero/NULL, we'll ignore if our previous one was.
|
||||
if ($this->total() !== 0)
|
||||
return parent::save($validation);
|
||||
|
||||
$l = ORM::factory($this->_object_name)->where('service','=',$this->service)->where('supplier_id','=',$this->supplier_id)->list_last();
|
||||
$l = ORM::factory($this->_object_name)->where('service','=',$this->service)->where('supplier_id','=',$this->supplier_id)->find_last();
|
||||
|
||||
if ($l->total() !== 0)
|
||||
return parent::save($validation);
|
||||
@@ -57,10 +70,23 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the select statements to SUM up the traffic metrics that we use
|
||||
*/
|
||||
public function selectsummetric() {
|
||||
foreach (Model_Service_Plugin_Adsl_Traffic::$metrics as $metric=>$v)
|
||||
$this->select(array("sum(".$metric.")",$metric));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Total up the traffic into the metrics we use
|
||||
*/
|
||||
public function total() {
|
||||
$result = 0;
|
||||
|
||||
foreach ($this->metrics as $metric) {
|
||||
foreach (array_keys(Model_Service_Plugin_Adsl_Traffic::$metrics) as $metric) {
|
||||
if (is_null($this->$metric))
|
||||
$this->$metric = 0;
|
||||
|
||||
@@ -70,21 +96,26 @@ class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function traffic(Model_Product_Plugin_Adsl $plan) {
|
||||
// Roll up the charges according to the product plan configuration
|
||||
return ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($plan->base_down_peak) ? NULL : $this->down_peak,
|
||||
'base_down_offpeak'=>is_null($plan->base_down_offpeak) ? NULL : $this->down_offpeak,
|
||||
'base_up_peak'=>is_null($plan->base_up_peak) ? NULL : $this->up_peak,
|
||||
'base_up_offpeak'=>is_null($plan->base_up_offpeak) ? NULL : $this->up_offpeak,
|
||||
'extra_down_peak'=>$plan->extra_down_peak,
|
||||
'extra_down_offpeak'=>$plan->extra_down_offpeak,
|
||||
'extra_up_peak'=>$plan->extra_up_peak,
|
||||
'extra_up_offpeak'=>$plan->extra_up_offpeak,
|
||||
));
|
||||
/**
|
||||
* Collapse our traffic data into an array as per $this->_metric
|
||||
*/
|
||||
public function traffic_data() {
|
||||
$result = array();
|
||||
|
||||
foreach (Model_Service_Plugin_Adsl_Traffic::$metrics as $metric=>$v) {
|
||||
if (! isset($result[$v]))
|
||||
$result[$v] = 0;
|
||||
|
||||
$result[$v] += $this->{$metric};
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function list_last() {
|
||||
/**
|
||||
* Find the last traffic record
|
||||
*/
|
||||
public function find_last() {
|
||||
return $this->order_by('date','DESC')->order_by('time','DESC')->find();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user