feat: Abstract progress info into utility class

This commit is contained in:
Dendy 2025-05-01 15:44:26 +02:00
parent b7ec7623b2
commit cfaafb58e1
2 changed files with 29 additions and 12 deletions

View File

@ -123,18 +123,9 @@ class CreateProductionCommand extends Command
}
printf(" OK (%d)\n", count($knownTerms));
$total = count($knownTerms);
$i = 0;
foreach ($allNotes as $note) {
$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
);
}
$progress = new Progress('Getting frequenciees', count($allSentenceNotes));
foreach ($allSentenceNotes as $note) {
$progress->tick();
assert($note instanceof SentenceNote);

26
src/Utils/Progress.php Normal file
View File

@ -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
);
}
}
}