<commit_before><?php

namespace mh\BTBundle\Command;

use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use mh\Common\Random;
use mh\BTBundle\Entity as Entity;

class UserGeneratorCommand extends DoctrineCommand
{
	const DATA_DIR = '/Data/';

	protected function configure()
    {
        $this
            ->setName('mh:gen:user')
            ->setDescription('User generator')
            ->addArgument('count', InputArgument::REQUIRED, 'What count of user you want to generate?')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
		$users = $this->generate($input->getArgument('count'));
		$em = $this->getEntityManager(null);

		foreach ($users as $user) {
			$output->writeln($user->getLogin());
			$em->persist($user);
		}

		$em->flush();
	}

	private function generate($count)
    {
        $users = array();

        $m_names = file(__DIR__.self::DATA_DIR."m_names.txt", FILE_IGNORE_NEW_LINES);
        $m_second_names = file(__DIR__.self::DATA_DIR."m_second_names.txt", FILE_IGNORE_NEW_LINES);

        $f_names = file(__DIR__.self::DATA_DIR."f_names.txt");
        $f_second_names = file(__DIR__.self::DATA_DIR."f_second_names.txt", FILE_IGNORE_NEW_LINES);

        $nicknames = file(__DIR__.self::DATA_DIR."nicknames.txt", FILE_IGNORE_NEW_LINES);

        for ($i = 0; $i < $count; $i++) {

            if (mt_rand(0, 1) == 0) {
                $name = Random::getArrayElement($m_names);
                $sname = Random::getArrayElement($m_second_names);
            } else {
                $name = Random::getArrayElement($f_names);
                $sname = Random::getArrayElement($f_second_names);
            }

            $login = Random::popArrayElement($nicknames);

            $user = new Entity\User();
            $user->setSource(Entity\User::SOURCE_INTERNAL);
            $user->setName(sprintf("%s %s", $name, $sname));
            $user->setEmail(sprintf("<EMAIL>", $login));
            $user->setEmailConfirmed(true);
            $user->setLogin($login);
            $user->setPassword('password');

            $users[] = $user;
        }

        return $users;
    }
}<commit_msg>added avatar loading in generator<commit_after><?php

namespace mh\BTBundle\Command;

use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use mh\Common\Random;
use mh\BTBundle\Entity as Entity;

class UserGeneratorCommand extends DoctrineCommand
{
	const DATA_DIR = '/Data/';

	protected function configure()
    {
        $this
            ->setName('mh:gen:user')
            ->setDescription('User generator')
            ->addArgument('count', InputArgument::REQUIRED, 'What count of user you want to generate?')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
		$users = $this->generate($input->getArgument('count'));
		$em = $this->getEntityManager(null);

		foreach ($users as $user) {
			$output->writeln($user->getLogin());
			$em->persist($user);
		}

		$em->flush();
	}

	private function generate($count)
    {
        $users = array();
		
		$cacheDir = $this->getApplication()->getKernel()->getCacheDir();
		
        $m_names = file(__DIR__.self::DATA_DIR."m_names.txt", FILE_IGNORE_NEW_LINES);
        $m_second_names = file(__DIR__.self::DATA_DIR."m_second_names.txt", FILE_IGNORE_NEW_LINES);

        $f_names = file(__DIR__.self::DATA_DIR."f_names.txt");
        $f_second_names = file(__DIR__.self::DATA_DIR."f_second_names.txt", FILE_IGNORE_NEW_LINES);

        $nicknames = file(__DIR__.self::DATA_DIR."nicknames.txt", FILE_IGNORE_NEW_LINES);
		
		$avatarsDir = __DIR__.self::DATA_DIR."avatars/";
		if ($handle = opendir($avatarsDir)) {
			while (false !== ($entry = readdir($handle))) {
				if (!is_dir($entry)) {
					$avatars[] = $avatarsDir . $entry;
				}
			}
			closedir($handle);
		}
		var_dump($avatars);
        
		for ($i = 0; $i < $count; $i++) {

            if (mt_rand(0, 1) == 0) {
                $name = Random::getArrayElement($m_names);
                $sname = Random::getArrayElement($m_second_names);
            } else {
                $name = Random::getArrayElement($f_names);
                $sname = Random::getArrayElement($f_second_names);
            }

            $login = Random::popArrayElement($nicknames);

            $user = new Entity\User();
            $user->setSource(Entity\User::SOURCE_INTERNAL);
            $user->setName(sprintf("%s %s", $name, $sname));
            $user->setEmail(sprintf("<EMAIL>", $login));
            $user->setEmailConfirmed(true);
            $user->setLogin($login);
            $user->setPassword('password');
			
			if ($avatars) {
				$avatarSrc = Random::getArrayElement($avatars);
				$pathParts = pathinfo($avatarSrc);
				$local = sprintf("%s/%s.%s", $cacheDir, Random::generate(), $pathParts['extension']);
				file_put_contents($local, file_get_contents($avatarSrc));
				
				$avatar = new UploadedFile($local, $pathParts['basename'], null, null, null, true);
				$user->setFoto(new Entity\UserFoto($avatar));
			}
			
            $users[] = $user;
        }

        return $users;
    }
}
{'fraction_non_alphanumeric': 0.15387361656551232, 'fraction_numerical': 0.0014280614066404856, 'mean_word_length': 3.0660377358490565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 41, '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': '971787', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1727, 'n_words': 281}