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.
*