]> git.localhorst.tv Git - alttp.git/blobdiff - app/Console/Commands/ChatlibDatabase.php
separate chatlib database generation
[alttp.git] / app / Console / Commands / ChatlibDatabase.php
index cb7978f6e92bb84074c183354dc85f04766d1d36..e492bb7c1169160fafea1c9a938aec7f5b0c8b86 100644 (file)
@@ -13,14 +13,14 @@ class ChatlibDatabase extends Command {
         *
         * @var string
         */
-       protected $signature = 'chatlib:database';
+       protected $signature = 'chatlib:database {which=de} {size=7}';
 
        /**
         * The console command description.
         *
         * @var string
         */
-       protected $description = 'Updates the ChatLib database';
+       protected $description = 'Update a ChatLib database';
 
        /**
         * Execute the console command.
@@ -28,22 +28,38 @@ class ChatlibDatabase extends Command {
         * @return int
         */
        public function handle() {
-               $db = new ChatLib();
+               $count = 0;
+               $start = time();
+
+               $size = $this->argument('size');
+               $lang = $this->argument('which');
+               $db = new ChatLib($size);
 
                ChatLog::where('type', '=', 'chat')
                        ->where('banned', '=', false)
                        ->whereNotNull('evaluated_at')
-                       ->chunk(500, function ($msgs) use ($db) {
+                       ->where('created_at', '<', now()->sub(7, 'day'))
+                       ->whereNotIn('classification', ['gg', 'gl', 'number', 'o7'])
+                       ->where(function ($query) use ($lang) {
+                               $query->whereNull('detected_language');
+                               $query->orWhere('detected_language', '=', $lang);
+                       })
+                       ->whereRaw('LENGTH(`text_content`) > 10')
+                       ->chunk(5000, function ($msgs) use (&$count, $db) {
                                foreach ($msgs as $msg) {
                                        $db->addMessage($msg);
+                                       ++$count;
                                }
+                               $this->line($count);
                        });
 
                $db->compile();
+               $db->saveAs($lang);
 
-               for ($i = 0; $i < 50; ++$i) {
-                       $this->line($db->generate());
-               }
+               $this->line(
+                       number_format(time() - $start, 0).'s '.
+                       number_format(memory_get_usage() / 1024 / 1024, 3).'MB now '.
+                       number_format(memory_get_peak_usage() / 1024 / 1024, 3).'MB peak');
 
                return 0;
        }