feat: Abstract progress info into utility class
This commit is contained in:
parent
b7ec7623b2
commit
cfaafb58e1
|
@ -123,18 +123,9 @@ class CreateProductionCommand extends Command
|
||||||
}
|
}
|
||||||
printf(" OK (%d)\n", count($knownTerms));
|
printf(" OK (%d)\n", count($knownTerms));
|
||||||
|
|
||||||
$total = count($knownTerms);
|
$progress = new Progress('Getting frequenciees', count($allSentenceNotes));
|
||||||
$i = 0;
|
foreach ($allSentenceNotes as $note) {
|
||||||
foreach ($allNotes as $note) {
|
$progress->tick();
|
||||||
$i += 1;
|
|
||||||
if ($i % 12 === 0 or $i === $total) {
|
|
||||||
printf(
|
|
||||||
"\33[2K\r% 7d/% 7d | %.2f GiB | Getting frequencies",
|
|
||||||
$i,
|
|
||||||
$total,
|
|
||||||
memory_get_usage() / 1024 / 1024 / 1024
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
assert($note instanceof SentenceNote);
|
assert($note instanceof SentenceNote);
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Utils;
|
||||||
|
|
||||||
|
class Progress
|
||||||
|
{
|
||||||
|
function __construct(
|
||||||
|
private string $message,
|
||||||
|
private int $total,
|
||||||
|
private int $speed = 12,
|
||||||
|
private int $i = 0,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function tick()
|
||||||
|
{
|
||||||
|
$this->i += 1;
|
||||||
|
if ($this->i % $this->speed === 0 or $this->i === $this->total) {
|
||||||
|
printf(
|
||||||
|
"\33[2K\r% 7d/% 7d | %.2f GiB | {$this->message}",
|
||||||
|
$this->i,
|
||||||
|
$this->total,
|
||||||
|
memory_get_usage() / 1024 / 1024 / 1024
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue