Merge branch '2.4' into feature/merge-install-commands

This commit is contained in:
Nico Stapelbroek
2018-07-03 14:39:38 +02:00
committed by GitHub
19 changed files with 147 additions and 86 deletions

View File

@@ -12,8 +12,6 @@
namespace CachetHQ\Cachet\Console\Commands;
use CachetHQ\Cachet\Models\MetricPoint;
use DateInterval;
use DateTime;
use Illuminate\Console\Command;
use Illuminate\Console\ConfirmableTrait;
use Symfony\Component\Console\Input\InputOption;
@@ -66,16 +64,26 @@ class DemoMetricPointSeederCommand extends Command
{
MetricPoint::truncate();
// Generate 11 hours of metric points
for ($i = 0; $i < 11; $i++) {
$metricTime = (new DateTime())->sub(new DateInterval('PT'.$i.'H'));
$points = [];
MetricPoint::create([
'metric_id' => 1,
'value' => random_int(1, 10),
'created_at' => $metricTime,
'updated_at' => $metricTime,
]);
// Generate 24 hours of metric points
for ($i = 0; $i <= 23; $i++) {
for ($j = 0; $j <= 59; $j++) {
$this->info("{$i}:{$j}");
$pointTime = date("Y-m-d {$i}:{$j}:00");
$points[] = [
'metric_id' => 1,
'value' => random_int(1, 10),
'created_at' => $pointTime,
'updated_at' => $pointTime,
];
}
}
foreach (array_chunk($points, 100) as $chunk) {
MetricPoint::insert($chunk);
}
}

View File

@@ -24,7 +24,7 @@ use Illuminate\Support\Facades\View;
/**
* This is the component group controller class.
*
* @author James Brooks <james@bluebaytravel.co.uk>
* @author James Brooks <james@alt-three.com>
*/
class ComponentGroupController extends Controller
{

View File

@@ -81,10 +81,6 @@ class Beacon implements BeaconContract
return;
}
if (!($contactEmail = User::admins()->active()->first()->email)) {
$contactEmail = null;
}
$setting = app(Setting::class);
if (!$installId = $setting->get('install_id', null)) {
@@ -94,12 +90,11 @@ class Beacon implements BeaconContract
}
$payload = [
'install_id' => $installId,
'version' => CACHET_VERSION,
'docker' => $this->config->get('cachet.is_docker'),
'database' => $this->config->get('database.default'),
'contact_email' => $contactEmail,
'data' => [
'install_id' => $installId,
'version' => CACHET_VERSION,
'docker' => $this->config->get('cachet.is_docker'),
'database' => $this->config->get('database.default'),
'data' => [
'components' => Component::all()->count(),
'incidents' => Incident::all()->count(),
'metrics' => Metric::all()->count(),

View File

@@ -182,7 +182,7 @@ class Metric extends Model implements HasPresenter
*/
public function points()
{
return $this->hasMany(MetricPoint::class, 'metric_id', 'id');
return $this->hasMany(MetricPoint::class, 'metric_id', 'id')->latest();
}
/**

View File

@@ -29,6 +29,15 @@ class MetricPoint extends Model implements HasPresenter
{
use ValidatingTrait;
/**
* The accessors to append to the model's array form.
*
* @var string[]
*/
protected $appends = [
'calculated_value',
];
/**
* The model's attributes.
*
@@ -82,19 +91,13 @@ class MetricPoint extends Model implements HasPresenter
}
/**
* Override the value attribute.
* Show the actual calculated value; as per (value * counter).
*
* @param mixed $value
*
* @return float
* @return int
*/
public function getActiveValueAttribute($value)
public function getCalculatedValueAttribute()
{
if ($this->metric->calc_type === Metric::CALC_SUM) {
return round((float) $value * $this->counter, $this->metric->places);
}
return round((float) $value, $this->metric->places);
return $this->value * $this->counter;
}
/**
@@ -117,7 +120,11 @@ class MetricPoint extends Model implements HasPresenter
$timestamp = $createdAt->format('U');
$timestamp = 30 * round($timestamp / 30);
return Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
$date = Carbon::createFromFormat('U', $timestamp)->toDateTimeString();
$this->attributes['created_at'] = $date;
return $date;
}
/**

View File

@@ -19,16 +19,6 @@ class MetricPointPresenter extends BasePresenter implements Arrayable
{
use TimestampsTrait;
/**
* Show the actual calculated value; as per (value * counter).
*
* @return int
*/
public function calculated_value()
{
return $this->wrappedObject->value * $this->wrappedObject->counter;
}
/**
* Convert the presenter instance to an array.
*
@@ -37,9 +27,8 @@ class MetricPointPresenter extends BasePresenter implements Arrayable
public function toArray()
{
return array_merge($this->wrappedObject->toArray(), [
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
'calculated_value' => $this->calculated_value(),
'created_at' => $this->created_at(),
'updated_at' => $this->updated_at(),
]);
}
}

View File

@@ -18,7 +18,7 @@ use McCool\LaravelAutoPresenter\BasePresenter;
/**
* This is the user presenter class.
*
* @author James Brooks <james@bluebaytravel.co.uk>
* @author James Brooks <james@alt-three.com>
*/
class UserPresenter extends BasePresenter implements Arrayable
{

View File

@@ -98,7 +98,7 @@ class MetricRepository
$pointKey = $dateTime->format('Y-m-d H:00');
$points = $this->repository->getPointsSinceHour($metric, $hours)->pluck('value', 'key');
for ($i = 0; $i <= $hours; $i++) {
for ($i = 0; $i < $hours; $i++) {
if (!$points->has($pointKey)) {
$points->put($pointKey, $metric->default_value);
}

View File

@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
/**
* This is the pgsql repository class.

View File

@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
/**
* This is the sqlite repository class.