Skip to content

Commit

Permalink
support querying current match about other summoners
Browse files Browse the repository at this point in the history
  • Loading branch information
danReynolds committed Mar 31, 2018
1 parent f29f06b commit e1974d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
28 changes: 13 additions & 15 deletions app/controllers/summoners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,46 +285,44 @@ def champion_performance_summary
end

def current_match
args = { summoner: @summoner.name }
match_data = RiotApi.get_current_match(id: @summoner.summoner_id)

unless match_data
return render json: {
speech: ApiResponse.get_response(dig_set(:errors, *@namespace, :no_current_match), args)
speech: ApiResponse.get_response(dig_set(:errors, *@namespace, :no_current_match), { summoner: @summoner.name })
}
end

match = MatchHelper.initialize_current_match(match_data)

performances = match.team1.summoner_performances + match.team2.summoner_performances
summoner_performance = performances.find { |performance| performance.summoner == @summoner }
opposing_performance = performances.find do |performance|
performance.role == summoner_performance.role && performance != summoner_performance
end
own_summoner_performance = performances.find { |performance| performance.summoner == @summoner }
role = summoner_params[:role] || own_summoner_performance.role
queried_summoner_performance = own_summoner_performance.team.summoner_performances.find { |performance| performance.role == role }
queried_summoner = queried_summoner_performance.summoner
opposing_performance = performances.find { |performance| performance.role == role && performance != queried_summoner_performance }
opposing_summoner = opposing_performance.summoner
role = summoner_performance.role

champion = Champion.find(summoner_performance.champion_id)
champion = Champion.find(queried_summoner_performance.champion_id)
opposing_champion = Champion.find(opposing_performance.champion_id)

args.merge!({
args = {
summoner: queried_summoner.name,
champion: champion.name,
opposing_champion: opposing_champion.name,
opposing_summoner: opposing_summoner.name,
role: ChampionGGApi::MATCHUP_ROLES[role.to_sym]
})
}

performance_rating = StrategyEngine.run(
summoner: @summoner,
summoner: queried_summoner,
summoner2: opposing_summoner,
champion: champion,
champion2: opposing_champion,
role: role
)
Cache.set_current_match_rating(
@summoner.id,
queried_summoner.id,
performance_rating.merge({
summoner: @summoner.name,
summoner: queried_summoner.name,
champion: champion.name,
opposing_champion: opposing_champion.name,
opposing_summoner: opposing_summoner.name,
Expand Down
11 changes: 11 additions & 0 deletions spec/controllers/summoners_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@
end
end

context 'with a role specified' do
before :each do
summoner_params[:role] = 'DUO_SUPPORT'
end

it 'should determine the current match performance ratings for the summoners in the requested role' do
post action, params: params
expect(speech).to eq 'This one looks fairly close, I am going to give Yang a performance rating of 40% for this matchup versus Gardy with 45%. Ask me why for details.'
end
end

context 'with the summoner in game' do
it "should determine the performance ratings for the summoner's lane" do
post action, params: params
Expand Down

0 comments on commit e1974d1

Please sign in to comment.