Module: Neuron::Client::ZoneCalculations
- Included in:
- Zone
- Defined in:
- lib/neuron-client/model/zone_calculations.rb
Instance Method Summary collapse
-
#ads_by_priority ⇒ Object
This module expects the following methods to be defined:.
- #calculate_ads_by_priority ⇒ Object
Instance Method Details
#ads_by_priority ⇒ Object
This module expects the following methods to be defined:
ad_links (Hash, keys are ad IDs, values are a sub-hash: => p, ‘weight’ => w) find_ad(ad_id) (nil, or an object that responds to :active? and :pressure)
9 10 11 |
# File 'lib/neuron-client/model/zone_calculations.rb', line 9 def ads_by_priority calculate_ads_by_priority end |
#calculate_ads_by_priority ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/neuron-client/model/zone_calculations.rb', line 13 def calculate_ads_by_priority entries = {} ad_links.each do |ad_id, link| next unless ad = find_ad(ad_id) pressure = ad.active? ? ad.pressure : nil next if pressure.nil? weight = link['weight'].to_f priority = link['priority'].to_f entries[priority] ||= [] entries[priority] << [ad_id, weighted_pressure(weight, pressure)] end entries.sort_by do |priority, entry| priority end.map do |priority, entry| entry.sort_by(&:first) end end |