Module: Weathercock::Scorable::ClassMethods
- Defined in:
- lib/weathercock/scorable.rb
Instance Method Summary collapse
- #hit_counts(event, ids:, **window) ⇒ Object
- #top(event, decay_factor: nil, **window) ⇒ Object
- #weathercock_base_key(event) ⇒ Object
Instance Method Details
#hit_counts(event, ids:, **window) ⇒ Object
26 27 28 29 30 |
# File 'lib/weathercock/scorable.rb', line 26 def hit_counts(event, ids:, **window) redis = Weathercock.config.redis dest = window.empty? ? "#{weathercock_base_key(event)}:total" : weathercock_union(event, window) ids.to_h { |id| [id.to_s, (redis.call("ZSCORE", dest, id.to_s) || "0").to_i] } end |
#top(event, decay_factor: nil, **window) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/weathercock/scorable.rb', line 19 def top(event, decay_factor: nil, **window) return Weathercock.config.redis.call("ZRANGE", "#{weathercock_base_key(event)}:total", 0, -1, "REV") if window.empty? dest = weathercock_union(event, window, decay_factor: decay_factor) Weathercock.config.redis.call("ZRANGE", dest, 0, -1, "REV") end |
#weathercock_base_key(event) ⇒ Object
32 33 34 |
# File 'lib/weathercock/scorable.rb', line 32 def weathercock_base_key(event) "#{Weathercock.config.namespace}:#{name.gsub("::", "_").downcase}:#{event}" end |