Fix generation of metrics, no longer sub an extra hour in calculation

This commit is contained in:
James Brooks
2015-05-22 15:32:55 +01:00
parent d24e83e0ae
commit e4ef64d014
5 changed files with 84 additions and 1 deletions

View File

@@ -93,7 +93,7 @@ class Metric extends Model implements HasPresenter
$dateTimeZone = SettingFacade::get('app_timezone');
$dateTime = (new Date())->setTimezone($dateTimeZone)->sub(new DateInterval('PT'.$hour.'H'));
$hourInterval = $dateTime->sub(new DateInterval('PT'.$hour.'H'))->format('YmdH');
$hourInterval = $dateTime->format('YmdH');
if (Config::get('database.default') === 'mysql') {
if (!isset($this->calc_type) || $this->calc_type == self::CALC_SUM) {

View File

@@ -27,5 +27,6 @@ class DatabaseSeeder extends Seeder
$this->call('SettingsTableSeeder');
$this->call('IncidentTableSeeder');
$this->call('ComponentTableSeeder');
$this->call('MetricTableSeeder');
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
* (c) Graham Campbell <graham@mineuk.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use CachetHQ\Cachet\Models\MetricPoint;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class MetricPointSeeder extends Seeder
{
/**
* Run the database seeding.
*/
public function run()
{
Model::unguard();
$metric = [
'metric_id' => 1,
'value' => rand(1, 100),
];
MetricPoint::create($metric);
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
* (c) Joseph Cohen <joseph.cohen@dinkbit.com>
* (c) Graham Campbell <graham@mineuk.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use CachetHQ\Cachet\Models\Metric;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
class MetricTableSeeder extends Seeder
{
/**
* Run the database seeding.
*/
public function run()
{
Model::unguard();
$defaultMetrics = [
[
'name' => 'Demo Metric',
'suffix' => 'rnd',
'description' => 'Random data points.',
'default_value' => 0,
'calc_type' => 1,
'display_chart' => 1,
],
];
Metric::truncate();
foreach ($defaultMetrics as $metric) {
Metric::create($metric);
}
}
}

View File

@@ -61,6 +61,10 @@ class SettingsTableSeeder extends Seeder
'name' => 'app_analytics_gs',
'value' => 'GSN-712462-P',
],
[
'name' => 'display_graphs',
'value' => '1',
],
];
Setting::truncate();