diff --git a/app/Repositories/Metric/MetricRepository.php b/app/Repositories/Metric/MetricRepository.php index c424336b19cd..d9e2efaf248c 100644 --- a/app/Repositories/Metric/MetricRepository.php +++ b/app/Repositories/Metric/MetricRepository.php @@ -40,7 +40,7 @@ class MetricRepository * Create a new metric repository class. * * @param \CachetHQ\Cachet\Repositories\Metric\MetricInterface $repository - * @param \CachetHQ\Cachet\Services\Dates\DateFactory $dates + * @param \CachetHQ\Cachet\Services\Dates\DateFactory $dates * * @return void */ @@ -64,27 +64,29 @@ public function listPointsLastHour(Metric $metric) $nrOfMinutes = 61; $points = $this->repository->getPointsSinceMinutes($metric, $nrOfMinutes + $metric->threshold)->pluck('value', 'key')->take(-$nrOfMinutes); - $timeframe = $nrOfMinutes; - - //Settings counter for minutes without data - $minutesWithNoData = 0; - - for ($i = 0; $i < $timeframe; $i++) { - if (!$points->has($pointKey)) { - if ($i >= $metric->threshold) { - $points->put($pointKey, $metric->default_value); - //We put default value as metric, so we can reset counter for minutes without data - $minutesWithNoData = 0; + if ($metric->default_value >= 0) { + $timeframe = $nrOfMinutes; + + //Settings counter for minutes without data + $minutesWithNoData = 0; + + for ($i = 0; $i < $timeframe; $i++) { + if (!$points->has($pointKey)) { + if ($i >= $metric->threshold) { + $points->put($pointKey, $metric->default_value); + //We put default value as metric, so we can reset counter for minutes without data + $minutesWithNoData = 0; + } else { + //We didn't find any data, but threshold is not meet yet so we just adding to counter + $minutesWithNoData++; + } } else { - //We didn't find any data, but threshold is not meet yet so we just adding to counter - $minutesWithNoData++; + //We found data within this threshold, zeroing counter + $minutesWithNoData = 0; } - } else { - //We found data within this threshold, zeroing counter - $minutesWithNoData = 0; - } - $pointKey = $dateTime->sub(new DateInterval('PT1M'))->format('Y-m-d H:i'); + $pointKey = $dateTime->sub(new DateInterval('PT1M'))->format('Y-m-d H:i'); + } } return $points->sortBy(function ($point, $key) { @@ -96,7 +98,7 @@ public function listPointsLastHour(Metric $metric) * Returns all points as an array, by x hours. * * @param \CachetHQ\Cachet\Models\Metric $metric - * @param int $hours + * @param int $hours * * @return array */ @@ -106,12 +108,14 @@ public function listPointsToday(Metric $metric, $hours = 12) $pointKey = $dateTime->format('Y-m-d H:00'); $points = $this->repository->getPointsSinceHour($metric, $hours)->pluck('value', 'key'); - for ($i = 0; $i < $hours; $i++) { - if (!$points->has($pointKey)) { - $points->put($pointKey, $metric->default_value); - } + if ($metric->default_value >= 0) { + for ($i = 0; $i < $hours; $i++) { + if (!$points->has($pointKey)) { + $points->put($pointKey, $metric->default_value); + } - $pointKey = $dateTime->sub(new DateInterval('PT1H'))->format('Y-m-d H:00'); + $pointKey = $dateTime->sub(new DateInterval('PT1H'))->format('Y-m-d H:00'); + } } return $points->sortBy(function ($point, $key) { @@ -132,12 +136,14 @@ public function listPointsForWeek(Metric $metric) $pointKey = $dateTime->format('Y-m-d'); $points = $this->repository->getPointsSinceDay($metric, 7)->pluck('value', 'key'); - for ($i = 0; $i <= 7; $i++) { - if (!$points->has($pointKey)) { - $points->put($pointKey, $metric->default_value); - } + if ($metric->default_value >= 0) { + for ($i = 0; $i <= 7; $i++) { + if (!$points->has($pointKey)) { + $points->put($pointKey, $metric->default_value); + } - $pointKey = $dateTime->sub(new DateInterval('P1D'))->format('Y-m-d'); + $pointKey = $dateTime->sub(new DateInterval('P1D'))->format('Y-m-d'); + } } return $points->sortBy(function ($point, $key) { @@ -159,12 +165,14 @@ public function listPointsForMonth(Metric $metric) $daysInMonth = $dateTime->format('t'); $points = $this->repository->getPointsSinceDay($metric, $daysInMonth)->pluck('value', 'key'); - for ($i = 0; $i <= $daysInMonth; $i++) { - if (!$points->has($pointKey)) { - $points->put($pointKey, $metric->default_value); - } + if ($metric->default_value >= 0) { + for ($i = 0; $i <= $daysInMonth; $i++) { + if (!$points->has($pointKey)) { + $points->put($pointKey, $metric->default_value); + } - $pointKey = $dateTime->sub(new DateInterval('P1D'))->format('Y-m-d'); + $pointKey = $dateTime->sub(new DateInterval('P1D'))->format('Y-m-d'); + } } return $points->sortBy(function ($point, $key) { diff --git a/resources/lang/af-ZA/forms.php b/resources/lang/af-ZA/forms.php index d87c854dc6a9..6427fe752f40 100644 --- a/resources/lang/af-ZA/forms.php +++ b/resources/lang/af-ZA/forms.php @@ -127,7 +127,7 @@ 'description' => 'Beskrywing', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/ar-SA/forms.php b/resources/lang/ar-SA/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/ar-SA/forms.php +++ b/resources/lang/ar-SA/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/ca-ES/forms.php b/resources/lang/ca-ES/forms.php index a41f0b27e327..bd832e9fd216 100644 --- a/resources/lang/ca-ES/forms.php +++ b/resources/lang/ca-ES/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/el-GR/forms.php b/resources/lang/el-GR/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/el-GR/forms.php +++ b/resources/lang/el-GR/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/en-US/forms.php b/resources/lang/en-US/forms.php index c4ba66881335..cc8ddafdc4c9 100644 --- a/resources/lang/en-US/forms.php +++ b/resources/lang/en-US/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/en/forms.php b/resources/lang/en/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/en/forms.php +++ b/resources/lang/en/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/et-EE/forms.php b/resources/lang/et-EE/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/et-EE/forms.php +++ b/resources/lang/et-EE/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/fa-IR/forms.php b/resources/lang/fa-IR/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/fa-IR/forms.php +++ b/resources/lang/fa-IR/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/fi-FI/forms.php b/resources/lang/fi-FI/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/fi-FI/forms.php +++ b/resources/lang/fi-FI/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/he-IL/forms.php b/resources/lang/he-IL/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/he-IL/forms.php +++ b/resources/lang/he-IL/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/hu-HU/forms.php b/resources/lang/hu-HU/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/hu-HU/forms.php +++ b/resources/lang/hu-HU/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/ja-JP/forms.php b/resources/lang/ja-JP/forms.php index 4d5208c8b2cc..cc028667f6fa 100644 --- a/resources/lang/ja-JP/forms.php +++ b/resources/lang/ja-JP/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/mn-MN/forms.php b/resources/lang/mn-MN/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/mn-MN/forms.php +++ b/resources/lang/mn-MN/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/sl-SI/forms.php b/resources/lang/sl-SI/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/sl-SI/forms.php +++ b/resources/lang/sl-SI/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/sq-AL/forms.php b/resources/lang/sq-AL/forms.php index a8b9c348ef4d..ca89dae5e5ba 100644 --- a/resources/lang/sq-AL/forms.php +++ b/resources/lang/sq-AL/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/th-TH/forms.php b/resources/lang/th-TH/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/th-TH/forms.php +++ b/resources/lang/th-TH/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/tr-TR/forms.php b/resources/lang/tr-TR/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/tr-TR/forms.php +++ b/resources/lang/tr-TR/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/uk-UA/forms.php b/resources/lang/uk-UA/forms.php index 5c5a41a9c5d5..1a3570fbde52 100644 --- a/resources/lang/uk-UA/forms.php +++ b/resources/lang/uk-UA/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/vi-VN/forms.php b/resources/lang/vi-VN/forms.php index 45642b96c11d..ddab85ef419f 100644 --- a/resources/lang/vi-VN/forms.php +++ b/resources/lang/vi-VN/forms.php @@ -127,7 +127,7 @@ 'description' => 'Description', 'description-help' => 'You may also use Markdown.', 'display-chart' => 'Display chart on status page?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => 'Sum', 'type_avg' => 'Average', diff --git a/resources/lang/zh-TW/forms.php b/resources/lang/zh-TW/forms.php index e714ba15c548..d96ab4a4be64 100644 --- a/resources/lang/zh-TW/forms.php +++ b/resources/lang/zh-TW/forms.php @@ -127,7 +127,7 @@ 'description' => '描述', 'description-help' => '你可以使用 Markdown 。', 'display-chart' => '在狀態頁上顯示圖表?', - 'default-value' => 'Default value', + 'default-value' => 'Default value (-1 to hide)', 'calc_type' => 'Calculation of metrics', 'type_sum' => '總和', 'type_avg' => '平均',