Created
May 6, 2016 17:08
-
-
Save rodrigovirgilio/8ae9173e8f78683ada0cadf3ec1513e7 to your computer and use it in GitHub Desktop.
Add MMR players to teams Riot - Codeminer42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TeamMMRUpdater | |
def self.call(*args) | |
new(*args).call | |
end | |
def initialize(team) | |
@team = team | |
end | |
def call | |
elo_400 = RiotAPI::BR::ParticipantAPI.new.call(player_names).map { |player| player.elo['400'] }.compact | |
team_size = Settings.riot_api.global.team_size | |
mmr_sum = elo_400.sort.reverse.take(team_size).sum | |
mmr_team = (mmr_sum / team_size.to_d).round | |
team.update(mmr: mmr_team) | |
end | |
private | |
attr_reader :team | |
def player_names | |
team.players.pluck(:name) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
team = Team.first #red_team
team = Team.first #blue_team
teams = Team.all
team.players.pluck(:name) #list players from team
TeamMMRUpdater.call(t) #add field mmr in table teams the average players
all teams
teams.each do |t|
TeamMMRUpdater.call(t)
end