<commit_before><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 16/05/2016
 * Time: 16:56
 */

namespace VimoliaBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use VimoliaBundle\Entity\Discussion;

class ApiController extends Controller
{
	/**
     * @Route("/admin/api/waitingQuestions", name="waitingQuestions")
     */
    public function displaywaitingQuestionsAction()
    {
    	$em = $this->getDoctrine()->getManager();
        $adminDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "new", "active" => true));
        $expertDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => ["expertAssociated", "advancedInfosFilled"], "active" => true));
        $userDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "waitingAdvancedInfos", "active" => true));
        $practsDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "practAttributed", "active" => true));

        $discussions = [
        	"categories" => ["Administrateur", "Expert", "Utilisateur", "Praticien"],
        	"data" => [count($adminDiscussions), count($expertDiscussions), count($userDiscussions), count($practsDiscussions)]
        ];
        return new JsonResponse($discussions);
    }

    /**
     * @Route("/admin/api/usersCount", name="usersCount")
     */
    public function displayUsersCount() {
    	$memebres = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_MEMBER');
    	$experts = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_EXPERT');
    	$practionners = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_PRACTITIONER');
    	$admins = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_SUPER_ADMIN');

    	$discussions = [
        	"categories" => ["Membres", "Experts", "Praticiens", "Administrateurs"],
        	"data" => [count($memebres), count($experts), count($practionners), count($admins)]
        ];
        return new JsonResponse($discussions);
    }

    /**
     * @Route("/admin/api/practiciensPerDomain", name="practiciensPerDomain")
     */
    public function displayPracticiensPerDomain() {
      $em = $this->getDoctrine()->getManager();
      $domains = $em->getRepository('VimoliaBundle:PractDomains')
                    ->findAll();

      $domainsCount = [];
      foreach ($domains as $domain) {
        $practs = $this->getDoctrine()->getRepository("UserBundle:User")->findPracticiensByDomain($domain->getId());
        $domainsCount[] = ["name" =>$domain->getName(), "y" => count($practs)];
      }
      return new JsonResponse($domainsCount);
    }


    /**
     * @Route("/admin/api/departements", name="departements")
     */
    public function displayDepartementsDomain() {
        $em = $this->getDoctrine()->getManager();
        $practionners = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_PRACTITIONER');


        $zipCodes = [];
        foreach( $practionners as $pract ){
            $dep = substr( $pract->getZipcode() , 0, 2);
            $index = strval($dep);

            if(array_key_exists ($index,$zipCodes)){
                $val = $zipCodes[$index];
                $zipCodes[$index] = $val+1;
            }
            else{
                $zipCodes[$index] = 1;
            }
        }


        
        /*
        $domainsCount = [];
        foreach ($domains as $domain) {
            $practs = $this->getDoctrine()->getRepository("UserBundle:User")->findPracticiensByDomain($domain->getId());
            $domainsCount[] = ["name" =>$domain->getName(), "y" => count($practs)];
        }
        return new JsonResponse($domainsCount);
        */
    }
}<commit_msg>[DATAVIZ] : Nombre de personne par département (Practicien + membres)<commit_after><?php
/**
 * Created by PhpStorm.
 * User: <NAME>
 * Date: 16/05/2016
 * Time: 16:56
 */

namespace VimoliaBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use VimoliaBundle\Entity\Discussion;

class ApiController extends Controller
{
	/**
     * @Route("/admin/api/waitingQuestions", name="waitingQuestions")
     */
    public function displaywaitingQuestionsAction()
    {
    	$em = $this->getDoctrine()->getManager();
        $adminDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "new", "active" => true));
        $expertDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => ["expertAssociated", "advancedInfosFilled"], "active" => true));
        $userDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "waitingAdvancedInfos", "active" => true));
        $practsDiscussions = $em->getRepository('VimoliaBundle:Discussion')
                          ->findBy(array("status" => "practAttributed", "active" => true));

        $discussions = [
        	"categories" => ["Administrateur", "Expert", "Utilisateur", "Praticien"],
        	"data" => [count($adminDiscussions), count($expertDiscussions), count($userDiscussions), count($practsDiscussions)]
        ];
        return new JsonResponse($discussions);
    }

    /**
     * @Route("/admin/api/usersCount", name="usersCount")
     */
    public function displayUsersCount() {
    	$memebres = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_MEMBER');
    	$experts = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_EXPERT');
    	$practionners = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_PRACTITIONER');
    	$admins = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_SUPER_ADMIN');

    	$discussions = [
        	"categories" => ["Membres", "Experts", "Praticiens", "Administrateurs"],
        	"data" => [count($memebres), count($experts), count($practionners), count($admins)]
        ];
        return new JsonResponse($discussions);
    }

    /**
     * @Route("/admin/api/practiciensPerDomain", name="practiciensPerDomain")
     */
    public function displayPracticiensPerDomain() {
      $em = $this->getDoctrine()->getManager();
      $domains = $em->getRepository('VimoliaBundle:PractDomains')
                    ->findAll();

      $domainsCount = [];
      foreach ($domains as $domain) {
        $practs = $this->getDoctrine()->getRepository("UserBundle:User")->findPracticiensByDomain($domain->getId());
        $domainsCount[] = ["name" =>$domain->getName(), "y" => count($practs)];
      }
      return new JsonResponse($domainsCount);
    }


    /**
     * @Route("/admin/api/departementsPraticien", name="departements-pract")
     */
    public function displayDepartementsPractDomain() {
        $em = $this->getDoctrine()->getManager();
        $practionners = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_PRACTITIONER');


        $zipCodes = [];
        foreach( $practionners as $pract ){
            $dep = substr( $pract->getZipcode() , 0, 2);
            $index = strval($dep);
            if(array_key_exists ($index,$zipCodes)){
                $val = $zipCodes[$index];
                $zipCodes[$index] = $val+1;
            }
            else{
                $zipCodes[$index] = 1;
            }
        }
    }




    /**
     * @Route("/admin/api/departementsMembres", name="departements-membres")
     */
    public function displayDepartementsMembreDomain() {
        $em = $this->getDoctrine()->getManager();
        $practionners = $this->getDoctrine()->getRepository("UserBundle:User")->findByRole('ROLE_MEMBER');


        $zipCodes = [];
        foreach( $practionners as $pract ){
            $dep = substr( $pract->getZipcode() , 0, 2);
            $index = strval($dep);
            if(array_key_exists ($index,$zipCodes)){
                $val = $zipCodes[$index];
                $zipCodes[$index] = $val+1;
            }
            else{
                $zipCodes[$index] = 1;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.16842961757526445, 'fraction_numerical': 0.00418458677205626, 'mean_word_length': 2.9925754060324827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 120, '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': '4883936', 'n_tokens_mistral': 2656, 'n_tokens_neox': 2562, 'n_words': 360}