<commit_before><?php

namespace AppBundle\Repository;


use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;

use AppBundle\Entity\Racer;
use AppBundle\Entity\Timing;
use AppBundle\Entity\Team;


class TimingRepository extends EntityRepository
{

    /**
     * description
     *
     * @param void
     * @return void
     *
     * used: src/AppBundle/Controller/TimingController.php x 2
     */
    public function findLatests($id)
    {
        $qb = $this->createQueryBuilder('ti');
        $qb
            ->addSelect('r')
            ->addSelect('te')
            ->leftJoin('ti.idRacer', 'r')
            ->leftJoin('r.idTeam', 'te')
            ->where('ti.id = :id')
            ->setParameter('id', $id)
            ;

        return $qb->getQuery()->getSingleResult();
    }

    /**
     * used: src/AppBundle/Command/RacerTimingConsolidateCommand.php
     */
    public function getStats(Racer $racer)
    {
        $qb = $this->createQueryBuilder('ti');
        $qb
            ->select($qb->expr()->min('ti.timing'))
            ->addSelect($qb->expr()->max('ti.timing'))
            //->addSelect($qb->expr()->avg('ti.timing'))
            ->addSelect('AVG(TIME_TO_SEC(ti.timing))')
            //->addSelect('AVG(UNIX_TIMESTAMP(ti.timing))')
            ->where('ti.idRacer = :idRacer')
            ->setParameter('idRacer', $racer)
            ;

        return $qb->getQuery()->getSingleResult();
    }

    //public function getLatests() {
    //    $qb = $this->createQueryBuilder('ti');
    //    $qb
    //        //->orderBy('ti.id', 'DESC')
    //        ->orderBy('ti.createdAt', 'DESC')
    //        ;
    //
    //    $qb->getQuery()->getResult();
    //}

    /**
     * description
     *
     * @param void
     * @return void
     *<commit_msg>* fix bad calculation of average time, was using not-manual ones<commit_after><?php

namespace AppBundle\Repository;


use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;

use AppBundle\Entity\Racer;
use AppBundle\Entity\Timing;
use AppBundle\Entity\Team;


class TimingRepository extends EntityRepository
{

    /**
     * description
     *
     * @param void
     * @return void
     *
     * used: src/AppBundle/Controller/TimingController.php x 2
     */
    public function findLatests($id)
    {
        $qb = $this->createQueryBuilder('ti');
        $qb
            ->addSelect('r')
            ->addSelect('te')
            ->leftJoin('ti.idRacer', 'r')
            ->leftJoin('r.idTeam', 'te')
            ->where('ti.id = :id')
            ->setParameter('id', $id)
            ;

        return $qb->getQuery()->getSingleResult();
    }

    /**
     * used: src/AppBundle/Command/RacerTimingConsolidateCommand.php
     */
    public function getStats(Racer $racer)
    {
        $stats = array();
        $qb = $this->createQueryBuilder('ti');
        $qb
            ->select($qb->expr()->min('ti.timing'))
            //->addSelect($qb->expr()->avg('ti.timing'))
            //->addSelect('AVG(UNIX_TIMESTAMP(ti.timing))')
            ->where('ti.idRacer = :idRacer')
            ->setParameter('idRacer', $racer)
            ;

        $r = $qb->getQuery()->getSingleResult();
	$stats[1] = $r[1];

        $qb = $this->createQueryBuilder('ti');
        $qb
            ->select($qb->expr()->max('ti.timing'))
            //->addSelect($qb->expr()->avg('ti.timing'))
            //->addSelect('AVG(UNIX_TIMESTAMP(ti.timing))')
            ->where('ti.idRacer = :idRacer')
            ->setParameter('idRacer', $racer)
            ;

        $r = $qb->getQuery()->getSingleResult();
	$stats[2] = $r[1];

        $qb = $this->createQueryBuilder('ti');
        $qb
            ->select('AVG(TIME_TO_SEC(TIME(ti.timing)))')
            //->addSelect('AVG(UNIX_TIMESTAMP(ti.timing))')
            ->where('ti.idRacer = :idRacer')
            ->setParameter('idRacer', $racer)
            ->andWhere($qb->expr()->in('ti.type', array(Timing::MANUAL)))
            ;

        $r = $qb->getQuery()->getSingleResult();
	$stats[3] = $r[1];
	return $stats;
    }

    //public function getLatests() {
    //    $qb = $this->createQueryBuilder('ti');
    //    $qb
    //        //->orderBy('ti.id', 'DESC')
    //        ->orderBy('ti.createdAt', 'DESC')
    //        ;
    //
    //    $qb->getQuery()->getResult();
    //}

    /**
     * description
     *
     * @param void
     * @return void
     *
{'fraction_non_alphanumeric': 0.1873869801084991, 'fraction_numerical': 0.0018083182640144665, 'mean_word_length': 1.9304635761589404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '7240411', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1451, 'n_words': 203}