You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$points = Collection::make(DB::select("SELECT DATE_FORMAT(mp.`created_at`, '%H:%i') AS `key`, {$queryType} FROM {$this->getTableName()}m INNER JOIN metric_points mp ON m.id = mp.metric_id WHERE m.id = :metricId AND mp.`created_at` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) GROUP BY HOUR(mp.`created_at`), MINUTE(mp.`created_at`) ORDER BY mp.`created_at`", [
36
+
$points = Collection::make(DB::select("SELECT DATE_FORMAT(metric_points.`created_at`, '%H:%i') AS `key`, {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.`created_at` >= DATE_SUB(NOW(), INTERVAL :minutes MINUTE) GROUP BY HOUR(metric_points.`created_at`), MINUTE(metric_points.`created_at`) ORDER BY metric_points.`created_at`", [
37
37
'metricId' => $metric->id,
38
38
'minutes' => $minutes,
39
39
]));
@@ -52,7 +52,7 @@ public function getPointsSinceMinutes(Metric $metric, $minutes)
$points = Collection::make(DB::select("SELECT DATE_FORMAT(mp.`created_at`, '%H:00') AS `key`, {$queryType} FROM {$this->getTableName()}m INNER JOIN metric_points mp ON m.id = mp.metric_id WHERE m.id = :metricId AND mp.`created_at` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) GROUP BY HOUR(mp.`created_at`) ORDER BY mp.`created_at`", [
55
+
$points = Collection::make(DB::select("SELECT DATE_FORMAT(metric_points.`created_at`, '%H:00') AS `key`, {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.`created_at` >= DATE_SUB(NOW(), INTERVAL :hour HOUR) GROUP BY HOUR(metric_points.`created_at`) ORDER BY metric_points.`created_at`", [
56
56
'metricId' => $metric->id,
57
57
'hour' => $hour,
58
58
]));
@@ -70,7 +70,7 @@ public function getPointsSinceHour(Metric $metric, $hour)
$points = Collection::make(DB::select("SELECT DATE_FORMAT(mp.`created_at`, '%Y-%m-%d') AS `key`, {$queryType} FROM {$this->getTableName()}m INNER JOIN metric_points mp ON m.id = mp.metric_id WHERE m.id = :metricId AND mp.`created_at` >= DATE_SUB(NOW(), INTERVAL :day DAY) GROUP BY DATE_FORMAT(mp.`created_at`) ORDER BY mp.`created_at`", [
73
+
$points = Collection::make(DB::select("SELECT DATE_FORMAT(metric_points.`created_at`, '%Y-%m-%d') AS `key`, {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.`created_at` >= DATE_SUB(NOW(), INTERVAL :day DAY) GROUP BY DATE(metric_points.`created_at`) ORDER BY metric_points.`created_at`", [
$points = Collection::make(DB::select("SELECT to_char(metric_points.`created_at`, 'HHMI') AS `key`, {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.`created_at` >= NOW() -, INTERVAL ':minutes' MINUTE) GROUP BY to_char(metric_points.`created_at`, 'HHMI') ORDER BY metric_points.`created_at`", [
38
+
'metricId' => $metric->id,
39
+
'minutes' => $minutes,
40
+
]));
39
41
40
-
$value = 0;
41
-
$query = DB::select("select {$queryType} FROM {$this->getTableName()} m JOIN metric_points ON metric_points.metric_id = m.id WHERE m.id = :metricId AND to_char(metric_points.created_at, 'YYYYMMDDHH24MI') = :timeInterval GROUP BY to_char(metric_points.created_at, 'HHMI')", [
42
-
'metricId' => $metric->id,
43
-
'timeInterval' => $dateTime->format('YmdHi'),
44
-
]);
45
-
46
-
if (isset($query[0])) {
47
-
$value = $query[0]->value;
48
-
}
49
-
50
-
if ($value === 0 && $metric->default_value != $value) {
51
-
return$metric->default_value;
52
-
}
53
-
54
-
returnround($value, $metric->places);
42
+
return$this->mapResults($metric, $points);
55
43
}
56
44
57
45
/**
@@ -64,26 +52,18 @@ public function getPointsSinceMinutes(Metric $metric, $minutes)
$query = DB::select("select {$queryType} FROM {$this->getTableName()} m JOIN metric_points ON metric_points.metric_id = m.id WHERE metric_points.metric_id = :metricId AND to_char(metric_points.created_at, 'YYYYMMDDHH24') = :timeInterval GROUP BY to_char(metric_points.created_at, 'H')", [
55
+
$query = DB::select("select {$queryType} FROM {$this->getTableName()} JOIN metric_points ON metric_points.metric_id = metrics.id WHERE metric_points.metric_id = :metricId AND to_char(metric_points.created_at, 'YYYYMMDDHH24') = :timeInterval GROUP BY to_char(metric_points.created_at, 'H')", [
74
56
'metricId' => $metric->id,
75
57
'timeInterval' => $dateTime->format('YmdH'),
76
58
]);
77
59
78
-
if (isset($query[0])) {
79
-
$value = $query[0]->value;
80
-
}
81
-
82
-
if ($value === 0 && $metric->default_value != $value) {
83
-
return$metric->default_value;
84
-
}
60
+
$queryType = $this->getQueryType($metric);
61
+
$points = Collection::make(DB::select("SELECT to_char(metric_points.`created_at`, 'H') AS `key`, {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.`created_at` >= NOW() -, INTERVAL ':minutes' MINUTE) GROUP BY to_char(metric_points.`created_at`, 'H') ORDER BY metric_points.`created_at`", [
62
+
'metricId' => $metric->id,
63
+
'minutes' => $minutes,
64
+
]));
85
65
86
-
returnround($value, $metric->places);
66
+
return$this->mapResults($metric, $points);
87
67
}
88
68
89
69
/**
@@ -100,7 +80,7 @@ public function getPointsForDayInWeek(Metric $metric, $day)
100
80
$queryType = $this->getQueryType($metric);
101
81
102
82
$value = 0;
103
-
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()}m INNER JOIN metric_points mp ON m.id = mp.metric_id WHERE m.id = :metricId AND mp.created_at BETWEEN (mp.created_at - interval '1 week') AND (now() + interval '1 day') AND to_char(mp.created_at, 'YYYYMMDD') = :timeInterval GROUP BY to_char(mp.created_at, 'YYYYMMDD')", [
83
+
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()} INNER JOIN metric_points ON metrics.id = metric_points.metric_id WHERE metrics.id = :metricId AND metric_points.created_at BETWEEN (metric_points.created_at - interval '1 week') AND (now() + interval '1 day') AND to_char(metric_points.created_at, 'YYYYMMDD') = :timeInterval GROUP BY to_char(metric_points.created_at, 'YYYYMMDD')", [
0 commit comments