module Dialog::Statistics
Public Class Methods
defHeaderFQNPerUser(args)
click to toggle source
# File lib/statistics/func.rb, line 57 def defHeaderFQNPerUser(args) return {:type => 'FQNPerUser', :typeKey => "#{args[:mmsg][:fqndata][:o][:from][:id]}:#{args[:mmsg][:fqn].map{|k,v| "#{v}"}.join('_') }"} end
defHeaderPerChat(args)
click to toggle source
# File lib/statistics/func.rb, line 44 def defHeaderPerChat(args) return {:type => 'perChat', :typeKey => "#{args[:mmsg][:fqndata][:o][:chat][:id]}"} end
defHeaderPerUser(args)
click to toggle source
# File lib/statistics/func.rb, line 31 def defHeaderPerUser(args) return {:type => 'perUser', :typeKey => "#{args[:mmsg][:fqndata][:o][:from][:id]}:#{args[:mmsg][:fqndata][:o][:chat][:id]}"} end
defHeaderUserOverall(args)
click to toggle source
# File lib/statistics/func.rb, line 18 def defHeaderUserOverall(args) return {:type => 'UserOverall', :typeKey => args[:mmsg][:fqndata][:o][:from][:id]} end
general(args)
click to toggle source
# File lib/statistics/general.rb, line 18 def general(args) msgLast = {:key => 'msgLast', :value => args[:mmsg][:fqndata][:o][:msg][:date]} msgCount = {:key => 'msgCountOverall', :redisOp => 'inc'} ##UserOverall pushStatUserOverall(args, msgLast) pushStatUserOverall(args, msgCount) ##PerUser pushStatPerUser(args, msgLast) pushStatPerUser(args, msgCount) ##PerChat pushStatPerChat(args, msgLast) pushStatPerChat(args, msgCount) ##PerFQN pushStatFQNPerUser(args, msgLast) pushStatFQNPerUser(args, msgCount) end
pushStatFQNPerUser(args, push)
click to toggle source
# File lib/statistics/func.rb, line 62 def pushStatFQNPerUser(args, push) run = defHeaderFQNPerUser(args) run[:key] = push[:key] run[:value] = push[:value] if push.has_key?(:value) run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp) Dialog::Storage::Redis.pushStat(run) end
pushStatPerChat(args, push)
click to toggle source
# File lib/statistics/func.rb, line 48 def pushStatPerChat(args, push) run = defHeaderPerChat(args) run[:key] = push[:key] run[:value] = push[:value] if push.has_key?(:value) run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp) Dialog::Storage::Redis.pushStat(run) end
pushStatPerUser(args, push)
click to toggle source
# File lib/statistics/func.rb, line 35 def pushStatPerUser(args, push) run = defHeaderPerUser(args) run[:key] = push[:key] run[:value] = push[:value] if push.has_key?(:value) run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp) Dialog::Storage::Redis.pushStat(run) end
pushStatUserOverall(args, push)
click to toggle source
# File lib/statistics/func.rb, line 22 def pushStatUserOverall(args, push) run = defHeaderUserOverall(args) run[:key] = push[:key] run[:value] = push[:value] if push.has_key?(:value) run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp) Dialog::Storage::Redis.pushStat(run) end
redisDump2json()
click to toggle source
# File lib/statistics/redisDump.rb, line 17 def redisDump2json require 'redis/dump' require 'json' stat = {} redisDump = Redis::Dump.new 2, 'redis://localhost:4000' dump = redisDump.dump dump.each do |list| src = JSON.parse(list) preKey = src["key"].split(':') keyHead = preKey[0].to_sym stat[keyHead] ||= {} keySecond = preKey[1].to_sym stat[keyHead][keySecond] ||= {} preKey[2] ? keyType = preKey[2].to_sym : keyType = :main stat[keyHead][keySecond][keyType] ||= {} src["value"].each do |data| stat[keyHead][keySecond][keyType][data[0][1..-1].to_sym] = data[1].to_i end end json = JSON.generate(stat) return json end