Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 43 additions & 35 deletions app/Repositories/Metric/MetricRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) {
Expand All @@ -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
*/
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/af-ZA/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ar-SA/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ca-ES/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/el-GR/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en-US/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/en/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/et-EE/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fa-IR/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/fi-FI/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/he-IL/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/hu-HU/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/ja-JP/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/mn-MN/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/sl-SI/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/sq-AL/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/th-TH/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/tr-TR/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/uk-UA/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/vi-VN/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion resources/lang/zh-TW/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '平均',
Expand Down