Added highcharts stats via /stats
This commit is contained in:
31
app/Http/Controllers/StatsController.php
Normal file
31
app/Http/Controllers/StatsController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use AgliPanci\LaravelCase\Facades\CaseBuilder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
use App\Models\SiteVersion;
|
||||
|
||||
class StatsController extends Controller
|
||||
{
|
||||
public function home()
|
||||
{
|
||||
$case = CaseBuilder::whenRaw("version ~ '-dev-'")->thenRaw("CONCAT(SPLIT_PART(version,'-',1),'-',SPLIT_PART(version,'-',2))")
|
||||
->whenRaw("version ~ '-00000000$'")->thenRaw("CONCAT(SPLIT_PART(version,'-',1),'-GH')")
|
||||
->whenRaw("version ~ '^v[0-9]+\.[0-9]+\.[0-9]+'")->thenRaw("SPLIT_PART(version,'-',1)")
|
||||
->elseRaw("'unknown'");
|
||||
|
||||
$stats = SiteVersion::select([
|
||||
DB::raw('DATE(site_versions.created_at) AS created_at'),
|
||||
//'site_versions.version',
|
||||
DB::raw('count(distinct site_id) as total')
|
||||
])
|
||||
->selectRaw($case->toRaw().' AS ver')
|
||||
->groupBy([DB::raw('DATE(site_versions.created_at)'),'ver'])
|
||||
;
|
||||
|
||||
return view('stats')
|
||||
->with('query',$stats->get());
|
||||
}
|
||||
}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SiteVersion extends Model
|
||||
@@ -12,4 +13,10 @@ class SiteVersion extends Model
|
||||
{
|
||||
return $this->belongsTo(Site::class);
|
||||
}
|
||||
|
||||
/* ATTRIBUTES */
|
||||
public function getDateAttribute(): int
|
||||
{
|
||||
return Carbon::parse($this->attributes['created_at'])->timestamp*1000;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user