<commit_before><?php

class DRRecolteAppellationLieu extends BaseDRRecolteAppellationLieu {

    protected $_total_acheteurs_by_cvi = array();

    public function getConfig() {
        return sfCouchdbManager::getClient('Configuration')->getConfiguration()->get($this->getHash());
    }

    public function getCodeDouane($vtsgn = '') {
      if ($this->getParent()->getKey() == 'appellation_VINTABLE') {
	if ($this->getParent()->getParent()->filter('appellation_')->count() > 1) {
	  $vtsgn = 'AOC';
	}
      }
      return $this->getConfig()->getDouane()->getFullAppCode($vtsgn);
    }

    public function getAppellation() {
      return $this->getParent()->getAppellation();
    }

    public function getLibelleWithAppellation() {
      if ($this->getLibelle())
	return $this->getParent()->getLibelle().' - '.$this->getLibelle();
      return $this->getParent()->getLibelle();
    }

    public function getLibelle() {
        return ConfigurationClient::getConfiguration()->get($this->getHash())->getLibelle();
    }

    public function getVolumeAcheteur($cvi, $type) {
        $sum = 0;
        foreach ($this->getAcheteursFromCepage($type) as $a) {
            if ($a->cvi == $cvi)
                $sum += $a->quantite_vendue;
        }
        return $sum;
    }

    public function getTotalVolume() {
      $r = $this->_get('total_volume');
      if ($r)
	return $r;
      return $this->getSumCepageFields('total_volume');
      
    }
    public function getTotalSuperficie() {
      $r =  $this->_get('total_superficie');
      if ($r)
	return $r;
      return $this->getSumCepageFields('total_superficie');
    }

    public function getTotalVolumeRevendique() {
      $r =  $this->_get('total_superficie');
      if ($r)
	return $r;
      return $this->getSumCepageFields('volume_revendique');
    }

    public function getTotalDPLC() {
      $r = $this->_get('dplc');
      if ($r)
	return $r;
      return $this->getSumCepageFields('dplc');
    }

    public function getTotalCaveParticuliere() {
      $sum = 0;
      foreach ($this->filter('^cepage') as $key => $cepage) {
	$sum += $cepage->getTotalCaveParticuliere();
      }
      return $sum;
    }
    
    private function getSumCepageFields($field) {
      $sum = 0;
      foreach ($this->filter('^cepage') as $key => $cepage) {
	$sum += $cepage->get($field);
      }
      return $sum;
    }


    private function getAcheteursFromCepage($type = 'negoces|cooperatives') {
        $acheteurs = array();
        foreach ($this->filter('^cepage') as $key => $cepage) {
            foreach ($cepage->detail as $key => $d) {
                foreach ($d->filter($type) as $key => $t) {
                    foreach ($t as $key => $a) {
                        array_push($acheteurs, $a);
                    }
                }
            }
        }
        return $acheteurs;
    }

    public function getTotalAcheteursByCvi($field) {
        if (!isset($this->_total_acheteurs_by_cvi[$field])) {
            $this->_total_acheteurs_by_cvi[$field] = array();
            foreach ($this->filter('^cepage') as $object) {
                $acheteurs = $object->getTotalAcheteursByCvi($field);
                foreach ($acheteurs as $cvi => $quantite_vendue) {
                    if (!isset($this->_total_acheteurs_by_cvi[$field][$cvi])) {
                        $this->_total_acheteurs_by_cvi[$field][$cvi] = 0;
                    }
                    $this->_total_acheteurs_by_cvi[$field][$cvi] += $quantite_vendue;
                }
            }
        }<commit_msg>Les rebeches ne comptent pas dans les totaux<commit_after><?php

class DRRecolteAppellationLieu extends BaseDRRecolteAppellationLieu {

    protected $_total_acheteurs_by_cvi = array();

    public function getConfig() {
        return sfCouchdbManager::getClient('Configuration')->getConfiguration()->get($this->getHash());
    }

    public function getCodeDouane($vtsgn = '') {
      if ($this->getParent()->getKey() == 'appellation_VINTABLE') {
	if ($this->getParent()->getParent()->filter('appellation_')->count() > 1) {
	  $vtsgn = 'AOC';
	}
      }
      return $this->getConfig()->getDouane()->getFullAppCode($vtsgn);
    }

    public function getAppellation() {
      return $this->getParent()->getAppellation();
    }

    public function getLibelleWithAppellation() {
      if ($this->getLibelle())
	return $this->getParent()->getLibelle().' - '.$this->getLibelle();
      return $this->getParent()->getLibelle();
    }

    public function getLibelle() {
        return ConfigurationClient::getConfiguration()->get($this->getHash())->getLibelle();
    }

    public function getVolumeAcheteur($cvi, $type) {
        $sum = 0;
        foreach ($this->getAcheteursFromCepage($type) as $a) {
            if ($a->cvi == $cvi)
                $sum += $a->quantite_vendue;
        }
        return $sum;
    }

    public function getTotalVolume() {
      $r = $this->_get('total_volume');
      if ($r)
	return $r;
      return $this->getSumCepageFields('total_volume');
      
    }
    public function getTotalSuperficie() {
      $r =  $this->_get('total_superficie');
      if ($r)
	return $r;
      return $this->getSumCepageFields('total_superficie');
    }

    public function getTotalVolumeRevendique() {
      $r =  $this->_get('total_superficie');
      if ($r)
	return $r;
      return $this->getSumCepageFields('volume_revendique');
    }

    public function getTotalDPLC() {
      $r = $this->_get('dplc');
      if ($r)
	return $r;
      return $this->getSumCepageFields('dplc');
    }

    public function getTotalCaveParticuliere() {
      $sum = 0;
      foreach ($this->filter('^cepage') as $key => $cepage) {
	$sum += $cepage->getTotalCaveParticuliere();
      }
      return $sum;
    }
    
    private function getSumCepageFields($field) {
      $sum = 0;
      foreach ($this->filter('^cepage') as $key => $cepage) {
	if ($key != 'cepage_RB')
	  $sum += $cepage->get($field);
      }
      return $sum;
    }


    private function getAcheteursFromCepage($type = 'negoces|cooperatives') {
        $acheteurs = array();
        foreach ($this->filter('^cepage') as $key => $cepage) {
            foreach ($cepage->detail as $key => $d) {
                foreach ($d->filter($type) as $key => $t) {
                    foreach ($t as $key => $a) {
                        array_push($acheteurs, $a);
                    }
                }
            }
        }
        return $acheteurs;
    }

    public function getTotalAcheteursByCvi($field) {
        if (!isset($this->_total_acheteurs_by_cvi[$field])) {
            $this->_total_acheteurs_by_cvi[$field] = array();
            foreach ($this->filter('^cepage') as $key => $object) {
	      if ($key != 'cepage_RB') {
                $acheteurs = $object->getTotalAcheteursByCvi($field);
                foreach ($acheteurs as $cvi => $quantite_vendue) {
		  if (!isset($this->_total_acheteurs_by_cvi[$field][$cvi])) {
		    $this->_total_acheteurs_by_cvi[$field][$cvi] = 0;
		  }
		  $this->_total_acheteurs_by_cvi[$field][$cvi] += $quantite_vendue;
                }
	      }
            }
        }
{'fraction_non_alphanumeric': 0.16152984029139816, 'fraction_numerical': 0.0014009526478005044, 'mean_word_length': 2.4638524987869967, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 116, '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': '133100', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2302, 'n_words': 392}