<commit_before><?php

namespace Monmiel\MonmielApiBundle\Services\TransformersService;

use JMS\DiExtraBundle\Annotation as DI;
use Monmiel\MonmielApiModelBundle\Model\Quarter;
use Monmiel\MonmielApiBundle\Services\TransformersService\TransformersInterface;

/**
 * @DI\Service("monmiel.transformers.service")
 */
class TransformersV1 implements TransformersInterface
{

    /**
     * Injection of the RiakDao
     * @DI\Inject("monmiel.dao.riak")
     * @var \Monmiel\MonmielApiBundle\Dao\RiakDao
     */
    public $riakDao;


    /**
     * the consommation in 2050
     * @var \Monmiel\MonmielApiModelBundle\Model\Mesure
     */
    protected  $consoInput;

    /**
     * the actual consommation
     * @var \Monmiel\MonmielApiModelBundle\Model\Mesure
     */
    protected  $consoActual;


    /**
     * @param $day integer
     * @return \Monmiel\MonmielApiModelBundle\Model\Day $day
     */
    public function get($day)
    {
        $consoDay = $this->riakDao->getDayConso($day);
        return $this->getTotalUpdated($consoDay);
    }
    /**
     * update the conso total for the Quarters of the Day in parameter with the actual conso and the input Coson
     * @param $day \Monmiel\MonmielApiModelBundle\Model\Day
     * @param $actualConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @param $inputConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    public function updateConsoTotalForDayWithActualConsoAndInputConso($day, $actualConso, $inputConso){
        $this->setConsoActual($actualConso);
        $this->setConsoInput($inputConso);
        return $this->getTotalUpdated($day);
    }


    /**
     * get the Day with the Quarters updated by Day Id,actual conso and the input Conso
     * @param $dayId integer
     * @param $actualConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @param $inputConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    public function getDayUpdatedByDayIdActualConsoAndInputConso($dayId, $actualConso, $inputConso){
        $this->setConsoActual($actualConso);
        $this->setConsoInput($inputConso);
        $dayTemp = $this->riakDao->getDayConso($dayId);
        return $this->getTotalUpdated($dayTemp);
    }

    /**
     * update sum of the list of Quarter of Day  by the current consommation and the new consommation
     * @param $consoDay \Monmiel\MonmielApiModelBundle\Model\Day
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    private function getTotalUpdated($consoDay)
    {
        $retour = new \Monmiel\MonmielApiModelBundle\Model\Day($consoDay->getDateTime());
        if(isset($consoDay)){
            $cActuel = $this->getConsoActual();
            $cInput = $this->getConsoInput();
            if(\Monmiel\MonmielApiModelBundle\Model\Mesure::isEqualsMesure($cActuel,$cInput)){
                $array =  $this->transformeTotalToConsoTher($consoDay->getQuarters(),$cActuel,$cInput);
                $retour->setQuarters($array);
            }
            else{
                $consoInputConverted = \Monmiel\MonmielApiModelBundle\Model\Mesure::convertMesureByOtherUnitOfMesure($cInput,$cActuel->getUnitOfMesure());
                $array =  $this->transformeTotalToConsoTher($consoDay->getQuarters(),$this->getConsoActual(), $consoInputConverted);
                $retour->setQuarters($array);
                echo "------ different mesure \n -------";
            }
        }
        return $retour;
    }

    /**
     * Transformer le total de la consommation donnee au total de la consommation theorique
     * @param $listQuarter array<\Monmiel\MonmielApiModelBundle\Model\Quarter>
     * @param $consoAct \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @param $consoUser \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @return array<\Monmiel\MonmielApiModelBundle\Model\Quarter>
     */

     private function transformeTotalToConsoTher($listQuarter,$consoAct,$consoUser)
     {
        // Definir une liste temporaire
        $tmp = array();
        // Parcourir la liste et transformer chaque conso en conso theorique
        foreach ($listQuarter as $value) {
            // Appliquer la formule de calcul

            $tmpVal= $this->transformeTotalCalcul($value->getConsoTotal(),$consoAct->getValue(),$consoUser->getValue());

            // Remplacer la valeur par la nouvelle valeur

            $value->setConsoTotal($tmpVal);

            $tmpValeur = $value;
            array_push($tmp,$tmpValeur);

        }

        return $tmp;
    }


    /**
     * La methode utilisee pour calculer la transformation totale theorique
     * @param $totalActQuart float
     * @param $consoAct float
     * @param $consoUser float
     * @return float
     */
    private function transformeTotalCalcul($totalActQuart,$consoAct,$consoUser)
    {
        $ret = ($totalActQuart* $consoUser)/$consoAct;
        return $ret;
    }
<commit_msg>comment in english<commit_after><?php

namespace Monmiel\MonmielApiBundle\Services\TransformersService;

use JMS\DiExtraBundle\Annotation as DI;
use Monmiel\MonmielApiModelBundle\Model\Quarter;
use Monmiel\MonmielApiBundle\Services\TransformersService\TransformersInterface;

/**
 * @DI\Service("monmiel.transformers.service")
 */
class TransformersV1 implements TransformersInterface
{

