diff --git a/app/Models/MetricPoint.php b/app/Models/MetricPoint.php index 34125a2f..dd70b0f7 100644 --- a/app/Models/MetricPoint.php +++ b/app/Models/MetricPoint.php @@ -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. * diff --git a/app/Presenters/MetricPointPresenter.php b/app/Presenters/MetricPointPresenter.php index 388ef816..5cbfdd60 100644 --- a/app/Presenters/MetricPointPresenter.php +++ b/app/Presenters/MetricPointPresenter.php @@ -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(), ]); } }