<commit_before><?php

namespace PHPWorldWide\Stats\Command;

use PHPWorldWide\Stats\Fetcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use PHPWorldWide\Stats\Auth;
use PHPWorldWide\Stats\Config;
use PHPWorldWide\Stats\Log;
use PHPWorldWide\Stats\Mapper;
use Twig_Environment;
use Twig_Template;

/**
 * Class GenerateCommand
 * @package PHPWorldWide\Stats\Command
 */
class GenerateCommand extends Command
{
    /**
     * @var Twig_Template
     */
    private $template;

    /**
     * @var Config
     */
    private $config;

    /**
     * @var Auth
     */
    private $auth;

    /**
     * @var Log
     */
    private $log;

    /**
     * Set configuration.
     *
     * @param Config $config
     */
    public function setConfig(Config $config)
    {
        $this->config = $config;
    }

    /**
     * Set template.
     *
     * @param Twig_Environment $twig
     */
    public function setTemplate(Twig_Environment $twig)
    {
        $this->template = $twig->loadTemplate('report.txt.twig');
    }

    /**
     * Set authentication.
     *
     * @param Auth $auth
     */
    public function setAuth(Auth $auth)
    {
        $this->auth = $auth;
    }

    /**
     * @param Log $log
     */
    public function setLog(Log $log)
    {
        $this->log = $log;
    }

    /**
     * Configures generate command for Console component.
     */
    protected function configure()
    {
        try {
            $this
                ->setName('generate')
                ->setDescription('Generates Facebook group stats report.')
                ->setHelp('This command generates Facebook group stats report.')
                ->addOption(
                    'from',
                    'f',
                    InputOption::VALUE_REQUIRED,
                    'Start date of the generated stats report ('.date('Y-m-d', strtotime('last monday')).')',
                    date('Y-m-d', strtotime('last monday'))
                )
                ->addOption(
                    'to',
                    't',
                    InputOption::VALUE_REQUIRED,
                    'End date of the generated stats report ('.date('Y-m-d', strtotime('last monday +7 days')).')',
                    date('Y-m-d', strtotime('last monday +7 days'))
                )
            ;
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $fromDate = $input->getOption('from').' 00:00:00';
        $toDate = $input->getOption('to').' 23:59:59';

        $this->config->setParameter('start_datetime', $fromDate);
        $this->config->setParameter('end_datetime', $toDate);

        $progress = new ProgressBar($output, 40);
        $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%\n\n");
        $progress->setMessage('Starting...');
        $progress->setProgressCharacter("\xF0\x9F\x8D\xBA");

        if (!$this->auth->isValid()) {
            $helper = $this->getHelper('question');

            $question = new Question($this->auth->getError()."\n\n".
                "Enter user access token from the Graph API Explorer\n".
                "https://developers.facebook.com/tools/explorer\n");<commit_msg>Fix minor bug for weekly stats timeframe<commit_after><?php

namespace PHPWorldWide\Stats\Command;

use PHPWorldWide\Stats\Fetcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use PHPWorldWide\Stats\Auth;
use PHPWorldWide\Stats\Config;
use PHPWorldWide\Stats\Log;
use PHPWorldWide\Stats\Mapper;
use Twig_Environment;
use Twig_Template;

/**
 * Class GenerateCommand
 * @package PHPWorldWide\Stats\Command
 */
class GenerateCommand extends Command
{
    /**
     * @var Twig_Template
     */
    private $template;

    /**
     * @var Config
     */
    private $config;

    /**
     * @var Auth
     */
    private $auth;

    /**
     * @var Log
     */
    private $log;

    /**
     * Set configuration.
     *
     * @param Config $config
     */
    public function setConfig(Config $config)
    {
        $this->config = $config;
    }

    /**
     * Set template.
     *
     * @param Twig_Environment $twig
     */
    public function setTemplate(Twig_Environment $twig)
    {
        $this->template = $twig->loadTemplate('report.txt.twig');
    }

    /**
     * Set authentication.
     *
     * @param Auth $auth
     */
    public function setAuth(Auth $auth)
    {
        $this->auth = $auth;
    }

    /**
     * @param Log $log
     */
    public function setLog(Log $log)
    {
        $this->log = $log;
    }

    /**
     * Configures generate command for Console component.
     */
    protected function configure()
    {
        try {
            $this
                ->setName('generate')
                ->setDescription('Generates Facebook group stats report.')
                ->setHelp('This command generates Facebook group stats report.')
                ->addOption(
                    'from',
                    'f',
                    InputOption::VALUE_REQUIRED,
                    'Start date of the generated stats report ('.date('Y-m-d', strtotime('last monday')).')',
                    date('Y-m-d', strtotime('last monday'))
                )
                ->addOption(
                    'to',
                    't',
                    InputOption::VALUE_REQUIRED,
                    'End date of the generated stats report ('.date('Y-m-d', strtotime('last monday +7 days')).')',
                    date('Y-m-d', strtotime('last monday +6 days'))
                )
            ;
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }

    /**
     * @inheritdoc
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $fromDate = $input->getOption('from').' 00:00:00';
        $toDate = $input->getOption('to').' 23:59:59';

        $this->config->setParameter('start_datetime', $fromDate);
        $this->config->setParameter('end_datetime', $toDate);

        $progress = new ProgressBar($output, 40);
        $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%\n\n");
        $progress->setMessage('Starting...');
        $progress->setProgressCharacter("\xF0\x9F\x8D\xBA");

        if (!$this->auth->isValid()) {
            $helper = $this->getHelper('question');

            $question = new Question($this->auth->getError()."\n\n".
                "Enter user access token from the Graph API Explorer\n".
                "https://developers.facebook.com/tools/explorer\n");
{'fraction_non_alphanumeric': 0.1432712215320911, 'fraction_numerical': 0.006349206349206349, 'mean_word_length': 1.970889708897089, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1340959', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2093, 'n_words': 423}