Module Prompt::Extremes
In: lib/algorithms/prompt/extremes.rb

Methods

prompts  

Included Modules

Algorithms::Prompt

Constants

ID = 4   TODO: legacy algorithm IDs are on higher than their DB in database update database data and sync here to match DB IDs. algorithm ID

Public Class methods

Generate count number of prompts based on question ID and voter ID by placing high rating prompt against low ratings prompts as measured by winning percentage.

Return

An array of prompts

Parameters

question_id<int>:Generate prompts for this question ID
voter_id<int>:Generate prompts for this voter ID
count<int>:Generate this number of prompts

[Source]

    # File lib/algorithms/prompt/extremes.rb, line 19
19:     def prompts(question_id, voter_id, count)
20:       all_items = Item.all(conditions(question_id).merge(
21:         :group => "items.id",
22:         :order => "items_questions.wins / (items_questions.wins + items_questions.losses) DESC"
23:       ))
24:       top_items = all_items.first(all_items.length / 2)
25:       bottom_items = all_items - top_items
26:       cur_top_items = []
27:       cur_bottom_items = []
28:       prompt_item_ids = {}
29:       # leaks with create/find in req loop
30:       Prompt.transaction do
31:         count.times do |i|
32:           cur_top_items = top_items.dup if cur_top_items.empty? # ensure we still have items
33:           cur_bottom_items = bottom_items.dup if cur_bottom_items.empty?
34:           prompt = prompt_for_request(question_id, voter_id, ID)
35:           prompt.items << cur_top_items.delete_at(rand(cur_top_items.length)) << cur_bottom_items.delete_at(rand(cur_bottom_items.length))
36:           redo if bad_prompt?(prompt)
37:           prompt_item_ids[prompt.id] = prompt.item_ids
38:         end
39:       end
40:       prompt_item_ids
41:     end

[Validate]