Class: KRL_CMD::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/stats.rb

Class Method Summary collapse

Class Method Details

.account_kpis(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/stats.rb', line 34

def self.(options)
  user = KRL_CMD::User.new
  begin
    data = user.kpis([], options["range"])
    display_stats(data, %w(RULESET DAY RSE BRSE CALLBACKS RULES RULES_FIRED ACTIONS), options["format"]) 
  rescue => e
    ap e.message if $DEBUG
    ap e.backtrace if $DEBUG
    raise e.message
  end 
end

.interfaceObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stats.rb', line 4

def self.interface
  user = KRL_CMD::User.new
  begin
    p_interface = user.stats_interface
    puts "-- Dimensions --"
    p_interface["dims"].each {|s| puts "\t" + s}
    puts
    puts "-- KPIS --"
    p_interface["kpis"].each {|s| puts "\t" + s}
    puts
    puts "-- Ranges --"
    p_interface["ranges"].each {|s| puts "\t" + s}
  rescue 
    raise "There was an error trying to retrieve the stats interface"
  end
end

.kpis(options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/stats.rb', line 21

def self.kpis(options)
  app = KRL_COMMON::get_app
  begin
    data = app.kpis(options["range"])
    display_stats(data, %w(DAY RSE BRSE CALLBACKS RULES RULES_FIRED ACTIONS), options["format"]) 
  rescue => e
    ap e.message if $DEBUG
    ap e.backtrace if $DEBUG
    raise e.message
  end
  
end

.logging(options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stats.rb', line 46

def self.logging(options)
  app = KRL_COMMON::get_app
  begin
    data = app.logging(options["range"])
    display_stats(data, [], "json")
  rescue => e
    ap e.message if $DEBUG
    ap e.backtrace if $DEBUG
    raise e.message
  end 
end

.query(options) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/stats.rb', line 58

def self.query(options)
  user = KRL_CMD::User.new
  if options["conditions"]
    conditions = []
    options["conditions"].each {|k,v| conditions << {:field => k, :value => v}}
  else
    conditions = nil
  end
  begin
    data = user.api.get_stats_query(
      options["kpis"].join(","),
      options["dims"].join(","),
      conditions,
      options["range"]
    )
    fields = []
    (options["dims"] + options["kpis"]).each {|v| fields << v.upcase}
    display_stats(data, fields, options["format"])

  rescue => e
    ap e.message   #if $DEBUG
    ap e.backtrace #if $DEBUG
    raise "Unable to retrieve query results. #{e.message}"
  end 
end