Module: Batsd::Dash::ParamsHelper

Defined in:
lib/batsd-dash/params.rb

Instance Method Summary collapse

Instance Method Details

#parse_statisticsHash

Parse params and return stats hash

Returns:

  • (Hash)

    stats hash



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/batsd-dash/params.rb', line 8

def parse_statistics
  Hash.new { |hash,key| hash[key] = [] }.tap do |stats|
    %w[ counters gauges timers ].each do |datatype|
      list = params[datatype]

      list = [list] unless Array === list
      list.reject! { |m| m.nil? || m.empty? }

      stats[datatype] = list unless list.empty?
    end
  end
end

#parse_time_rangeArray

Parse time range from params

Returns:

  • (Array)

    an array with 2 elements (start and stop)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/batsd-dash/params.rb', line 25

def parse_time_range
  start, stop = params[:start], params[:stop]

  if start.nil? && stop.nil?
    now = Time.now.to_i

    # 1 hr range
    # TODO make this setting?
    [ now - 1800, now ]

  else
    [start.to_i, stop.to_i].tap do |range|
      if range[0] <= 0 || range[1] <= 0 || range[0] >= range[1]
        return nil
      end
    end
  end
end