Skip to content

Commit

Permalink
add summoner bans (#188)
Browse files Browse the repository at this point in the history
* add summoner bans

* update api.json to renamed counters endpoint

* add summoner spells endpoint as well
  • Loading branch information
danReynolds committed Dec 22, 2017
1 parent d94b66c commit e9ac469
Show file tree
Hide file tree
Showing 6 changed files with 686 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

# Ignore all logfiles and tempfiles.
log/*
tmp/*
!/log/.keep
!/tmp/.keep
!/tmp/.pids
!tmp/pids
*.env

# Ignore Byebug command history file.
Expand Down
82 changes: 70 additions & 12 deletions api.json

Large diffs are not rendered by default.

68 changes: 63 additions & 5 deletions app/controllers/summoners_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SummonersController < ApplicationController
before_action only: [:champion_performance_summary, :champion_performance_position] do
process_performance_request(with_role: true, with_champion: true)
end
before_action only: [:champion_build, :champion_matchup_ranking] do
before_action only: [:champion_build, :champion_counters, :champion_bans, :champion_spells] do
process_performance_request(with_role: true, with_champion: true, with_sorting: true)
end

Expand All @@ -29,6 +29,64 @@ def performance_summary
}
end

def champion_spells
champion = Champion.new(name: summoner_params[:champion])
args = @processed_request[:args]
performance_spells = @processed_request[:performances].group_by do |performance|
[performance.spell1_id, performance.spell2_id].sort
end

spell_filter = Filterable.new({
collection: performance_spells,
sort_method: performance_ranking_sort(@processed_request[:sort_type]),
reverse: true,
list_size: 1
}.merge(summoner_params.slice(:list_order, :list_position)))
filtered_spells = spell_filter.filter
filter_types = spell_filter.filter_types

args.merge!(ApiResponse.filter_args(spell_filter))
ids_to_names = Cache.get_collection(:spells)
spells = if filtered_spells.empty?
[]
else
filtered_spells.first.first.map { |spell_id| ids_to_names[spell_id] }
end

args.merge!({
spells: spells.en.conjunction(article: false),
real_size_combination_conjugation: 'combination'.en.pluralize(spell_filter.real_size)
})
namespace = dig_set(*@namespace, *@processed_request[:namespace], *filter_types.values)
render json: { speech: ApiResponse.get_response(namespace, args) }
end

def champion_bans
champion = Champion.new(name: summoner_params[:champion])
args = @processed_request[:args]
performance_bans = @processed_request[:performances].group_by { |performance| performance.ban.champion_id }

ban_filter = Filterable.new({
collection: performance_bans,
sort_method: performance_ranking_sort(@processed_request[:sort_type]),
reverse: true
}.merge(summoner_params.slice(:list_order, :list_size, :list_position)))
filtered_bans = ban_filter.filter
filter_types = ban_filter.filter_types

args.merge!(ApiResponse.filter_args(ban_filter))
ids_to_names = Cache.get_collection(:champions)
champions = filtered_bans.map { |performance_data| ids_to_names[performance_data.first] }

args.merge!({
champions: champions.en.conjunction(article: false),
real_size_champion_conjugation: 'champion'.en.pluralize(ban_filter.real_size)
})

namespace = dig_set(*@namespace, *@processed_request[:namespace], *filter_types.values)
render json: { speech: ApiResponse.get_response(namespace, args) }
end

def champion_build
champion = Champion.new(name: summoner_params[:champion])
args = @processed_request[:args].merge({ champion: champion.name })
Expand Down Expand Up @@ -64,20 +122,20 @@ def champion_build
render json: { speech: ApiResponse.get_response(namespace, args) }
end

def champion_matchup_ranking
def champion_counters
args = @processed_request[:args]
matchup_rankings = @processed_request[:performances].map(&:opponent)
counters = @processed_request[:performances].map(&:opponent)
.compact.group_by(&:champion_id).to_a

if matchup_rankings.empty?
if counters.empty?
namespace = dig_set(
:errors, *@namespace, *dig_list(@processed_request[:namespace]), :no_opponents
)
return render json: { speech: ApiResponse.get_response(namespace, args) }
end

matchup_filter = Filterable.new({
collection: matchup_rankings,
collection: counters,
sort_method: performance_ranking_sort(@processed_request[:sort_type]),
reverse: true
}.merge(summoner_params.slice(:list_order, :list_size, :list_position)))
Expand Down
96 changes: 94 additions & 2 deletions config/api_responses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,99 @@ summoners:
- "{name} has played {champion} {role} {total_performances} recently and averages {position_value} {position_name}."
no_recency:
- "{name} has played {champion} {role} {total_performances} this season and averages {position_value} {position_name}."
champion_matchup_ranking:
champion_spells:
no_recency:
empty:
normal:
- '{name} has not played any games as {champion} {role} this season in ranked solo queue.'
offset:
- '{name} only has used {real_size} spell {real_size_combination_conjugation} playing as {champion} {role} so far this season.'
single:
normal:
- 'The spell combination used by {name} that gives the summoner playing {champion} {role} the {list_order} {sort_type} is {spells}.'
offset:
- 'The spell combination used by {name} that gives the summoner playing {champion} {role} the {list_position} {list_order} {sort_type} is {spells}.'
recency:
empty:
normal:
- '{name} has not played any games as {champion} {role} recently in ranked solo queue.'
offset:
- '{name} only has used {real_size} spell {real_size_combination_conjugation} playing as {champion} {role} recently this season.'
single:
normal:
complete:
- 'The spell combination used by {name} that gives the summoner playing {champion} {role} the {list_order} {sort_type} is {spells}.'
incomplete:
- '{name} has only used {real_size} spell {real_size_combination_conjugation} recently as {champion} {role}. The spell combo used by {name} with the {list_order} {sort_type} playing {name} as {champion} {role} is {spells}.'
offset:
complete:
- 'The spell combination used by {name} that gives the summoner playing {champion} {role} the {list_position} {list_order} {sort_type} is {spells}.'
incomplete:
- '{name} has only used {real_size} different spell {real_size_combination_conjugation} recently as {champion} {role}. The spell combo used by {name} that gives gives the {list_position} {list_order} {sort_type} is {spells}.'
champion_bans:
no_recency:
empty:
normal:
- '{name} has not played any games as {champion} {role} this season in ranked solo queue.'
offset:
complete:
- 'No bans were requested.'
incomplete:
- '{name} has only banned {real_size} {real_size_champion_conjugation} playing as {champion} {role} so far this season.'
single:
normal:
complete:
- 'The ban by {name} playing {champion} {role} that gives the summoner the {list_order} {sort_type} is {champions}.'
incomplete:
- '{name} has only played against {real_size} {real_size_champion_conjugation} so far this season as {champion} {role}. The ban by {name} with the {list_order} {sort_type} is {champions}.'
offset:
complete:
- 'The ban by {name} that gives the summoner playing {champion} {role} the {list_position} {list_order} {sort_type} is {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} so far this season as {champion} {role}. The ban by {name} that gives the summoner the {list_position} {list_order} {sort_type} is {champions}.'
multiple:
normal:
complete:
- 'The bans by {name} playing {champion} {role} that give the summoner the {list_order} {sort_type} are {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} so far this season as {champion} {role}. The bans by {name} that give the summoner the {list_order} {sort_type} are {champions}.'
offset:
complete:
- 'The {list_position} through {filtered_position_offset} bans that give {name} playing {champion} {role} the {list_order} {sort_type} are {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} so far this season as {champion} {role}. The {list_position} through {filtered_position_offset} bans that give {name} the {list_order} {sort_type} are {champions}.'
recency:
empty:
normal:
- '{name} has not played any games as {champion} {role} recently in ranked solo queue.'
offset:
complete:
- 'No bans were requested.'
incomplete:
- '{name} has only banned {real_size} {real_size_champion_conjugation} playing as {champion} {role} recently.'
single:
normal:
complete:
- 'The ban by {name} playing {champion} {role} that gives the summoner the {list_order} {sort_type} is {champions}.'
incomplete:
- '{name} has only played against {real_size} {real_size_champion_conjugation} recently as {champion} {role}. The ban by {name} with the {list_order} {sort_type} is {champions}.'
offset:
complete:
- 'The ban by {name} that gives the summoner playing {champion} {role} the {list_position} {list_order} {sort_type} is {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} recently as {champion} {role}. The ban by {name} that gives the summoner the {list_position} {list_order} {sort_type} is {champions}.'
multiple:
normal:
complete:
- 'The bans by {name} playing {champion} {role} that give the summoner the {list_order} {sort_type} are {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} recently as {champion} {role}. The bans by {name} that give the summoner the {list_order} {sort_type} are {champions}.'
offset:
complete:
- 'The {list_position} through {filtered_position_offset} bans that give {name} playing {champion} {role} the {list_order} {sort_type} are {champions}.'
incomplete:
- '{name} has only played against {real_size} different {real_size_champion_conjugation} recently as {champion} {role}. The {list_position} through {filtered_position_offset} bans that give {name} the {list_order} {sort_type} are {champions}.'
champion_counters:
no_recency:
empty:
normal:
Expand Down Expand Up @@ -367,7 +459,7 @@ summoners:
- '{name} has only played {real_size} {real_size_champion_conjugation} recently. The {list_position} through {filtered_position_offset} champions played by {name} with the {list_order} {sort_type} are {champions}.'
errors:
summoners:
champion_matchup_ranking:
champion_counters:
no_recency:
no_opponents:
- 'I could not find any opponents for {name} playing {champion} {role} this season.'
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
post :champion_performance_summary
post :champion_performance_position
post :champion_performance_ranking
post :champion_matchup_ranking
post :champion_counters
post :champion_build
post :champion_bans
post :champion_spells
end
end

0 comments on commit e9ac469

Please sign in to comment.