Skip to content

Instantly share code, notes, and snippets.

@rodrigovirgilio
Created May 6, 2016 17:08
Show Gist options
  • Save rodrigovirgilio/8ae9173e8f78683ada0cadf3ec1513e7 to your computer and use it in GitHub Desktop.
Save rodrigovirgilio/8ae9173e8f78683ada0cadf3ec1513e7 to your computer and use it in GitHub Desktop.
Add MMR players to teams Riot - Codeminer42
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
@rodrigovirgilio
Copy link
Author

rodrigovirgilio commented May 6, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment