2
0
Эх сурвалжийг харах

Merge pull request #2193 from visuddhinanda/laravel

100句为一页统计
visuddhinanda 1 жил өмнө
parent
commit
7dd7dc45a7

+ 6 - 9
app/Console/Commands/ExportNissaya.php

@@ -45,18 +45,15 @@ class ExportNissaya extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $nissaya_channel = Channel::where('type','nissaya')->select('uid')->get();
-        $channels = [];
-        foreach ($nissaya_channel as $key => $value) {
-            # code...
-            $channels[] = $value->uid;
-        }
-        $this->info('channel:'.count($channels));
+        $nissaya_channels = Channel::where('type','nissaya')
+                            ->where('lang','my')
+                            ->select('uid')->get();
+        $this->info('channel:'.count($nissaya_channels));
         $filename = "public/export/nissaya.csv";
         Storage::disk('local')->put($filename, "");
         $file = fopen(storage_path("app/$filename"),"w");
-        $bar = $this->output->createProgressBar(Sentence::whereIn('channel_uid',$channels)->count());
-        foreach (Sentence::whereIn('channel_uid',$channels)->select('content')->cursor() as $sent) {
+        $bar = $this->output->createProgressBar(Sentence::whereIn('channel_uid',$nissaya_channels)->count());
+        foreach (Sentence::whereIn('channel_uid',$nissaya_channels)->select('content')->cursor() as $sent) {
             $lines = explode("\n",$sent->content);
             foreach ($lines as $key => $line) {
                 # code...

+ 3 - 1
app/Console/Commands/StatisticsNissaya.php

@@ -44,7 +44,9 @@ class StatisticsNissaya extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $nissaya_channels = Channel::where('type','nissaya')->select('uid')->get();
+        $nissaya_channels = Channel::where('type','nissaya')
+                            ->where('lang','my')
+                            ->select('uid')->get();
         $this->info('channel:'.count($nissaya_channels));
         $file = "public/statistics/nissaya-monthly.csv";
 

+ 14 - 3
app/Console/Commands/StatisticsNissayaCover.php

@@ -97,7 +97,9 @@ class StatisticsNissayaCover extends Command
         if(\App\Tools\Tools::isStop()){
             return 0;
         }
-        $nissaya_channels = Channel::where('type','nissaya')->select('uid')->get();
+        $nissaya_channels = Channel::where('type','nissaya')
+                                ->where('lang','my')
+                                ->select('uid')->get();
         $this->info('channel:'.count($nissaya_channels));
         $output = [];
         foreach ($this->types as $type => $books) {
@@ -110,7 +112,9 @@ class StatisticsNissayaCover extends Command
                                 ->get();
             $sentences = [];
             $final = 0;
+            $this->info($type . count($nissayaSentences). " sentences");
             if(count($nissayaSentences)>0){
+                $count = 0;
                 foreach ($nissayaSentences as  $value) {
                     $sentences[] = [
                         $value->book_id,
@@ -118,9 +122,16 @@ class StatisticsNissayaCover extends Command
                         $value->word_start,
                         $value->word_end,
                     ];
-                }
-                $final = PaliSentence::whereIns(['book','paragraph','word_begin','word_end'],$sentences)
+                    if($count % 100 === 0 ){
+                        $final += PaliSentence::whereIns(['book','paragraph','word_begin','word_end'],$sentences)
                                         ->sum('length');
+                        $sentences = [];
+                        $percent = intval($count * 100 / count($nissayaSentences));
+                        $this->info("[{$percent}] {$final}");
+                    }
+                    $count++;
+                }
+
             }
 
             $this->info($type . '=' . $pali . '=' . $final);