Exemplo n.º 1
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $websiteArray = array();
     $listWebSiteAvailable = WebsiteGetData::getListWebsiteAvailable();
     foreach ($listWebSiteAvailable as $website) {
         $websiteArray[$website] = $website;
     }
     $builder->add('url')->add('nom', ChoiceType::class, array('choices' => $websiteArray))->add('logo');
 }
Exemplo n.º 2
0
 function transformData($tableauData)
 {
     // $tableauData
     // wind  -> 17.5 | 12 | 10 | 14.5 | 15
     // orientation  -> 198 | 172 | 170 | 180 | 188
     // heure -> 13   | 19 | 22 | 01   | 04
     // date  -> 04   | 04 | 04 | 05   | 05
     $tableauWindData = array();
     $currentDate = '';
     $firstElem = true;
     $currenteLine = array();
     //$indexCol=0;
     foreach ($tableauData['date'] as $key => $date) {
         if ($currentDate != $date) {
             if ($firstElem) {
                 $firstElem = false;
             } else {
                 $tableauWindData[WindguruGetData::getCompleteDate($currentDate)] = $currenteLine;
             }
             $currenteLine = array();
         }
         $dataPrev = array();
         $dataPrev["wind"] = $tableauData['wind'][$key];
         $dataPrev["heure"] = $tableauData['heure'][$key];
         if (isset($tableauData['orientation'][$key])) {
             $dataPrev["orientation"] = WebsiteGetData::transformeOrientationDegToNom($tableauData['orientation'][$key]);
         } else {
             $dataPrev["orientation"] = '?';
         }
         $currenteLine[$tableauData['heure'][$key]] = $dataPrev;
         $currentDate = $date;
         //$indexCol++;
     }
     $tableauWindData[WindguruGetData::getCompleteDate($currentDate)] = $currenteLine;
     $tableauWindData['update'] = array(array(WindguruGetData::transformeUpdate($tableauData['update'][0])));
     return $tableauWindData;
 }
Exemplo n.º 3
0
 public static function getDataFromDataWindPrev(DataWindPrev $dataWindPrev, OutputInterface $output, EntityManager $em)
 {
     $output->write('<info>Spot ' . $dataWindPrev->getSpot()->getNom() . ' - </info>');
     // get each web site
     $output->writeln('<info>site ' . $dataWindPrev->getWebSite()->getNom() . ' -> ' . $dataWindPrev->getUrl() . '</info>');
     // Delete old value
     GetDataCommand::deleteOldPrevisionDate($dataWindPrev, $output, $em);
     // save data
     $websiteGetData = WebsiteGetData::getWebSiteObject($dataWindPrev);
     // return WindguruGetData or MeteoFranceGetData... depend of $dataWindPrev
     $data = $websiteGetData->getDataFromURL($dataWindPrev);
     // array($result,$chrono)
     $output->write('<info>    get data: ' . $data[1] . '</info>');
     $analyse = $websiteGetData->analyseDataFromPage($data[0], $dataWindPrev->getUrl());
     // array($result,$chrono)
     $output->write('<info>    analyse: ' . $analyse[1] . '</info>');
     $transformData = $websiteGetData->transformDataFromTab($analyse[0]);
     // array($result,$chrono)
     $output->write('<info>    transforme data: ' . $transformData[1] . '</info>');
     $saveData = $websiteGetData->saveFromTransformData($transformData[0], $dataWindPrev, $em);
     // array(array $prevDate,$chrono)
     $output->writeln('<info>    save data: ' . $saveData[1] . '</info>');
     $output->writeln('<info>******************************</info>');
 }
Exemplo n.º 4
0
 /**
  * Set orientationDeg
  *
  * @param string $orientationDeg
  *
  * @return WindOrientation
  */
 public function setOrientationDeg($orientationDeg)
 {
     $this->orientationDeg = $orientationDeg;
     $this->orientation = WebsiteGetData::transformeOrientationDegToNom($orientationDeg);
     return $this;
 }
