/** * Валидирует массивы с ИД на корректность данных и их количество. * * @param string $attribute the attribute currently being validated * @param array $params the additional name-value pairs given in the rule */ public function validateCount($attribute, $params) { //echo'<pre>'; print_r($this->$attribute);echo'</pre>';//die; if (!$this->hasErrors()) { $dotaParams = DotaParams::loadParams(); $slots_field = $this->getSlotsField($attribute, $this->draft_id); $slots_count = $dotaParams->{$slots_field}; //echo'<pre>'; print_r($slots_count);echo'</pre>';//die; //echo'<pre>'; print_r($slots_field);echo'</pre>';//die; //echo'<pre>'; print_r($this->draft_id);echo'</pre>';//die; //echo'<pre>'; print_r($this->$attribute);echo'</pre>';//die; if (count($this->{$attribute}) != $slots_count) { $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_SLOTS')); } $NumberValidator = new NumberValidator(); $NumberValidator->integerOnly = true; $attr_value = $this->{$attribute}; foreach ($attr_value as $v) { if (!$NumberValidator->validate($v)) { $this->addError($attribute, Yii::t('app', 'FANTASY_RATE_SEND_ERROR_INT')); break; } } } }
/** * * @return mixed */ public function actionUpdateDota() { $model = DotaParams::loadParams(); //echo'<pre>';print_r($model['scores_on_rate']);echo'</pre>';//die; if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->session->setFlash('success', Yii::t('app', 'Saved.')); return $this->redirect(['view-dota']); } else { return $this->render('dota/update', ['model' => $model]); } }
/** * считает кол-во очков у ивента * @param $event DotaEvent */ public static function calculateScores($event) { $params = DotaParams::loadParams(); $hero_ids = []; foreach ($event->dotaEventHeroStat as $hero) { $hero_ids[] = $hero->hero_id; } $hero_roles = DotaHero::getHeroesRolesList($hero_ids); //echo'<pre>';print_r($hero_roles);echo'</pre>';//die; //echo'<pre>';print_r($event->dotaEventHeroStat);echo'</pre>';die; foreach ($event->dotaEventHeroStat as $hero) { $level = $hero->level + $hero->level_corr; $kills = $hero->kills + $hero->kills_corr; $deaths = $hero->deaths + $hero->deaths_corr; $assists = $hero->assists + $hero->assists_corr; $gold_per_min = $hero->gold_per_min + $hero->gold_per_min_corr; $xp_per_min = $hero->xp_per_min + $hero->xp_per_min_corr; $bans = $hero->bans + $hero->bans_corr; $picks = $hero->picks + $hero->picks_corr; $scores = $level * $hero_roles[$hero->hero_id] + $kills * $params['ratio_kills'] + $deaths * $params['ratio_deaths'] + $assists * $params['ratio_assists'] + $gold_per_min * $params['ratio_gold_per_min'] + $xp_per_min * $params['ratio_xp_per_min'] + $bans * $params['scores_per_ban'] + $picks * $params['scores_per_pick']; //$scores = ($kills * $params['ratio_kills']) + ($deaths * $params['ratio_deaths']) + ($assists * $params['ratio_assists']) + ($gold_per_min * $params['ratio_gold_per_min']) + ($xp_per_min * $params['ratio_xp_per_min']); $hero->scores = $scores; $hero->save(); } }
/** * считает кол-во очков у ивента * @param $event DotaEvent */ public static function calculateScores($event) { $params = DotaParams::loadParams(); $account_ids = []; foreach ($event->dotaEventPlayerStat as $player) { $account_ids[] = $player->account_id; } $player_roles = DotaPlayer::getPlayersRolesList($account_ids); foreach ($event->dotaEventPlayerStat as $player) { $level = $player->level + $player->level_corr; $kills = $player->kills + $player->kills_corr; $deaths = $player->deaths + $player->deaths_corr; $assists = $player->assists + $player->assists_corr; $gold_per_min = $player->gold_per_min + $player->gold_per_min_corr; $xp_per_min = $player->xp_per_min + $player->xp_per_min_corr; $scores = $level * $player_roles[$player->account_id] + $kills * $params['ratio_kills'] + $deaths * $params['ratio_deaths'] + $assists * $params['ratio_assists'] + $gold_per_min * $params['ratio_gold_per_min'] + $xp_per_min * $params['ratio_xp_per_min']; $player->scores = $scores; $player->save(); } }
public function actionShowRatings($id) { $modelFantasy = new DotaFantasy(); $model = $modelFantasy->loadFantasyInfo($id); //echo'<pre>';print_r($model);echo'</pre>';die; if ($model === false) { return; } $DraftModel = new DotaDraft(); $rates_list = $DraftModel->getRatesListWithResults([$id]); $params = DotaParams::loadParams(); $prizes = PrizeMatrix::getPrizesForFantasy($model); return $this->renderPartial('/common/show-ratings', ['model' => $model, 'rates_list' => $rates_list, 'params' => $params, 'prizes' => $prizes, 'game_id' => GamesParams::GAME_DOTA, 'game_name' => GamesParams::GAME_DOTA_NAME]); }
public static function updateDotaEventHeroStat() { $params = DotaParams::loadParams(); $events = DotaEvent::getActualEventsList(); $event_ids = ArrayHelper::map($events, 'id', 'id'); $heroesInEvents = DotaEventHeroStat::getHeroesInEvents($event_ids); $DotaEventLeague = new DotaEventLeague(); $LeaguesInEvents = $DotaEventLeague->getLeaguesInEvents($event_ids); //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';die; $league_ids = []; foreach ($LeaguesInEvents as $event) { foreach ($event as $leagueid) { $league_ids[] = $leagueid; } } $played_matches = DotaMatchHistoryHeroes::getCountPlayedMatches($league_ids); //echo'<pre>';print_r($played_matches);echo'</pre>';die; $HeroesInLeagues = DotaLeagueHeroesStat::getHeroesInLeagues($league_ids); //echo'<pre>';print_r($HeroesInLeagues);echo'</pre>';die; $HeroesInEvents = DotaEventHero::getHeroesInEvents(); $hero_ids = []; foreach ($HeroesInEvents as $event) { foreach ($event as $hero) { $hero_ids[] = $hero; } } $hero_ids = array_unique($hero_ids); //echo'<pre>';print_r($hero_ids);echo'</pre>';die; //$player_roles = DotaPlayer::getPlayersRolesList($account_ids); //echo'<pre>';print_r($LeaguesInEvents);echo'</pre>';//die; $summaries = []; foreach ($LeaguesInEvents as $event_id => $event) { foreach ($event as $leagueid) { if (isset($HeroesInLeagues[$leagueid])) { foreach ($HeroesInLeagues[$leagueid] as $hero_id => $heroesInLeague) { if (isset($HeroesInEvents[$event_id][$hero_id])) { $summaries[$event_id][$hero_id] = $heroesInLeague; } } } } } $data_for_insert = []; //echo'<pre>';print_r($summaries);echo'</pre>';die; foreach ($summaries as $event_id => $heroes) { foreach ($heroes as $hero_id => $hero) { $kills = $deaths = $assists = $gold_per_min = $xp_per_min = $level = $picks = $bans = 0; $kills += $hero['kills']; $deaths += $hero['deaths']; $assists += $hero['assists']; $gold_per_min += $hero['gold_per_min']; $xp_per_min += $hero['xp_per_min']; $level += $hero['level']; $picks += $hero['picks']; $bans += $hero['bans']; if (isset($heroesInEvents[$event_id][$hero_id])) { //если есть запись по игроку в event, то обновляем ее $data = ['`kills`' => $kills, '`deaths`' => $deaths, '`assists`' => $assists, '`gold_per_min`' => $gold_per_min, '`xp_per_min`' => $xp_per_min, '`level`' => $level, '`picks`' => $picks, '`bans`' => $bans, '`matches`' => isset($played_matches[$hero_id]) ? $played_matches[$hero_id] : 0]; $where = ['`id` = ' . $heroesInEvents[$event_id][$hero_id]]; //echo'<pre>updateRow</pre>';//die; DotaEventHeroStat::updateRow($data, $where); } else { $data = [$event_id, $hero_id, $kills, $deaths, $assists, $gold_per_min, $xp_per_min, $level, $picks, $bans, isset($played_matches[$hero_id]) ? $played_matches[$hero_id] : 0]; $data_for_insert[] = "(" . implode(',', $data) . ")"; } } } //echo'<pre>';print_r($data_for_insert);echo'</pre>';die; if (count($data_for_insert) > 0) { DotaEventHeroStat::addRows($data_for_insert); } // перерасчет кол-ва очков у каждого героя foreach ($summaries as $event_id => $heroes) { DotaEventHeroStat::calculateScoresForEvent($event_id); } return true; }