Module: Dialog::Statistics

Defined in:
lib/statistics/func.rb,
lib/statistics/general.rb,
lib/statistics/redisDump.rb

Class Method Summary collapse

Class Method Details

.defHeaderFQNPerUser(args) ⇒ Object



57
58
59
60
# 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) ⇒ Object



44
45
46
# File 'lib/statistics/func.rb', line 44

def defHeaderPerChat(args)
  return {:type    => 'perChat', :typeKey => "#{args[:mmsg][:fqndata][:o][:chat][:id]}"}
end

.defHeaderPerUser(args) ⇒ Object



31
32
33
# 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) ⇒ Object



18
19
20
# File 'lib/statistics/func.rb', line 18

def defHeaderUserOverall(args)
  return {:type    => 'UserOverall', :typeKey => args[:mmsg][:fqndata][:o][:from][:id]}
end

.general(args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



62
63
64
65
66
67
68
# 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) ⇒ Object



48
49
50
51
52
53
54
# 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) ⇒ Object



35
36
37
38
39
40
41
# 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) ⇒ Object



22
23
24
25
26
27
28
# 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

.redisDump2jsonObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 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