X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FChatlibDatabase.php;h=e492bb7c1169160fafea1c9a938aec7f5b0c8b86;hb=4c72d4b8bec61eba5b3dc43df5eafd890e123d37;hp=bfe0135c4b8e00e684a9f2974faf862f447296fd;hpb=c2cc99020eee56f7790d1358abb44df078f2e655;p=alttp.git diff --git a/app/Console/Commands/ChatlibDatabase.php b/app/Console/Commands/ChatlibDatabase.php index bfe0135..e492bb7 100644 --- a/app/Console/Commands/ChatlibDatabase.php +++ b/app/Console/Commands/ChatlibDatabase.php @@ -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,36 +28,38 @@ class ChatlibDatabase extends Command { * @return int */ public function handle() { - $de = new ChatLib(); - $en = 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(5000, function ($msgs) use ($de, $en) { + ->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) { - if ($msg->detected_language === 'de') { - $de->addMessage($msg); - } else if ($msg->detected_language === 'en') { - $en->addMessage($msg); - } else if (is_null($msg->detected_language)) { - $de->addMessage($msg); - $en->addMessage($msg); - } + $db->addMessage($msg); + ++$count; } + $this->line($count); }); - $de->compile(); - $en->compile(); + $db->compile(); + $db->saveAs($lang); - $this->line(''); - for ($i = 0; $i < 50; ++$i) { - $this->line($de->generate()); - } - $this->line(''); - for ($i = 0; $i < 50; ++$i) { - $this->line($en->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; }