public function searchForEvent($league_ids = [])
 {
     $query = DotaLeaguePlayersStat::find()->joinWith('account')->where(['leagueid' => $league_ids]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     return $dataProvider;
 }
예제 #2
0
 public static function updateDotaEventPlayerStat()
 {
     $params = DotaParams::loadParams();
     $events = DotaEvent::getActualEventsList();
     $event_ids = ArrayHelper::map($events, 'id', 'id');
     $playersInEvents = DotaEventPlayerStat::getPlayersInEvents($event_ids);
     //echo'<pre>';print_r($playersInEvents);echo'</pre>';die;
     $DotaEventLeague = new DotaEventLeague();
     $LeaguesInEvents = $DotaEventLeague->getLeaguesInEvents($event_ids);
     //echo'<pre>';print_r($event_ids);echo'</pre>';//die;
     //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';die;
     $league_ids = [];
     foreach ($LeaguesInEvents as $event) {
         foreach ($event as $leagueid) {
             $league_ids[] = $leagueid;
         }
     }
     $played_matches = DotaMatchHistoryPlayers::getCountPlayedMatches($league_ids);
     //echo'<pre>';print_r($played_matches);echo'</pre>';die;
     $PlayersInLeagues = DotaLeaguePlayersStat::getPlayersInLeagues($league_ids);
     $PlayersInEvents = DotaEventPlayer::getPlayersInEvents();
     $account_ids = [];
     foreach ($PlayersInEvents as $event) {
         foreach ($event as $player) {
             $account_ids[] = $player;
         }
     }
     $account_ids = array_unique($account_ids);
     $player_roles = DotaPlayer::getPlayersRolesList($account_ids);
     //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';//die;
     //echo'<pre>';print_r($PlayersInLeagues);echo'</pre>';//die;
     //echo'<pre>';print_r($PlayersInEvents);echo'</pre>';//die;
     $summaries = [];
     foreach ($LeaguesInEvents as $event_id => $event) {
         foreach ($event as $leagueid) {
             if (isset($PlayersInLeagues[$leagueid])) {
                 foreach ($PlayersInLeagues[$leagueid] as $account_id => $playersInLeague) {
                     if (isset($PlayersInEvents[$event_id][$account_id])) {
                         $summaries[$event_id][$account_id] = $playersInLeague;
                     }
                 }
             }
         }
     }
     $data_for_insert = [];
     //echo'<pre>';print_r($summaries);echo'</pre>';die;
     foreach ($summaries as $event_id => $players) {
         foreach ($players as $account_id => $player) {
             $kills = $deaths = $assists = $gold_per_min = $xp_per_min = $level = 0;
             $kills += $player['kills'];
             $deaths += $player['deaths'];
             $assists += $player['assists'];
             $gold_per_min += $player['gold_per_min'];
             $xp_per_min += $player['xp_per_min'];
             $level += $player['level'];
             if (isset($playersInEvents[$event_id][$account_id])) {
                 //если есть запись по игроку в event, то обновляем ее
                 $data = ['`kills`' => $kills, '`deaths`' => $deaths, '`assists`' => $assists, '`gold_per_min`' => $gold_per_min, '`xp_per_min`' => $xp_per_min, '`level`' => $level, '`matches`' => isset($played_matches[$account_id]) ? $played_matches[$account_id] : 0];
                 $where = ['`id` = ' . $playersInEvents[$event_id][$account_id]];
                 DotaEventPlayerStat::updateRow($data, $where);
             } else {
                 $data = [$event_id, $account_id, $kills, $deaths, $assists, $gold_per_min, $xp_per_min, $level, isset($played_matches[$account_id]) ? $played_matches[$account_id] : 0];
                 $data_for_insert[] = "(" . implode(',', $data) . ")";
             }
         }
     }
     if (count($data_for_insert) > 0) {
         DotaEventPlayerStat::addRows($data_for_insert);
     }
     // перерасчет кол-ва очков у каждого игрока
     foreach ($summaries as $event_id => $players) {
         DotaEventPlayerStat::calculateScoresForEvent($event_id);
     }
     return true;
 }
 /**
  * Finds the DotaLeaguePlayersStat model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DotaLeaguePlayersStat the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DotaLeaguePlayersStat::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDotaLeaguePlayersStats()
 {
     return $this->hasMany(DotaLeaguePlayersStat::className(), ['account_id' => 'account_id']);
 }