Class: Mouth::Graph

Inherits:
Record show all
Defined in:
lib/mouth/graph.rb

Overview

{

:dashboard_id => BSON::ObjectId,
:position => {
  :top => 0,
  :left => 0,
  :height => 7,
  :width => 20
},
:kind => 'counter' || 'timer' || 'gauge',
:sources => ["auth.authentications"]

}

Instance Attribute Summary

Attributes inherited from Record

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

all, #all_attributes, collection, create, #destroy, find, #initialize, #normalize_attributes, #update

Constructor Details

This class inherits a constructor from Mouth::Record

Class Method Details

.for_dashboard(dashboard_id) ⇒ Object



54
55
56
# File 'lib/mouth/graph.rb', line 54

def self.for_dashboard(dashboard_id)
  collection.find({:dashboard_id => BSON::ObjectId(dashboard_id.to_s)}).to_a.collect {|g| new(g) }
end

Instance Method Details

#bson_object_id_ize(*args) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mouth/graph.rb', line 42

def bson_object_id_ize(*args)
  orig_attrs = self.attributes.dup
  args.each do |a|
    self.attributes[a] = BSON::ObjectId(self.attributes[a])
  end
  res = yield
  orig_attrs[:id] = self.attributes[:id]
  self.attributes = orig_attrs
  
  res
end

#data(opts = {}) ⇒ Object

Options:

- :start_time (Time object)
- :end_time (Time object)
- :granularity_in_minutes


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mouth/graph.rb', line 27

def data(opts = {})
  sources = self.attributes[:sources] || []
  seq_opts = {:kind => self.attributes[:kind].to_sym}.merge(opts)
  sequence = SequenceQuery.new(sources, seq_opts)
  seqs = sequence.sequences
  seqs.map do |seq|
    {
      :data => seq[1],
      :start_time => sequence.start_time_epoch,
      :source => seq[0]
    }
  end
end

#saveObject



17
18
19
20
21
# File 'lib/mouth/graph.rb', line 17

def save
  bson_object_id_ize(:dashboard_id) do
    super
  end
end