<commit_before><?php

namespace Intracto\SecretSantaBundle\Query;

use Doctrine\DBAL\Connection;

class PoolReportQueries
{
    private $dbal;

    /**
     * @param Connection $dbal
     */
    public function __construct(Connection $dbal)
    {
        $this->dbal = $dbal;
    }

    /**
     * @return array
     * @throws NoResultException
     */
    public function getFullPoolReport()
    {
        $pools = $this->dbal->fetchAll(
            'SELECT count(*) as poolCount
            FROM Pool'
        );
        $entries = $this->dbal->fetchAll(
            'SELECT count(*) as entryCount
            FROM Entry
            JOIN Pool on Pool.id = Entry.poolId'
        );
        $wishlists = $this->dbal->fetchAll(
            'SELECT count(*) as wishListCount
            FROM Entry
            JOIN Pool on Pool.id = Entry.poolId
            WHERE wishlist_updated = TRUE'
        );

        if ($pools[0]['poolCount'] != 0 || $entries[0]['entryCount']) {
            $entryAverage = number_format(implode($entries[0]) / implode($pools[0]), 2);
            $wishlistAverage = number_format((implode($wishlists[0]) / implode($entries[0])) * 100, 2);

            return [
                'pools' => $pools,
                'entries' => $entries,
                'wishlists' => $wishlists,
                'entry_average' => $entryAverage,
                'wishlist_average' => $wishlistAverage,
            ];
        } else {
            throw new NoResultException();
        }
    }

    /**
     * @param int $year
     * @return array
     */
    public function getPoolReport($year)
    {
        $firstDay = \DateTime::createFromFormat('Y-m-d', $year . '-01-01');
        $lastDay = \DateTime::createFromFormat('Y-m-d', $year + 1 . '-01-01');

        $pools = $this->dbal->fetchAll(
            'SELECT count(*) AS poolCount
            FROM Pool p
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        $entries = $this->dbal->fetchAll(
            'SELECT count(*) AS entryCount
            FROM Pool p
            JOIN Entry e ON p.id = e.poolId
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        $wishlists = $this->dbal->fetchAll(
            'SELECT count(*) as wishListCount
            FROM Pool p JOIN Entry e on p.id = e.poolId
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay AND e.wishlist_updated = TRUE',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        if ($pools[0]['poolCount'] != 0 || $entries[0]['entryCount']) {
            $entryAverage = number_format(implode($entries[0]) / implode($pools[0]), 2);
            $wishlistAverage = number_format((implode($wishlists[0]) / implode($entries[0])) * 100, 2);

            return [
                'pools' => $pools,
                'entries' => $entries,
                'wishlists' => $wishlists,
                'entry_average' => $entryAverage,
                'wishlist_average' => $wishlistAverage,
            ];
        } else {
            throw new NoResultException();
        }
    }

    /**
     * @return array
     */
    public function getFeaturedYears()
    {
        $yearsQuery = $this->dbal->fetchAll(
            'SELECT DISTINCT year(sentdate) as featured_year
            FROM Pool
            WHERE year(sentdate) IS NOT NULL
            ORDER BY year(sentdate) DESC'
        );

        $featuredYears = [];

        foreach ($yearsQuery as $f) {
            array_push($featuredYears, $f['featured_year']);
        }

        return [
            'featured_years' => $featuredYears,
        ];
    }
}<commit_msg>Rounded entryAverage<commit_after><?php

namespace Intracto\SecretSantaBundle\Query;

use Doctrine\DBAL\Connection;

class PoolReportQueries
{
    private $dbal;

    /**
     * @param Connection $dbal
     */
    public function __construct(Connection $dbal)
    {
        $this->dbal = $dbal;
    }

    /**
     * @return array
     * @throws NoResultException
     */
    public function getFullPoolReport()
    {
        $pools = $this->dbal->fetchAll(
            'SELECT count(*) as poolCount
            FROM Pool'
        );
        $entries = $this->dbal->fetchAll(
            'SELECT count(*) as entryCount
            FROM Entry
            JOIN Pool on Pool.id = Entry.poolId'
        );
        $wishlists = $this->dbal->fetchAll(
            'SELECT count(*) as wishListCount
            FROM Entry
            JOIN Pool on Pool.id = Entry.poolId
            WHERE wishlist_updated = TRUE'
        );

        if ($pools[0]['poolCount'] != 0 || $entries[0]['entryCount']) {
            $entryAverage = round(implode($entries[0]) / implode($pools[0]));
            $wishlistAverage = number_format((implode($wishlists[0]) / implode($entries[0])) * 100, 2);

            return [
                'pools' => $pools,
                'entries' => $entries,
                'wishlists' => $wishlists,
                'entry_average' => $entryAverage,
                'wishlist_average' => $wishlistAverage,
            ];
        } else {
            throw new NoResultException();
        }
    }

    /**
     * @param int $year
     * @return array
     */
    public function getPoolReport($year)
    {
        $firstDay = \DateTime::createFromFormat('Y-m-d', $year . '-01-01');
        $lastDay = \DateTime::createFromFormat('Y-m-d', $year + 1 . '-01-01');

        $pools = $this->dbal->fetchAll(
            'SELECT count(*) AS poolCount
            FROM Pool p
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        $entries = $this->dbal->fetchAll(
            'SELECT count(*) AS entryCount
            FROM Pool p
            JOIN Entry e ON p.id = e.poolId
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        $wishlists = $this->dbal->fetchAll(
            'SELECT count(*) as wishListCount
            FROM Pool p JOIN Entry e on p.id = e.poolId
            WHERE p.sentdate >= :firstDay AND p.sentdate < :lastDay AND e.wishlist_updated = TRUE',
            ['firstDay' => $firstDay->format('Y-m-d H:i:s'), 'lastDay' => $lastDay->format('Y-m-d H:i:s')]
        );

        if ($pools[0]['poolCount'] != 0 || $entries[0]['entryCount']) {
            $entryAverage = round(implode($entries[0]) / implode($pools[0]));
            $wishlistAverage = number_format((implode($wishlists[0]) / implode($entries[0])) * 100, 2);

            return [
                'pools' => $pools,
                'entries' => $entries,
                'wishlists' => $wishlists,
                'entry_average' => $entryAverage,
                'wishlist_average' => $wishlistAverage,
            ];
        } else {
            throw new NoResultException();
        }
    }

    /**
     * @return array
     */
    public function getFeaturedYears()
    {
        $yearsQuery = $this->dbal->fetchAll(
            'SELECT DISTINCT year(sentdate) as featured_year
            FROM Pool
            WHERE year(sentdate) IS NOT NULL
            ORDER BY year(sentdate) DESC'
        );

        $featuredYears = [];

        foreach ($yearsQuery as $f) {
            array_push($featuredYears, $f['featured_year']);
        }

        return [
            'featured_years' => $featuredYears,
        ];
    }
}
{'fraction_non_alphanumeric': 0.14876456279605685, 'fraction_numerical': 0.008193573166047881, 'mean_word_length': 1.7880085653104925, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 85, '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': '6034290', 'n_tokens_mistral': 2503, 'n_tokens_neox': 2384, 'n_words': 491}