src/Controller/HomeController.php line 124

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use App\Entity\Rencontre;
  6. use App\Manager\CrawlManager;
  7. /**
  8.  * Description of HomeController
  9.  *
  10.  * @author jerome
  11.  */
  12. class HomeController extends AbstractController
  13. {
  14.     private $saison "2019/2020";
  15.     private $urlLigue1 "https://www.scibet.com/football/france/ligue-1/";
  16.     private $urlBundesliga "https://www.scibet.com/football/germany/bundesliga-1/";
  17.     private $urlSeriea "https://www.scibet.com/football/italy/serie-a/";
  18.     private $urlPrimera "https://www.scibet.com/football/spain/primera-division/";
  19.     private $urlPremier "https://www.scibet.com/football/england/premier-league/";
  20.     
  21.     /**
  22.      * @Route("/", name="home")
  23.      */
  24.     public function index()
  25.     {
  26.         
  27.         $rencontres $this->getDoctrine()
  28.         ->getRepository(Rencontre::class)
  29.         ->findBy(
  30.             ['idSaison' => 14,'idChampionnat' => [1,3,4,6,8]],
  31.             ['dateRencontre' => 'DESC']);
  32. //        1,2,3,4,5,6,7,8,9
  33. //        1,3,4,6,8
  34.         $matchs $this->selectionMatches($rencontres);
  35.         $resultat $this->martagale($matchs);
  36.         return $this->render('home.html.twig');
  37.     }
  38.     
  39.     public function selectionMatches($rencontres): array
  40.     {
  41.         if ($rencontres){
  42.             $matchs = [];
  43.             $timestampOld null;
  44.             $timestamp null;
  45.             foreach ($rencontres as $rencontre) {
  46.                 if($rencontre->getCoteDomicile() >= 2.0 && $rencontre->getCoteDomicile() < $rencontre->getCoteExterieur()){
  47.                     if(is_null($timestamp) && is_null($timestampOld)){
  48.                         $timestamp $rencontre->getDaterencontre()->getTimestamp();
  49.                         $timestampOld $rencontre->getDaterencontre()->getTimestamp();
  50.                         array_push ($matchs,$rencontre);
  51.                         
  52.                     } else {
  53.                         $timestamp $rencontre->getDaterencontre()->getTimestamp();
  54.                         $troisheures $timestampOld $timestamp;
  55.                         if($troisheures >= 10800){
  56.                             array_push ($matchs,$rencontre);
  57.                         }
  58.                         $timestampOld $timestamp;
  59.                     }
  60.                 }
  61.             }
  62.         }
  63.         return $matchs;
  64.     }
  65.     
  66.     public function martagale($matchs)
  67.     {
  68.         $gainTotal 0;
  69.         $mise 1;
  70.         $nbsansVictoireMax 0;
  71.         $nbsansVictoire 0;
  72.         $nbMiseMax 0;
  73.         $nbMise 0;
  74.         $flag true;
  75.         foreach ($matchs as $key=>$match){
  76. //            if ($key == 10){
  77. //                break;
  78. //            }else{
  79. //                dump($match->getDaterencontre());
  80. //            }
  81.             if($flag === true){
  82.                 $resultat str_split($match->getResultat(),1);
  83.                 //pari gagnant
  84. //                if($resultat[0] > $resultat[4]){
  85. //                    $gainTotal += $match->getCoteDomicile()*$mise;
  86. //                    $gainTotal -= $mise;
  87. //                    $mise = 1;
  88. //                    $nbsansVictoire = 0;
  89. //                    $nbMise = 0;
  90. //                }else{
  91. //                    $nbsansVictoire ++;
  92. //                    $nbMise += $mise;
  93. //                    $gainTotal -= $mise;
  94. //                    $mise = $mise*2;
  95. //                    if($nbsansVictoireMax < $nbsansVictoire){
  96. //                        $nbsansVictoireMax = $nbsansVictoire;
  97. //                    }
  98. //                    if($nbMiseMax < $nbMise){
  99. //                        $nbMiseMax = $nbMise;
  100. //                    }
  101. //                }
  102.                 if($resultat[0] == $resultat[4]){
  103.                     $gainTotal += $match->getCoteNul()*$mise;
  104.                     $gainTotal -= $mise;
  105.                     $mise 1;
  106.                     $nbsansVictoire 0;
  107.                     $nbMise 0;
  108.                 }else{
  109.                     $nbsansVictoire ++;
  110.                     $nbMise += $mise;
  111.                     $gainTotal -= $mise;
  112.                     $mise $mise*2;
  113.                     if($nbsansVictoireMax $nbsansVictoire){
  114.                         $nbsansVictoireMax $nbsansVictoire;
  115.                     }
  116.                     if($nbMiseMax $nbMise){
  117.                         $nbMiseMax $nbMise;
  118.                     }
  119.                 }
  120.             }
  121.         }
  122.         dump($gainTotal); dump($nbsansVictoireMax); dump($nbMiseMax);                 exit();
  123.     }
  124.    
  125.     public function initialisation()
  126.     {
  127.         ini_set("memory_limit""-1");
  128.         set_time_limit(0);
  129.         
  130.         $url $urlLigue1.$saison.'/';
  131.         dump($url);        exit();
  132.                 
  133.                 $client = new \GuzzleHttp\Client();
  134.                 $response $client->request('POST'$url , ['form_params' => ['call' => 'expose_full']]);
  135.                 $crawler = new Crawler(json_decode((string)$response->getBody())->echo);
  136.                 
  137.                 $tableauResultat array_filter($crawler->filter('tr')->each(function($node) {
  138.                   
  139.                     try {
  140.                         return [
  141.                         'date' => $node->filter('td')->eq(1)->text(),
  142.                         'domicile' => $node->filter('td')->eq(2)->text(),
  143.                         'resultat' => $node->filter('td')->eq(3)->text(),
  144.                         'exterieur' => $node->filter('td')->eq(4)->text(),
  145.                         'cote_domicile' => $node->filter('td')->eq(5)->text(),
  146.                         'cote_nul' => $node->filter('td')->eq(6)->text(),
  147.                         'cote_exterieur' => $node->filter('td')->eq(7)->text(),
  148.                         ];
  149.                         
  150.                     } catch(\Exception $e) {
  151.                         return null;
  152.                     }
  153.                 }));
  154.         
  155.         
  156. //        $this->majBddSaison();
  157. //        $championnat = $this->getDoctrine()->getRepository(\AppBundle\Entity\Championnat::class)->find(9);
  158. //        $saisons = $this->getDoctrine()->getRepository(\AppBundle\Entity\Saison::class)->findAll();
  159. //            foreach ($saisons as $saison) {
  160. //                $url = 'https://www.scibet.com/football/germany/bundesliga-2/'.$saison->getAnnee().'/';
  161. //                
  162. //                $client = new \GuzzleHttp\Client();
  163. //                $response = $client->request('POST', $url , ['form_params' => ['call' => 'expose_full']]);
  164. //                $crawler = new Crawler(json_decode((string)$response->getBody())->echo);
  165. //                
  166. //                $tableauResultat = array_filter($crawler->filter('tr')->each(function($node) {
  167. //                  
  168. //                    try {
  169. //
  170. //                        return [
  171. //                        'date' => $node->filter('td')->eq(1)->text(),
  172. //                        'domicile' => $node->filter('td')->eq(2)->text(),
  173. //                        'resultat' => $node->filter('td')->eq(3)->text(),
  174. //                        'exterieur' => $node->filter('td')->eq(4)->text(),
  175. //                        'cote_domicile' => $node->filter('td')->eq(5)->text(),
  176. //                        'cote_nul' => $node->filter('td')->eq(6)->text(),
  177. //                        'cote_exterieur' => $node->filter('td')->eq(7)->text(),
  178. //                        ];
  179. //                        
  180. //                    } catch(\Exception $e) {
  181. //                        return null;
  182. //                    }
  183. //                }));
  184. //                $this->majNewBdd($tableauResultat,$saison, $championnat);
  185. //            }
  186. //            
  187.       
  188. //            
  189. //            
  190. //            
  191. //            $rencontres = $this->getDoctrine()->getRepository(\AppBundle\Entity\Rencontre::class)->findAll();
  192. //            $this->ajouterResultatPari($rencontres);
  193. //            
  194. //            
  195. //            
  196.             return ;
  197.     }
  198. }