From 55002bb4b40fef917679e4faa234b5a29a35a16c Mon Sep 17 00:00:00 2001 From: James Brooks Date: Wed, 27 Jun 2018 14:28:38 +0100 Subject: [PATCH] Group metric points into intervals of 30 seconds --- app/Models/MetricPoint.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Models/MetricPoint.php b/app/Models/MetricPoint.php index 89d531013..f06832e8d 100644 --- a/app/Models/MetricPoint.php +++ b/app/Models/MetricPoint.php @@ -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. *