Update code to match master

This commit is contained in:
Joseph Cohen
2015-03-26 15:07:16 -06:00
parent eb22ac6d8a
commit 37e20bf2bf
15 changed files with 192 additions and 105 deletions

View File

@@ -14,6 +14,8 @@ use Watson\Validating\ValidatingTrait;
* @property string $name
* @property string $suffix
* @property string $description
* @property float $default_value
* @property int $calc_type
* @property int $display_chart
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
@@ -90,6 +92,8 @@ class Metric extends Model
$queryType = "sum(metric_points.value)";
} elseif ($this->calc_type === self::CALC_AVG) {
$queryType = "avg(metric_points.value)";
} else {
$queryType = "sum(metric_points.value)";
}
$query = DB::select("select {$queryType} as aggregate FROM metrics JOIN metric_points ON metric_points.metric_id = metrics.id WHERE to_char(metric_points.created_at, 'YYYYMMDDHH') = :timestamp AND to_char(metric_points.created_at, 'H') = to_char(now() - interval '{$hour} hour', 'H') GROUP BY to_char(metric_points.created_at, 'H')", [