Module: CacheStache::ApplicationHelper

Defined in:
app/helpers/cache_stache/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_window_labelObject



9
10
11
# File 'app/helpers/cache_stache/application_helper.rb', line 9

def current_window_label
  WindowOptions.label_for(params[:window])
end

#sparkline_data(buckets, keyspace_name = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/cache_stache/application_helper.rb', line 13

def sparkline_data(buckets, keyspace_name = nil)
  return [] if buckets.empty?

  buckets.map do |bucket|
    stats = bucket[:stats]
    if keyspace_name
      hits = stats["#{keyspace_name}:hits"].to_f
      misses = stats["#{keyspace_name}:misses"].to_f
    else
      hits = stats["overall:hits"].to_f
      misses = stats["overall:misses"].to_f
    end

    total = hits + misses
    hit_rate = total.positive? ? (hits / total * 100).round(2) : 0.0

    {
      time: Time.at(bucket[:timestamp]).utc.iso8601,
      hit_rate: hit_rate,
      operations: total.round
    }
  end
end

#window_optionsObject



5
6
7
# File 'app/helpers/cache_stache/application_helper.rb', line 5

def window_options
  WindowOptions.for_select
end