Group metric points into intervals of 30 seconds

This commit is contained in:
James Brooks 2018-06-27 14:28:38 +01:00 committed by James Brooks
parent c9baa103dd
commit 55002bb4b4

View File

@ -13,6 +13,7 @@ namespace CachetHQ\Cachet\Models;
use AltThree\Validator\ValidatingTrait;
use CachetHQ\Cachet\Presenters\MetricPointPresenter;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use McCool\LaravelAutoPresenter\HasPresenter;
@ -88,6 +89,21 @@ class MetricPoint extends Model implements HasPresenter
return round((float) $value, $this->metric->places);
}
/**
* Round the created at value into intervals of 30 seconds.
*
* @param string $value
*
* @return void
*/
public function setCreatedAtAttribute($value)
{
$timestamp = $value->format('U');
$timestamp = 30 * round($timestamp / 30);
return Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
}
/**
* Get the presenter class.
*