Skip to content

Commit

Permalink
fix indeterminate calculation of performance based on order of create…
Browse files Browse the repository at this point in the history
…d_at of matches
  • Loading branch information
danReynolds committed Jul 4, 2018
1 parent 121f00e commit 1a4082d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -28,3 +28,4 @@ coverage/*
pgdata
todo.md
factors.md
tmp/pids/server.pid
2 changes: 1 addition & 1 deletion lib/strategy_engine.rb
Expand Up @@ -202,7 +202,7 @@ def champion_matchup_performance(args)

# Whether the summoner is on a winning or losing streak
def longest_streak(args)
streak = args[:performances].sort_by { |performance| performance.created_at }.reverse
streak = args[:performances].sort_by { |performance| performance.id }.reverse
winning_streak = streak.first.victorious?
streak_length = streak.take_while { |performance| performance.victorious? == winning_streak }.length

Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/summoners_controller_spec.rb
Expand Up @@ -28,6 +28,7 @@
allow(RiotApi::RiotApi).to receive(:fetch_response).and_return(
external_response
)
allow(Cache).to receive(:set_summoner_rank).and_return(nil)

@matches = create_list(:match, 10)
@matches.each do |match|
Expand Down Expand Up @@ -126,6 +127,8 @@ def rand(seed)
allow(RiotApi::RiotApi).to receive(:fetch_response).and_return(
summoner_queue_response
)
allow(Cache).to receive(:set_current_match_rating).and_return(nil)
allow(Cache).to receive(:set_summoner_rank).and_return(nil)
@summoner = create(:summoner, name: 'wingilote')
@summoner2 = create(:summoner, name: 'endless white')
@champion = Champion.new(name: 'Miss Fortune')
Expand Down Expand Up @@ -543,7 +546,7 @@ def rand(seed)

it 'should favor the strong performer' do
post action, params: params
expect(speech).to eq 'I would give Hero man playing Vayne a performance rating of 93% for this matchup compared to Other man as Sivir who I would rate around 56%. My money is definitely on Hero man this time.'
expect(speech).to eq 'I would give Hero man playing Vayne a performance rating of 97% for this matchup compared to Other man as Sivir who I would rate around 36%. My money is definitely on Hero man this time.'
end
end

Expand Down Expand Up @@ -574,7 +577,7 @@ def rand(seed)

it 'should indicate that it is unsure who to favor' do
post action, params: params
expect(speech).to eq 'This one looks fairly close, I am going to give Hero man a performance rating of 84% for this matchup versus Other man with 82%.'
expect(speech).to eq 'This one looks fairly close, I am going to give Hero man a performance rating of 87% for this matchup versus Other man with 80%.'
end
end

Expand Down Expand Up @@ -1589,7 +1592,7 @@ def rand(seed)
allow(RiotApi::RiotApi).to receive(:fetch_response).and_return(
external_response
)
Cache.set_summoner_rank(@summoner.summoner_id, nil)
allow(Cache).to receive(:set_summoner_rank).and_return(nil)
end

context 'with a renamed summoner' do
Expand All @@ -1615,12 +1618,9 @@ def rand(seed)
end
end

context 'when cached' do
it 'should not make an API request' do
post action, params: params
post action, params: params
expect(RiotApi::RiotApi).to have_received(:fetch_response).once
end
it 'should cache the summoner queue' do
post action, params: params
expect(Cache).to have_received(:set_summoner_rank)
end

context 'with no summoner information' do
Expand Down

0 comments on commit 1a4082d

Please sign in to comment.