    /**
     * Injection of the RiakDao
     * @DI\Inject("monmiel.dao.riak")
     * @var \Monmiel\MonmielApiBundle\Dao\RiakDao
     */
    public $riakDao;


    /**
     * the consommation in 2050
     * @var \Monmiel\MonmielApiModelBundle\Model\Mesure
     */
    protected  $consoInput;

    /**
     * the actual consommation
     * @var \Monmiel\MonmielApiModelBundle\Model\Mesure
     */
    protected  $consoActual;


    /**
     * @param $day integer
     * @return \Monmiel\MonmielApiModelBundle\Model\Day $day
     */
    public function get($day)
    {
        $consoDay = $this->riakDao->getDayConso($day);
        return $this->getTotalUpdated($consoDay);
    }
    /**
     * update the conso total for the Quarters of the Day in parameter with the actual conso and the input Coson
     * @param $day \Monmiel\MonmielApiModelBundle\Model\Day
     * @param $actualConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @param $inputConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    public function updateConsoTotalForDayWithActualConsoAndInputConso($day, $actualConso, $inputConso){
        $this->setConsoActual($actualConso);
        $this->setConsoInput($inputConso);
        return $this->getTotalUpdated($day);
    }


    /**
     * get the Day with the Quarters updated by Day Id,actual conso and the input Conso
     * @param $dayId integer
     * @param $actualConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @param $inputConso \Monmiel\MonmielApiModelBundle\Model\Mesure
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    public function getDayUpdatedByDayIdActualConsoAndInputConso($dayId, $actualConso, $inputConso){
        $this->setConsoActual($actualConso);
        $this->setConsoInput($inputConso);
        $dayTemp = $this->riakDao->getDayConso($dayId);
        return $this->getTotalUpdated($dayTemp);
    }

    /**
     * update sum of the list of Quarter of Day  by the current consommation and the new consommation
     * @param $consoDay \Monmiel\MonmielApiModelBundle\Model\Day
     * @return \Monmiel\MonmielApiModelBundle\Model\Day
     */
    private function getTotalUpdated($consoDay)
    {
        $retour = new \Monmiel\MonmielApiModelBundle\Model\Day($consoDay->getDateTime());
        if(isset($consoDay)){
            $cActuel = $this->getConsoActual();
            $cInput = $this->getConsoInput();
            if(\Monmiel\MonmielApiModelBundle\Model\Mesure::isEqualsMesure($cActuel,$cInput)){
                $array =  $this->transformeTotalToConsoTher($consoDay->getQuarters(),$cActuel,$cInput);
                $retour->setQuarters($array);
            }
            else{
                $consoInputConverted = \Monmiel\MonmielApiModelBundle\Model\Mesure::convertMesureByOtherUnitOfMesure($cInput,$cActuel->getUnitOfMesure());
                $array =  $this->transformeTotalToConsoTher($consoDay->getQuarters(),$this->getConsoActual(), $consoInputConverted);
                $retour->setQuarters($array);
                echo "------ different mesure \n -------";
            }
        }
        return $retour;
    }

    /**
     * Transformer the total of consumption given to total of consumption in theories
     * @param $listQuarter array<\Monmiel\MonmielApiModelBundle\Model\Quarter>
     * @param $consoAct \Monmiel\MonmielApiModelBundle\Model\Mesure       the actual consumption
     * @param $consoUser \Monmiel\MonmielApiModelBundle\Model\Mesure      the consumption typed by user
     * @return array<\Monmiel\MonmielApiModelBundle\Model\Quarter>        array of Quarter
     */
     private function transformeTotalToConsoTher($listQuarter,$consoAct,$consoUser)
     {
       // Define a temporal list
       $tmp = array();
       // Go through the list and transformer each consumption to theoretical consumption
       foreach ($listQuarter as $value) {
         // Call the method for the transformation calculate
         $tmpVal= $this->transformeTotalCalcul($value->getConsoTotal(),$consoAct->getValue(),$consoUser->getValue());
         //Replace the old value of consumption by a new one
         $value->setConsoTotal($tmpVal);
         $tmpValeur = $value;
         //Put the value modified in the array list tmp
         array_push($tmp,$tmpValeur);
       }
       // Return the list transformed
       return $tmp;
    }


    /**
     * This method used for the calculate of transformation, transformer actual
     * total consumption to theoretical total consumption
     * @param $totalActQuart float    the actual total consumption of this quarter
     * @param $consoAct float         the actual total consumption
     * @param $consoUser float        the total consumption typed by user
     * @return float                  value calculated
     */
    private function transformeTotalCalcul($totalActQuart,$consoAct,$consoUser)
    {
      // Calculate
      $ret = ($totalActQuart* $consoUser)/$consoAct;
      return $ret;
    }

{'fraction_non_alphanumeric': 0.11101491101491101, 'fraction_numerical': 0.000962000962000962, 'mean_word_length': 2.8762117822520508, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 61, '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': '1375929', 'n_tokens_mistral': 3288, 'n_tokens_neox': 3244, 'n_words': 608}