module ChannelStats
Constants
- KEY
- PLUGIN
Public Instance Methods
Source
# File lib/channel_stats.rb, line 46 def busiest_hour(network:, channel:, store: RabbotDb) hour_key = store.get_plugin_json( plugin: PLUGIN, key: "hour_counts", network: network, channel: channel, default: {} ) return nil if hour_key.empty? hour, count = hour_key.max_by { |_hour, value| value } { hour: hour.to_i, count: count } end
Source
# File lib/channel_stats.rb, line 79 def format_stats_report(top_nicks:, busiest_hour: nil) lines = top_nicks.map.with_index(1) { |entry, index| "#{index}. #{entry[:nick]} — #{entry[:count]} msgs" } if busiest_hour lines << "Busiest hour: #{busiest_hour[:hour].to_s.rjust(2, '0')}:00 UTC (#{busiest_hour[:count]} msgs)" end lines.join("\n") end
Source
# File lib/channel_stats.rb, line 11 def increment(network:, channel:, nick:, store: RabbotDb) counts = load(network: network, channel: channel, store: store) key = nick.to_s counts[key] = counts.fetch(key, 0) + 1 save(network: network, channel: channel, counts: counts, store: store) end
Source
# File lib/channel_stats.rb, line 18 def load(network:, channel:, store: RabbotDb) data = store.get_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, default: {} ) data.is_a?(Hash) ? data : {} end
Source
# File lib/channel_stats.rb, line 60 def record_hour(network:, channel:, at: Time.now, store: RabbotDb) hour = at.utc.hour counts = store.get_plugin_json( plugin: PLUGIN, key: "hour_counts", network: network, channel: channel, default: {} ) counts[hour.to_s] = counts.fetch(hour.to_s, 0) + 1 store.set_plugin_json( plugin: PLUGIN, key: "hour_counts", network: network, channel: channel, value: counts ) end
Source
# File lib/channel_stats.rb, line 29 def save(network:, channel:, counts:, store: RabbotDb) store.set_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, value: counts ) end
Source
# File lib/channel_stats.rb, line 39 def top_nicks(network:, channel:, limit: 5, store: RabbotDb) load(network: network, channel: channel, store: store) .sort_by { |nick, count| [-count, nick.downcase] } .first(limit) .map { |nick, count| { nick: nick, count: count } } end