Last hour of metric points

This commit is contained in:
James Brooks
2015-12-24 11:27:22 +00:00
parent 8c80565535
commit 3a0c052f8b
21 changed files with 199 additions and 45 deletions

View File

@@ -43,6 +43,27 @@ class MetricRepository
$this->dateTimeZone = SettingFacade::get('app_timezone');
}
/**
* Returns all points as an array, for the last hour.
*
* @param \CachetHQ\Cachet\Models\Metric $metric
*
* @return array
*/
public function listPointsLastHour(Metric $metric)
{
$dateTime = (new Date())->setTimezone($this->dateTimeZone);
$points = [];
$pointKey = $dateTime->format('H:i');
for ($i = 0; $i <= 60; $i++) {
$points[$pointKey] = $this->repository->getPointsLastHour($metric, 0, $i);
$pointKey = $dateTime->sub(new DateInterval('PT1M'))->format('H:i');
}
return array_reverse($points);
}
/**
* Returns all points as an array, by x hours.
*