Move calculated_value presenter method into MetricPoint getter
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user