Beispiel #1
0
 public static function updateMatchesResultsAdv($league_key = 0, $match_key = 0)
 {
     $cache = Yii::$app->cache;
     $match_ids = [];
     $league_ids_ = Yii::$app->cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS);
     $e_ids = Yii::$app->cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_E_IDS);
     //$league_ids_ = false;
     //echo'<pre>';var_dump(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS);echo'</pre>';//die;
     //echo'<pre>';var_dump(Yii::$app->cache[self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS]);echo'</pre>';//die;
     //echo'<pre>';var_dump($league_ids_);echo'</pre>';//die;
     //echo'<pre>';print_r(Yii::$app->cache);echo'</pre>';//die;
     if ($league_ids_ === false) {
         $events = DotaEvent::getActualEventsList();
         //echo'<pre>';print_r($events);echo'</pre>';//die;
         $league_ids = [];
         $e_ids = [];
         foreach ($events as $event) {
             foreach ($event->dotaEventLeagues as $league) {
                 $league_ids[] = $league->leagueid;
                 $e_ids[] = $event->id;
             }
         }
         $league_ids_ = array_unique($league_ids);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS, $league_ids_, self::DOTAPARSER_CACHE_TIME);
         //$cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS, $league_ids_);
         //Yii::$app->cache->add(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS, '12312312312');
         //Yii::$app->cache[self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS] = '12312312312';
         //echo'<pre>';var_dump($league_ids_);echo'</pre>';//die;
         //echo'cache<pre>';print_r($league_ids_);echo'</pre>';//die;
         // нужно забрать игроков только из активных лиг, т.е. тех которые есть в ивентах сейчас
         $e_ids = array_unique($e_ids);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_E_IDS, $e_ids, self::DOTAPARSER_CACHE_TIME);
     }
     //echo'<pre>';print_r($league_ids_);echo'</pre>';//die;
     //echo'<pre>';print_r($e_ids);echo'</pre>';die;
     $league_ids = [];
     foreach ($league_ids_ as $val) {
         $league_ids[$val] = $val;
     }
     //echo'<pre>';print_r($league_ids_);echo'</pre>';//die;
     //echo'<pre>';print_r($league_ids);echo'</pre>';//die;
     //echo'<pre>';print_r($league_key);echo'</pre>';die;
     if (count($league_ids_) != 0) {
         $player_ids = $cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_PLAYER_IDS);
         if ($player_ids === false) {
             $player_ids = DotaEventPlayer::getPresentedAccontIdsInEvents($e_ids);
             $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_PLAYER_IDS, $player_ids, self::DOTAPARSER_CACHE_TIME);
         }
         //echo'<pre>';print_r($e_ids);echo'</pre>';die;
         //echo'<pre>';print_r($player_ids);echo'</pre>';die;
         $hero_ids = $cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_HERO_IDS);
         if ($hero_ids === false) {
             $hero_ids = DotaEventHero::getPresentedHeroIdsInEvents($e_ids);
             $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_HERO_IDS, $hero_ids, self::DOTAPARSER_CACHE_TIME);
         }
         //echo'<pre>';print_r($hero_ids);echo'</pre>';//die;
         //$max_match_ids = DotaMatchHistoryPlayers::getMaxMatchIdOnLeagues($league_ids);
         $max_match_ids = $cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MAX_MATCH_IDS);
         if ($max_match_ids === false) {
             $max_match_ids = DotaMatchLastRecieved::getMaxMatchIds($league_ids);
             $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MAX_MATCH_IDS, $max_match_ids, self::DOTAPARSER_CACHE_TIME);
         }
         //echo'<pre>$max_match_ids ';print_r($max_match_ids);echo'</pre>';//die;
         //echo '<pre>$league_ids ';print_r($league_ids_);echo '</pre>';die;
         $league_id = $league_ids_[$league_key];
         $match_ids = $cache->get(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MATCH_IDS);
         if ($match_ids === false) {
             $match_ids = self::getMatchIdsFromLeague($league_id, isset($max_match_ids[$league_id]) ? $max_match_ids[$league_id] : -1);
             $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MATCH_IDS, $match_ids, self::DOTAPARSER_CACHE_TIME);
         }
         //echo'<pre>$match_ids ';print_r($match_ids);echo'</pre>';//die;
         //echo'<pre>$league_ids ';print_r($league_id);echo'</pre>';//die;
         //echo'<pre>$league_ids ';print_r($match_ids);echo'</pre>';die;
         $task = 'updateMatchesResults';
         if (count($match_ids) > 0) {
             for ($x = 0; $x < 30; $x++) {
                 if ($match_key == count($match_ids)) {
                     break;
                 }
                 $match_id = $match_ids[$match_key];
                 $rows = self::_getMatchDetails($match_id);
                 $hero_ids_map = [];
                 //echo'<pre>';print_r($rows);echo'</pre>';//die;
                 if (isset($rows['players'])) {
                     $hero_ids_map = self::_addDotaMatchHistoryPlayers($rows['players'], $player_ids, $match_id, $league_id);
                     if (isset($rows['picks_bans'])) {
                         self::_addDotaMatchHistoryHeroes($rows['players'], $rows['picks_bans'], $hero_ids_map, $hero_ids, $match_id, $league_id);
                     }
                 }
                 $match_key++;
                 if ($match_key == count($match_ids)) {
                     break;
                 }
             }
             if ($match_key == count($match_ids)) {
                 if (count($match_ids)) {
                     DotaMatchLastRecieved::addLastRecievedMatchId($league_id, $match_ids[0]);
                 }
                 $league_key++;
                 $match_key = 0;
                 $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MATCH_IDS, false);
             }
         } else {
             $league_key++;
             $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MATCH_IDS, false);
         }
     }
     if ($league_key == count($league_ids)) {
         $league_key = -1;
         $match_key = -1;
         $task = 'next';
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_LEAGUE_IDS, false);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_PLAYER_IDS, false);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_HERO_IDS, false);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MAX_MATCH_IDS, false);
         $cache->set(self::DOTAPARSER_UPDATEMATCHESRESULTSADV_MATCH_IDS, false);
     }
     return ['league_key' => $league_key, 'match_key' => $match_key, 'match_count' => count($match_ids), 'task' => $task];
 }