Forráskód Böngészése

Merge branch 'laravel' of https://github.com/visuddhinanda/mint into laravel

visuddhinanda 2 éve
szülő
commit
1bad33680e
1 módosított fájl, 20 hozzáadás és 10 törlés
  1. 20 10
      app/Console/Commands/UpgradeCompound.php

+ 20 - 10
app/Console/Commands/UpgradeCompound.php

@@ -5,18 +5,16 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
 use App\Models\WordIndex;
 use App\Models\WbwTemplate;
-use App\Models\UserDict;
 use App\Tools\TurboSplit;
 use App\Http\Api\DictApi;
 use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Http;
 
 class UpgradeCompound extends Command
 {
     /**
      * The name and signature of the console command.
-     * php artisan upgrade:compound --api=https://staging.wikipali.org/api
+     * php -d memory_limit=1024M artisan upgrade:compound  --api=https://next.wikipali.org/api --from=182852 --to=30000
      * @var string
      */
     protected $signature = 'upgrade:compound {word?} {--book=} {--debug} {--test} {--continue} {--api=} {--from=} {--to=}';
@@ -48,12 +46,11 @@ class UpgradeCompound extends Command
     public function handle()
     {
         if(\App\Tools\Tools::isStop()){
-            return 0;
-        }
-        if(file_exists(base_path('.stop'))){
             $this->info('.stop exists');
             return 0;
         }
+        $this->info('['.date('Y-m-d H:i:s', time()).'] upgrade:compound start');
+
         $dict_id = DictApi::getSysDict('robot_compound');
         if(!$dict_id){
             $this->error('没有找到 robot_compound 字典');
@@ -118,14 +115,22 @@ class UpgradeCompound extends Command
             $min = WordIndex::min('id');
             $max = WordIndex::max('id');
             if($this->option('from')){
-                $min = $min + $this->option('from');
+                $from = $min + $this->option('from');
+            }else{
+                $from = $min;
+            }
+            if($this->option('to')){
+                $to = $min + $this->option('to');
+            }else{
+                $to = $max;
             }
-            $words = WordIndex::whereBetween('id',[$min,$max])
+            $words = WordIndex::whereBetween('id',[$from,$to])
                             ->where('len','>',7)
+                            ->where('len','<',51)
                             ->orderBy('id')
                             ->selectRaw('word as real')
                             ->cursor();
-            $count = $max - $min + 1;
+            $count = $to - $from + 1;
         }
 
 		$sn = 0;
@@ -135,6 +140,7 @@ class UpgradeCompound extends Command
             if(\App\Tools\Tools::isStop()){
                 return 0;
             }
+            $sn++;
             $startAt = microtime(true);
 
 			$ts = new TurboSplit();
@@ -145,7 +151,8 @@ class UpgradeCompound extends Command
             $parts = $ts->splitA($word->real);
             $time = round(microtime(true) - $startAt,2);
             $percent = (int)($sn * 100 / $count);
-            $this->info("[{$percent}%] {$word->real}  {$time}s");
+
+            $this->info("[{$percent}%][{$sn}] {$word->real}  {$time}s");
 
             $resultCount = 0;
             foreach ($parts as $part) {
@@ -187,6 +194,9 @@ class UpgradeCompound extends Command
             }
 		}
         $this->upload($wordIndex,$result,$this->option('api'));
+
+        $this->info('['.date('Y-m-d H:i:s', time()).'] upgrade:compound finished');
+
         return 0;
     }