Exemplo n.º 1
0
 static function calculateWindAllPrev(WebSite $allPrevWebSite, Spot $spot, EntityManager $em)
 {
     // Find dataWindPrev with allPrevWebsite and spot
     $dataWindPrevAllPrev = $em->getRepository('LaPoizWindBundle:DataWindPrev')->getWithWebsiteAndSpot($allPrevWebSite, $spot);
     // Delete all old data
     AllPrevGetData::deleteOldData($dataWindPrevAllPrev, $em);
     $arrayEveryDay = array();
     // Pour chaque site de prevision remplis le tableau avec ses prévisions (vent, orientation)
     foreach ($spot->getDataWindPrev() as $dataWindPrev) {
         if ($dataWindPrev->getWebsite()->getNom() !== WebsiteGetData::allPrevName) {
             foreach ($dataWindPrev->getListPrevisionDate() as $previsionDate) {
                 AllPrevGetData::getPrevisionValue($arrayEveryDay, $previsionDate, $dataWindPrev->getWebsite()->getNom());
             }
         }
     }
     // $arrayEveryDay['Y-m-d']['H']['wind/orient'][websiteName]
     //$toto = $arrayEveryDay;
     // Calcul la moyenne pour chaque heure (avec coef pour le spot)
     foreach ($arrayEveryDay as $keyDate => $arrayHours) {
         $previsionDate = new PrevisionDate();
         $previsionDate->setDataWindPrev($dataWindPrevAllPrev);
         $previsionDate->setDatePrev(new \DateTime($keyDate));
         $previsionDate->setCreated(new \DateTime("now"));
         $dataWindPrevAllPrev->addListPrevisionDate($previsionDate);
         foreach ($arrayHours as $keyH => $arrayData) {
             // $arrayData['wind/orient'][websiteName]
             $nbWebsite = count($arrayData['wind']);
             if ($nbWebsite > 0) {
                 $windTotal = 0;
                 foreach ($arrayData['wind'] as $keywebsiteName => $windValue) {
                     $windTotal += $windValue;
                 }
                 $orientTotal = 0;
                 foreach ($arrayData['orient'] as $keywebsiteName => $orientationValue) {
                     $orientTotal += $orientationValue;
                 }
                 $prevision = new Prevision();
                 $prevision->setOrientation($orientTotal / $nbWebsite);
                 // Ne marche pas autour de l'orientation NNE et NNO
                 $prevision->setWind($windTotal / $nbWebsite);
                 $hour = new \DateTime();
                 $hour->setTime($keyH, "00");
                 $prevision->setTime($hour);
                 $prevision->setPrevisionDate($previsionDate);
                 $em->persist($prevision);
             }
         }
         $em->persist($previsionDate);
         $em->persist($dataWindPrevAllPrev);
     }
     $em->flush();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     // récupere tous les spots
     $listSpot = $em->getRepository('LaPoizWindBundle:Spot')->findAll();
     $allPrevWebSite = $em->getRepository('LaPoizWindBundle:WebSite')->findWithName(WebsiteGetData::allPrevName);
     foreach ($listSpot as $spot) {
         $output->writeln('<info>*** Spot ' . $spot->getNom() . ' ***</info>');
         // Find dataWindPrev with allPrevWebsite and spot
         $dataWindPrevAllPrev = $em->getRepository('LaPoizWindBundle:DataWindPrev')->getWithWebsiteAndSpot($allPrevWebSite, $spot);
         // Delete all old data
         AllPrevGetData::deleteOldData($dataWindPrevAllPrev, $em);
         // Construit un tableau avec toutes les heures pour les 7 prochains jours
         // Pour chaque site de prevision remplis le tableau avec ses prévisions (vent, vents max, orientation)
         // Pour chaque site remplis les cases vide en fonction des éléments remplis
         // Calcul la moyenne pour chaque heure (avec coef pour le spot)
     }
     $em->flush();
 }