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
if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
41
43
$queryType = 'SUM(mp.`value` * mp.`counter`) AS `value`';
@@ -45,7 +47,7 @@ public function getPointsLastHour(Metric $metric, $hour, $minute)
45
47
46
48
$value = 0;
47
49
48
-
$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 DATE_FORMAT(mp.`created_at`, '%Y%m%d%H%i') = :timeInterval GROUP BY HOUR(mp.`created_at`), MINUTE(mp.`created_at`)", [
50
+
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()} m INNER JOIN $metricPointsTableName mp ON m.id = mp.metric_id WHERE m.id = :metricId AND DATE_FORMAT(mp.`created_at`, '%Y%m%d%H%i') = :timeInterval GROUP BY HOUR(mp.`created_at`), MINUTE(mp.`created_at`)", [
49
51
'metricId' => $metric->id,
50
52
'timeInterval' => $timeInterval,
51
53
]);
@@ -73,6 +75,7 @@ public function getPointsByHour(Metric $metric, $hour)
if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
78
81
$queryType = 'SUM(mp.`value` * mp.`counter`) AS `value`';
@@ -82,7 +85,7 @@ public function getPointsByHour(Metric $metric, $hour)
82
85
83
86
$value = 0;
84
87
85
-
$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 DATE_FORMAT(mp.`created_at`, '%Y%m%d%H') = :hourInterval GROUP BY HOUR(mp.`created_at`)", [
88
+
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()} m INNER JOIN $metricPointsTableName mp ON m.id = mp.metric_id WHERE m.id = :metricId AND DATE_FORMAT(mp.`created_at`, '%Y%m%d%H') = :hourInterval GROUP BY HOUR(mp.`created_at`)", [
86
89
'metricId' => $metric->id,
87
90
'hourInterval' => $hourInterval,
88
91
]);
@@ -108,6 +111,7 @@ public function getPointsByHour(Metric $metric, $hour)
if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
113
117
$queryType = 'SUM(mp.`value` * mp.`counter`) AS `value`';
@@ -117,7 +121,7 @@ public function getPointsForDayInWeek(Metric $metric, $day)
117
121
118
122
$value = 0;
119
123
120
-
$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 DATE_SUB(mp.`created_at`, INTERVAL 1 WEEK) AND DATE_ADD(NOW(), INTERVAL 1 DAY) AND DATE_FORMAT(mp.`created_at`, '%Y%m%d') = :timeInterval GROUP BY DATE_FORMAT(mp.`created_at`, '%Y%m%d')", [
124
+
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()} m INNER JOIN $metricPointsTableName mp ON m.id = mp.metric_id WHERE m.id = :metricId AND mp.`created_at` BETWEEN DATE_SUB(mp.`created_at`, INTERVAL 1 WEEK) AND DATE_ADD(NOW(), INTERVAL 1 DAY) AND DATE_FORMAT(mp.`created_at`, '%Y%m%d') = :timeInterval GROUP BY DATE_FORMAT(mp.`created_at`, '%Y%m%d')", [
$query = DB::select("select {$queryType} as value 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')", [
50
+
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN $metricPointsTableName ON $metricPointsTableName.metric_id = m.id WHERE m.id = :metricId AND to_char($metricPointsTableName.created_at, 'YYYYMMDDHH24MI') = :timeInterval GROUP BY to_char($metricPointsTableName.created_at, 'HHMI')", [
50
51
'metricId' => $metric->id,
51
52
'timeInterval' => $dateTime->format('YmdHi'),
52
53
]);
@@ -73,18 +74,19 @@ public function getPointsLastHour(Metric $metric, $hour, $minute)
$query = DB::select("select {$queryType} as value 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')", [
89
+
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN $metricPointsTableName ON $metricPointsTableName.metric_id = m.id WHERE $metricPointsTableName.metric_id = :metricId AND to_char($metricPointsTableName.created_at, 'YYYYMMDDHH24') = :timeInterval GROUP BY to_char($metricPointsTableName.created_at, 'H')", [
88
90
'metricId' => $metric->id,
89
91
'timeInterval' => $dateTime->format('YmdH'),
90
92
]);
@@ -110,6 +112,7 @@ public function getPointsByHour(Metric $metric, $hour)
if (!isset($metric->calc_type) || $metric->calc_type == Metric::CALC_SUM) {
115
118
$queryType = 'sum(mp.value * mp.counter) AS value';
@@ -118,7 +121,7 @@ public function getPointsForDayInWeek(Metric $metric, $day)
118
121
}
119
122
120
123
$value = 0;
121
-
$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')", [
124
+
$points = DB::select("SELECT {$queryType} FROM {$this->getTableName()} m INNER JOIN $metricPointsTableName 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')", [
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN metric_points ON metric_points.metric_id = m.id WHERE m.id = :metricId AND strftime('%Y%m%d%H%M', metric_points.created_at) = :timeInterval GROUP BY strftime('%H%M', metric_points.created_at)", [
45
+
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN $metricPointsTableName ON $metricPointsTableName.metric_id = m.id WHERE m.id = :metricId AND strftime('%Y%m%d%H%M', $metricPointsTableName.created_at) = :timeInterval GROUP BY strftime('%H%M', $metricPointsTableName.created_at)", [
45
46
'metricId' => $metric->id,
46
47
'timeInterval' => $dateTime->format('YmdHi'),
47
48
]);
@@ -68,18 +69,19 @@ public function getPointsLastHour(Metric $metric, $hour, $minute)
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN metric_points ON metric_points.metric_id = m.id WHERE m.id = :metricId AND strftime('%Y%m%d%H', metric_points.created_at) = :timeInterval GROUP BY strftime('%H', metric_points.created_at)", [
84
+
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN $metricPointsTableName ON $metricPointsTableName.metric_id = m.id WHERE m.id = :metricId AND strftime('%Y%m%d%H', $metricPointsTableName.created_at) = :timeInterval GROUP BY strftime('%H', $metricPointsTableName.created_at)", [
83
85
'metricId' => $metric->id,
84
86
'timeInterval' => $dateTime->format('YmdH'),
85
87
]);
@@ -105,18 +107,19 @@ public function getPointsByHour(Metric $metric, $hour)
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN metric_points ON metric_points.metric_id = m.id WHERE m.id = :metricId AND metric_points.created_at > date('now', '-7 day') AND strftime('%Y%m%d', metric_points.created_at) = :timeInterval GROUP BY strftime('%Y%m%d', metric_points.created_at)", [
122
+
$query = DB::select("select {$queryType} as value FROM {$this->getTableName()} m JOIN $metricPointsTableName ON $metricPointsTableName.metric_id = m.id WHERE m.id = :metricId AND $metricPointsTableName.created_at > date('now', '-7 day') AND strftime('%Y%m%d', $metricPointsTableName.created_at) = :timeInterval GROUP BY strftime('%Y%m%d', $metricPointsTableName.created_at)", [
0 commit comments