Bläddra i källkod

Merge pull request #2191 from visuddhinanda/laravel

add count in nisssya export
visuddhinanda 1 år sedan
förälder
incheckning
f04b64ad63
2 ändrade filer med 15 tillägg och 11 borttagningar
  1. 1 1
      app/Console/Commands/ExportArticle.php
  2. 14 10
      app/Console/Commands/StatisticsNissaya.php

+ 1 - 1
app/Console/Commands/ExportArticle.php

@@ -135,7 +135,7 @@ class ExportArticle extends Command
                 'anthology'=> $this->option('anthology'),
                 'channel' => $this->option('channel'),
         ];
-
+        Log::debug('export article http request',['url'=>$url,'param'=>$urlParam]);
         if($this->option('token')){
             $response = Http::withToken($this->option('token'))->get($url,$urlParam);
         }else{

+ 14 - 10
app/Console/Commands/StatisticsNissaya.php

@@ -12,7 +12,7 @@ class StatisticsNissaya extends Command
 {
     /**
      * The name and signature of the console command.
-     *
+     * php artisan statistics:nissaya
      * @var string
      */
     protected $signature = 'statistics:nissaya';
@@ -44,13 +44,13 @@ class StatisticsNissaya extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $nissaya_channel = Channel::where('type','nissaya')->select('uid')->get();
-        $this->info('channel:'.count($nissaya_channel));
-        $maxDay = 360;
+        $nissaya_channels = Channel::where('type','nissaya')->select('uid')->get();
+        $this->info('channel:'.count($nissaya_channels));
         $file = "public/statistics/nissaya-monthly.csv";
+
         Storage::disk('local')->put($file, "");
         #按月获取数据
-        $firstDay = Sentence::whereIn('channel_uid',$nissaya_channel)
+        $firstDay = Sentence::whereIn('channel_uid',$nissaya_channels)
                             ->orderBy('created_at')
                             ->select('created_at')
                             ->first();
@@ -59,26 +59,30 @@ class StatisticsNissaya extends Command
         $now = Carbon::now();
         $current = $firstMonth;
         $sumStrlen = 0;
+        $sumCount = 0;
         while ($current <= $now) {
             # code...
             $start = Carbon::create($current)->startOfMonth();
             $end = Carbon::create($current)->endOfMonth();
             $date = $current->format('Y-m');
-            $strlen = Sentence::whereIn('channel_uid',$nissaya_channel)
+            $table = Sentence::whereIn('channel_uid',$nissaya_channels)
                               ->whereDate('created_at','>=',$start)
-                              ->whereDate('created_at','<=',$end)
-                              ->sum('strlen');
+                              ->whereDate('created_at','<=',$end);
+            $strlen =  $table->sum('strlen');
             $sumStrlen += $strlen;
-            $editor = Sentence::whereIn('channel_uid',$nissaya_channel)
+            $count = $table->count();
+            $sumCount += $count;
+            $editor = Sentence::whereIn('channel_uid',$nissaya_channels)
                               ->whereDate('created_at','>=',$start)
                               ->whereDate('created_at','<=',$end)
                               ->groupBy('editor_uid')
                               ->select('editor_uid')->get();
-            $info = $date.','.$strlen.','.$sumStrlen.','.count($editor);
+            $info = "{$date},{$strlen},{$sumStrlen},{$count},{$sumCount},".count($editor);
             $this->info($info);
             Storage::disk('local')->append($file, $info);
             $current->addMonth(1);
         }
+        $this->info('path='.$file);
         return 0;
     }
 }