diff --git a/src/Console/Commands/CountUniqueUser.php b/src/Console/Commands/CountUniqueUser.php index 863a911..834e7d3 100644 --- a/src/Console/Commands/CountUniqueUser.php +++ b/src/Console/Commands/CountUniqueUser.php @@ -30,17 +30,15 @@ class CountUniqueUser extends Command */ public function handle() { - $nbrUser = $this->countUniqueUser(); + $fromDate = Carbon::now()->subMonth()->startOfMonth()->toDateString(); + $tillDate = Carbon::now()->subMonth()->endOfMonth()->toDateString(); - $date = Carbon::now()->subMonth()->endOfMonth()->toDateString(); + $nbrUser = User::whereBetween('login_at', [$fromDate, $tillDate])->count(); - DB::table('kpis_unique_users')->insert(['date' => $date, 'value' => $nbrUser]); + DB::table('kpis_unique_users')->insert(['date' => $tillDate, 'value' => $nbrUser]); } private function countUniqueUser() { - $fromDate = Carbon::now()->subMonth()->startOfMonth()->toDateString(); - $tillDate = Carbon::now()->subMonth()->endOfMonth()->toDateString(); - return User::whereBetween('login_at', [$fromDate, $tillDate])->count(); } } diff --git a/src/Console/Commands/CountUser.php b/src/Console/Commands/CountUser.php index d4c65e3..6efff5b 100644 --- a/src/Console/Commands/CountUser.php +++ b/src/Console/Commands/CountUser.php @@ -29,16 +29,10 @@ class CountUser extends Command * @return void */ public function handle() - { - $nbrUser = $this->countUser(); - - DB::table('kpis_users')->insert(['date' => Carbon::yesterday()->toDateString(), 'value' => $nbrUser]); - } - - private function countUser() { $yesterday = Carbon::yesterday()->toDateString(); + $nbrUser = User::where('login_at', '=', $yesterday)->count(); - return User::where('login_at', '=', $yesterday)->count(); + DB::table('kpis_users')->insert(['date' => $yesterday, 'value' => $nbrUser]); } } diff --git a/src/Console/Commands/DetermineStorageUsage.php b/src/Console/Commands/DetermineStorageUsage.php index 82f87c7..2a504ee 100644 --- a/src/Console/Commands/DetermineStorageUsage.php +++ b/src/Console/Commands/DetermineStorageUsage.php @@ -10,6 +10,11 @@ class DetermineStorageUsage extends Command { + /** + * GB in byte. + */ + const GB = 1000000000; + /** * The console command name. * @@ -32,7 +37,7 @@ class DetermineStorageUsage extends Command public function handle() { $size = $this->getSizeInGB(); - + $date = Carbon::now()->subMonth()->endOfMonth()->toDateString(); DB::table('kpis_storage_usage')->insert(['date' => $date, 'value' => $size]); @@ -40,9 +45,9 @@ public function handle() private function getSizeInGB() { - $byte = 1000000000; $imageStorageUsage = Image::sum(DB::raw("(attrs->>'size')::bigint")); $videoStorageUsage = Video::sum(DB::raw("(attrs->>'size')::bigint")); - return ($imageStorageUsage + $videoStorageUsage)/$byte; + + return ($imageStorageUsage + $videoStorageUsage) / self::GB; } } diff --git a/src/KpisServiceProvider.php b/src/KpisServiceProvider.php index c7b8dda..0d28423 100644 --- a/src/KpisServiceProvider.php +++ b/src/KpisServiceProvider.php @@ -50,10 +50,6 @@ public function boot(Modules $modules, Router $router) ], ]); - $this->publishes([ - __DIR__.'/public/assets' => public_path('vendor/kpis'), - ], 'public'); - if ($this->app->runningInConsole()) { $this->commands([ CountUniqueUser::class, diff --git a/src/config/kpis.php b/src/config/kpis.php index b59d3ed..6920879 100644 --- a/src/config/kpis.php +++ b/src/config/kpis.php @@ -2,9 +2,7 @@ return [ /** - * * Token to verify cron job request to save visits/actions - * - **/ + */ 'token' => env('KPIS_TOKEN'), ];