Move calculated_value presenter method into MetricPoint getter

This commit is contained in:
James Brooks 2018-07-02 18:05:12 +01:00
parent c006b7d6ef
commit 085552607a
2 changed files with 21 additions and 13 deletions

View File

@ -29,6 +29,15 @@ class MetricPoint extends Model implements HasPresenter
{
use ValidatingTrait;
/**
* The accessors to append to the model's array form.
*
* @var string[]
*/
protected $appends = [
'calculated_value',
];
/**
* The model's attributes.
*
@ -81,6 +90,16 @@ class MetricPoint extends Model implements HasPresenter
return $this->belongsTo(Metric::class);
}
/**
* Show the actual calculated value; as per (value * counter).
*
* @return int
*/
public function getCalculatedValueAttribute()
{
return $this->value * $this->counter;
}
/**
* Round the created at value into intervals of 30 seconds.
*

View File

@ -19,16 +19,6 @@ class MetricPointPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;
/**
* Show the actual calculated value; as per (value * counter).
*
* @return int
*/
public function calculated_value()
{
return $this->wrappedObject->value * $this->wrappedObject->counter;
}
/**
* Convert the presenter instance to an array.
*
@ -37,9 +27,8 @@ class MetricPointPresenter extends BasePresenter implements Arrayable
public function toArray()
{
return array_merge($this->wrappedObject->toArray(), [
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
'calculated_value' => $this->calculated_value(),
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
]);
}
}