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(); }