Exemplo n.º 5
0
 private static function getMaxWindClean($htmlValue)
 {
     if (preg_match('#[[:alpha:]]*Raf.(?<windMax>[0-9]+)#', $htmlValue, $value) > 0) {
         $windMax = $value['windMax'];
         return WebsiteGetData::transformeKmhByNoeud($windMax);
     } else {
         return "?";
     }
 }
 /**
  * @Template()
  *
  * http://localhost/Wind/web/app_dev.php/fo/ajax/spot/ask/create/step3/2/1
  *
  * Etape 3: ajout des website
  */
 public function step3Action($id = null, $idContact = null, Request $request)
 {
     $em = $this->container->get('doctrine.orm.entity_manager');
     if (isset($id) && $id != -1) {
         $spot = $em->find('LaPoizWindBundle:Spot', $id);
         if (!$spot) {
             return $this->container->get('templating')->renderResponse('LaPoizWindBundle:FrontOffice:errorPage.html.twig', array('errMessage' => "No spot find !"));
         }
         $dataWindPrev = new DataWindPrev();
         $dataWindPrev->setSpot($spot);
         $form = $this->createForm('dataWindPrevForm', $dataWindPrev)->add('Ajoute et test le site', 'submit');
         if ($request->request->get("spot") == null) {
             if ('POST' == $request->getMethod()) {
                 $form->handleRequest($request);
                 if ($form->isValid()) {
                     // form submit
                     $dataWindPrev = $form->getData();
                     // Récupération du webSite grace à l'url
                     $website = WebsiteManage::getWebSiteEntityFromURL($dataWindPrev->getUrl(), $em);
                     if ($website != null) {
                         $dataWindPrevInDB = $em->getRepository('LaPoizWindBundle:DataWindPrev')->getWithWebsiteAndSpot($website, $spot);
                         if ($dataWindPrevInDB === null) {
                             $dataWindPrev->setWebsite($website);
                             // test si l'url est OK
                             $webSite = WebsiteGetData::getWebSiteObject($dataWindPrev);
                             if ($webSite->isDataWindPrevOK($dataWindPrev)) {
                                 // Il est possible de parser le site de cet URL
                                 if ($dataWindPrev->getWebsite()->getNom() == WebsiteGetData::windguruName) {
                                     $dataWindPrevWindGuruPro = clone $dataWindPrev;
                                     $dataWindPrevWindGuruPro->getWebsite()->removeDataWindPrev($dataWindPrevWindGuruPro);
                                     $windGuruProWebsite = $em->getRepository('LaPoizWindBundle:WebSite')->findByNom(WebsiteGetData::windguruProName)[0];
                                     $dataWindPrevWindGuruPro->setWebsite($windGuruProWebsite);
                                     $this->saveDataWindPrev($spot, $dataWindPrevWindGuruPro, $em);
                                 }
                                 $this->saveDataWindPrev($spot, $dataWindPrev, $em);
                                 // clean the form and display it
                                 $dataWindPrev = new DataWindPrev();
                                 $dataWindPrev->setSpot($spot);
                                 $form = $this->createForm('dataWindPrevForm', $dataWindPrev)->add('Ajoute et test le site', 'submit');
                                 return $this->render('LaPoizWindBundle:FrontOffice:AskNewSpot/blockAddSite.html.twig', array('form' => $form->createView(), 'spot' => $spot, 'idContact' => $idContact));
                             } else {
                                 // URL n'est pas bonne
                                 return new JsonResponse(array('message' => $website->getNom() . ' est déjà spécifié pour ce spot'), 419);
                             }
                         } else {
                             // URL n'est pas bonne
                             return new JsonResponse(array('message' => 'Impossible de parser l URL'), 419);
                         }
                     } else {
                         // URL n'est pas bonne
                         return new JsonResponse(array('message' => 'Cette URL ne correspond à aucun site parser par LaPoizWind.'), 419);
                     }
                 }
                 /*else {
                       return new Response($request);
                   }*/
             }
         }
         return $this->render('LaPoizWindBundle:FrontOffice:AskNewSpot/step3.html.twig', array('spot' => $spot, 'form' => $form->createView(), 'idContact' => $idContact));
     } else {
         return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice:errorPage.html.twig', array('errMessage' => "Miss id of spot... !"));
     }
 }
 public function testSaveAction($id = null)
 {
     try {
         $message = '';
         $em = $this->container->get('doctrine.orm.entity_manager');
         $step = 4;
         if (isset($id)) {
             $dataWindPrev = $em->find('LaPoizWindBundle:DataWindPrev', $id);
             $websiteGetData = WebSiteGetData::getWebSiteObject($dataWindPrev);
             // return WindguruGetData or MeteoFranceGetData... depend of $dataWindPrev
             $data = $websiteGetData->getDataFromURL($dataWindPrev);
             // array($result,$chrono)
             $analyse = $websiteGetData->analyseDataFromPage($data[0], $dataWindPrev->getUrl());
             // array($result,$chrono)
             $transformData = $websiteGetData->transformDataFromTab($analyse[0]);
             // array($result,$chrono)
             $saveData = $websiteGetData->saveFromTransformData($transformData[0], $dataWindPrev, $em);
             // array(array $prevDate,$chrono)
             return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice/Spot/Ajax:testdataWindPrev.html.twig', array('chrono' => $saveData[1], 'info' => $saveData[0], 'typeDisplay' => WebsiteGetData::typeDisplay($step), 'step' => $step, 'dataWindPrev' => $dataWindPrev));
         } else {
             $result = "No find DataWindPrev.id=" . $id;
         }
     } catch (Exception $e) {
         $result = toString($e);
     } catch (\ErrorException $ee) {
         $result = $ee->getMessage();
     }
     return $this->container->get('templating')->renderResponse('LaPoizWindBundle:BackOffice/Spot/Ajax:testdataWindPrev.html.twig', array('chrono' => 0, 'step' => 10, 'info' => $result, 'typeDisplay' => WebsiteGetData::typeDisplay(-1), 'dataWindPrev' => $dataWindPrev));
 }
Exemplo n.º 8
0
 static function getPrevisionValue(&$arrayEveryDay, PrevisionDate $previsionDate, $webSiteName)
 {
     if (!array_key_exists($previsionDate->getDatePrev()->format('Y-m-d'), $arrayEveryDay)) {
         $arrayEveryDay[$previsionDate->getDatePrev()->format('Y-m-d')] = AllPrevGetData::createArrayEveryHoure();
         // tableau de toutes les heures
     }
     $listPrevision = $previsionDate->getListPrevision();
     $prevHour = 0;
     $prevOrient = 0;
     $prevWind = 0;
     foreach ($listPrevision as $prevision) {
         $wind = $prevision->getWind();
         $orientation = WebsiteGetData::transformeOrientationDeg($prevision->getOrientation());
         $hour = intval($prevision->getTime()->format('H'));
         $arrayEveryDay[$previsionDate->getDatePrev()->format('Y-m-d')][$hour]['wind'][$webSiteName] = $wind;
         $arrayEveryDay[$previsionDate->getDatePrev()->format('Y-m-d')][$hour]['orient'][$webSiteName] = $orientation;
         AllPrevGetData::completeArrayPrevision($arrayEveryDay[$previsionDate->getDatePrev()->format('Y-m-d')], $webSiteName, $wind, $orientation, $hour, $prevWind, $prevOrient, $prevHour);
         $prevHour = $hour;
         $prevOrient = $orientation;
         $prevWind = $wind;
     }
 }