<commit_before><?php

namespace TaskTracker\Listener;

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use TaskTracker\Events;
use TaskTracker\Helper\BytesToHumanTrait;
use TaskTracker\Tick;

/**
 * Symfony Console Progress Meter Listener
 *
 * @author <NAME> <<EMAIL>>
 */
class SymfonyConsoleProgress implements EventSubscriberInterface
{
    use BytesToHumanTrait;

    // ---------------------------------------------------------------

    /**
     * @var OutputInterface;
     */
    private $output;

    /**
     * @var ProgressBar|null
     */
    private $progressBar;

    // --------------------------------------------------------------

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            Events::TRACKER_START  => 'start',
            Events::TRACKER_TICK   => 'tick',
            Events::TRACKER_FINISH => 'finish',
            Events::TRACKER_ABORT  => 'abort'
        ];
    }

    // --------------------------------------------------------------

    /**
     * Constructor
     *
     * @param OutputInterface $output
     */
    public function __construct(OutputInterface $output)
    {
        $this->output = $output;
    }

    // ---------------------------------------------------------------

    public function start(Tick $tick)
    {
        if ($tick->getMessage()) {
            $this->output->writeln($tick->getMessage());
        }

        $this->progressBar = new ProgressBar(
            $this->output,
            $tick->getReport()->getTotalItemCount() > -1
                ? $tick->getReport()->getTotalItemCount()
                : 0
        );
    }

    // ---------------------------------------------------------------

    public function tick(Tick $tick)
    {
        $rpt = $tick->getReport();


        $msgSegs = [$tick->getMessage()];

        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $msgSegs[] = sprintf('Processed: <fg=green>%s</fg=green>', number_format($rpt->getNumItemsSuccess(), 0));
            $msgSegs[] = sprintf('Skipped: <fg=yellow>%s</fg=yellow>', number_format($rpt->getNumItemsFail(), 0));
            $msgSegs[] = sprintf('Failed: <fg=red>%s</fg=red>'       , number_format($rpt->getNumItemsSkip(), 0));
        }

        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {

            $msgSegs[] = sprintf("Avg: %s", number_format($rpt->getAvgItemTime(), 2));

            $msgSegs[] = sprintf(
                'Memory: %s/%s',
                $this->bytesToHuman($rpt->getMemUsage(),   2),
                $this->bytesToHuman($rpt->getMemPeakUsage(), 2)
            );
        }

        $this->progressBar->setProgress($rpt->getNumItemsProcessed());
        $this->progressBar->setMessage(implode(' | ', $msgSegs));
    }


    public function finish(Tick $tick)
    {
        $this->progressBar->finish();

        if ($tick->getMessage()) {
            $this->output->writeln($tick->getMessage());
        }

    }

    public function abort(Tick $tick)
    {<commit_msg>Some tweaks to the Symfony Console Progress bar output.<commit_after><?php

namespace TaskTracker\Listener;

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use TaskTracker\Events;
use TaskTracker\Helper\BytesToHumanTrait;
use TaskTracker\Tick;

/**
 * Symfony Console Progress Meter Listener
 *
 * @author <NAME> <<EMAIL>>
 */
class SymfonyConsoleProgress implements EventSubscriberInterface
{
    use BytesToHumanTrait;

    // ---------------------------------------------------------------

    /**
     * @var OutputInterface;
     */
    private $output;

    /**
     * @var ProgressBar|null
     */
    private $progressBar;

    // --------------------------------------------------------------

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            Events::TRACKER_START  => 'start',
            Events::TRACKER_TICK   => 'tick',
            Events::TRACKER_FINISH => 'finish',
            Events::TRACKER_ABORT  => 'abort'
        ];
    }

    // --------------------------------------------------------------

    /**
     * Constructor
     *
     * @param OutputInterface $output
     */
    public function __construct(OutputInterface $output)
    {
        $this->output = $output;
    }

    // ---------------------------------------------------------------

    public function start(Tick $tick)
    {
        if ($tick->getMessage()) {
            $this->output->writeln($tick->getMessage());
        }

        $this->progressBar = new ProgressBar(
            $this->output,
            $tick->getReport()->getTotalItemCount() > -1
                ? $tick->getReport()->getTotalItemCount()
                : 0
        );

        $this->progressBar->start();
        $this->progressBar->setProgress(0);
    }

    // ---------------------------------------------------------------

    public function tick(Tick $tick)
    {
        $rpt = $tick->getReport();


        $msgSegs = [$tick->getMessage()];

        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $msgSegs[] = sprintf('Processed: <fg=green>%s</fg=green>', number_format($rpt->getNumItemsSuccess(), 0));
            $msgSegs[] = sprintf('Skipped: <fg=yellow>%s</fg=yellow>', number_format($rpt->getNumItemsFail(), 0));
            $msgSegs[] = sprintf('Failed: <fg=red>%s</fg=red>'       , number_format($rpt->getNumItemsSkip(), 0));
        }

        if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {

            $msgSegs[] = sprintf("Avg: %s", number_format($rpt->getAvgItemTime(), 2));

            $msgSegs[] = sprintf(
                'Memory: %s/%s',
                $this->bytesToHuman($rpt->getMemUsage(),   2),
                $this->bytesToHuman($rpt->getMemPeakUsage(), 2)
            );
        }

        $this->progressBar->setMessage(implode(' | ', $msgSegs));
        $this->progressBar->advance($rpt->getTick()->getIncrementBy());
    }


    public function finish(Tick $tick)
    {
        $this->progressBar->finish();

        if ($tick->getMessage()) {
            $this->output->writeln($tick->getMessage());
        }

    }

    public function abort(Tick $tick)
    {
{'fraction_non_alphanumeric': 0.23835700106886548, 'fraction_numerical': 0.002595816155138189, 'mean_word_length': 1.6976935749588138, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 112, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1200041', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1795, 'n_words': 276}