Class: Shades::AggEvent
- Inherits:
-
Object
- Object
- Shades::AggEvent
- Defined in:
- lib/shades/cube.rb
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
Instance Method Summary collapse
- #add(event) ⇒ Object
- #dimension(d) ⇒ Object
- #dimension_map ⇒ Object
- #dimensions ⇒ Object
-
#initialize(query, event) ⇒ AggEvent
constructor
A new instance of AggEvent.
- #key ⇒ Object
- #line ⇒ Object
- #measure(m) ⇒ Object
- #measure_map ⇒ Object
- #measures ⇒ Object
- #to_map ⇒ Object
Constructor Details
#initialize(query, event) ⇒ AggEvent
Returns a new instance of AggEvent.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/shades/cube.rb', line 175 def initialize(query, event) @query = query @key = event.key @dvalues = {} @dlist = [] event.dimensions.each do |k| @dvalues[k] = event.dimension(k) @dlist.push(k) end @rollup_info_by_measure = {} @stats_by_measure = {} @mlist = [] @query.rollup_list.each do |r| @mlist.push(r.outbound_measure) outbound_measure = r.outbound_measure @rollup_info_by_measure[outbound_measure] = r initial_value = r.get_value(event) stat = r.stat.call stat.add(initial_value) @stats_by_measure[outbound_measure] = stat end @metadata = Metadata.new(@dlist, @mlist) end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
173 174 175 |
# File 'lib/shades/cube.rb', line 173 def @metadata end |
Instance Method Details
#add(event) ⇒ Object
223 224 225 226 227 228 |
# File 'lib/shades/cube.rb', line 223 def add(event) measures.each do |k| value = @rollup_info_by_measure[k].get_value(event) @stats_by_measure[k].add(value) end end |
#dimension(d) ⇒ Object
207 208 209 |
# File 'lib/shades/cube.rb', line 207 def dimension(d) @dvalues[d] end |
#dimension_map ⇒ Object
237 238 239 |
# File 'lib/shades/cube.rb', line 237 def dimension_map @dvalues end |
#dimensions ⇒ Object
203 204 205 |
# File 'lib/shades/cube.rb', line 203 def dimensions @dlist end |
#key ⇒ Object
199 200 201 |
# File 'lib/shades/cube.rb', line 199 def key @key end |
#line ⇒ Object
230 231 232 233 234 235 |
# File 'lib/shades/cube.rb', line 230 def line f = [] f << dimensions.map { |k| '%s' % dimension(k) } f << measures.map { |k| '%.5f' % measure(k) } f.join("\t") end |
#measure(m) ⇒ Object
211 212 213 214 215 216 217 |
# File 'lib/shades/cube.rb', line 211 def measure(m) if @stats_by_measure.has_key?(m) @stats_by_measure[m].get_value else 0.0 end end |
#measure_map ⇒ Object
241 242 243 244 245 246 247 |
# File 'lib/shades/cube.rb', line 241 def measure_map mm = {} measures.each do |k, v| mm[k] = measure(k) end mm end |
#measures ⇒ Object
219 220 221 |
# File 'lib/shades/cube.rb', line 219 def measures @mlist end |
#to_map ⇒ Object
249 250 251 252 253 254 |
# File 'lib/shades/cube.rb', line 249 def to_map { :dimensions => @dvalues, :measures => measure_map } end |