Tidy up metric code

This commit is contained in:
James Brooks
2015-06-15 13:37:21 +01:00
parent 56802476a6
commit d5c4561fd1
2 changed files with 8 additions and 6 deletions

View File

@@ -80,13 +80,13 @@ class Metric extends Model implements HasPresenter
}
/**
* Returns the sum of all values a metric has.
* Returns the sum of all values a metric has by the hour.
*
* @param int $hour
*
* @return int
*/
public function getValues($hour)
public function getValuesByHour($hour)
{
$dateTimeZone = SettingFacade::get('app_timezone');
$dateTime = (new Date())->setTimezone($dateTimeZone)->sub(new DateInterval('PT'.$hour.'H'));

View File

@@ -2,11 +2,11 @@
<ul class="list-group metrics">
@foreach($metrics as $metric)
<?php
$points = [];
$hourPoints = [];
foreach (range(1, 11) as $hour) {
$points[$hour] = $metric->getValues($hour);
$hourPoints[$hour] = $metric->getValuesByHour($hour);
}
$points = array_reverse($points);
$hourPoints = array_reverse($hourPoints);
?>
<li class="list-group-item metric">
<div class="row">
@@ -42,6 +42,8 @@
hourList.push(moment(date).seconds(0).format('HH:ss'));
var hourPoints = [{{ implode(',', $hourPoints) }}];
var data = {
showTooltips: false,
labels: hourList,
@@ -52,7 +54,7 @@
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [{{ implode(',', $points) }}],
data: hourPoints
}],
};