visuddhinanda 1 год назад
Родитель
Сommit
39ab82de00
1 измененных файлов с 22 добавлено и 22 удалено
  1. 22 22
      app/Console/Commands/UpgradeProgress.php

+ 22 - 22
app/Console/Commands/UpgradeProgress.php

@@ -51,7 +51,7 @@ class UpgradeProgress extends Command
         $para = $this->option('para');
         $channelId = $this->option('channel');
         if($book && $para && $channelId){
-            $channels = Sentence::where('strlen','>',0)
+            $sentences = Sentence::where('strlen','>',0)
                           ->where('book_id',$book)
                           ->where('paragraph',$para)
                           ->where('channel_uid',$channelId)
@@ -59,7 +59,7 @@ class UpgradeProgress extends Command
                           ->select('book_id','paragraph','channel_uid')
                           ->cursor();
         }else{
-            $channels = Sentence::where('strlen','>',0)
+            $sentences = Sentence::where('strlen','>',0)
                           ->where('book_id','<',1000)
                           ->where('channel_uid','<>','')
                           ->groupby('book_id','paragraph','channel_uid')
@@ -67,27 +67,27 @@ class UpgradeProgress extends Command
                           ->cursor();
         }
 
-        $this->info('channels:',count($channels));
+        $this->info('sentences:',count($sentences));
         #第二步 更新段落表
-        $bar = $this->output->createProgressBar(count($channels));
-        foreach ($channels as $channel) {
+        $bar = $this->output->createProgressBar(count($sentences));
+        foreach ($sentences as $sentence) {
             # 第二步 生成para progress 1,2,15,zh-tw
             # 计算此段落完成时间
             $finalAt = Sentence::where('strlen','>',0)
-                        ->where('book_id',$channel->book_id)
-                        ->where('paragraph',$channel->paragraph)
-                        ->where('channel_uid',$channel->channel_uid)
+                        ->where('book_id',$sentence->book_id)
+                        ->where('paragraph',$sentence->paragraph)
+                        ->where('channel_uid',$sentence->channel_uid)
                         ->max('created_at');
             $updateAt = Sentence::where('strlen','>',0)
-                        ->where('book_id',$channel->book_id)
-                        ->where('paragraph',$channel->paragraph)
-                        ->where('channel_uid',$channel->channel_uid)
+                        ->where('book_id',$sentence->book_id)
+                        ->where('paragraph',$sentence->paragraph)
+                        ->where('channel_uid',$sentence->channel_uid)
                         ->max('updated_at');
             # 查询每个段落的等效巴利语字符数
             $result_sent = Sentence::where('strlen','>',0)
-                                    ->where('book_id',$channel->book_id)
-                                    ->where('paragraph',$channel->paragraph)
-                                    ->where('channel_uid',$channel->channel_uid)
+                                    ->where('book_id',$sentence->book_id)
+                                    ->where('paragraph',$sentence->paragraph)
+                                    ->where('channel_uid',$sentence->channel_uid)
                                     ->select('word_start')
                                     ->get();
             if (count($result_sent) > 0) {
@@ -95,25 +95,25 @@ class UpgradeProgress extends Command
                 $para_strlen = 0;
                 foreach ($result_sent as $sent) {
                     # code...
-                    $para_strlen += PaliSentence::where('book',$channel->book_id)
-                                ->where('paragraph',$channel->paragraph)
+                    $para_strlen += PaliSentence::where('book',$sentence->book_id)
+                                ->where('paragraph',$sentence->paragraph)
                                 ->where('word_begin',$sent->word_start)
                                 ->value('length');
                 }
-
-                Progress::updateOrInsert(
-                    [
+                $paraInfo = [
                         'book'=>$channel->book_id,
                         'para'=>$channel->paragraph,
                         'channel_id'=>$channel->channel_uid
-                    ],
-                    [
+                ];
+                $paraData = [
                         'lang'=>'en',
                         'all_strlen'=>$para_strlen,
                         'public_strlen'=>$para_strlen,
                         'created_at'=>$finalAt,
                         'updated_at'=>$updateAt,
-                    ]);
+                ];
+                Log::debug('Progress updateOrInsert',['para'=>$paraInfo,'data'=>$paraData]);
+                Progress::updateOrInsert($paraInfo,$paraData);
             }
             $bar->advance();
         }