Class: Bmg::Operator::Summarize
- Inherits:
-
Object
- Object
- Bmg::Operator::Summarize
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/summarize.rb
Overview
Summarize operator.
Makes a summarization by some attributes, applying aggregations to the corresponding images.
Instance Attribute Summary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, operand, by, summarization) ⇒ Summarize
constructor
A new instance of Summarize.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap
Methods included from Algebra::Shortcuts
#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where
Constructor Details
#initialize(type, operand, by, summarization) ⇒ Summarize
Returns a new instance of Summarize.
12 13 14 15 16 17 |
# File 'lib/bmg/operator/summarize.rb', line 12 def initialize(type, operand, by, summarization) @type = type @operand = operand @by = by @summarization = Summarizer.summarization(summarization) end |
Instance Method Details
#each ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bmg/operator/summarize.rb', line 45 def each return to_enum unless block_given? # summary key => summarization memo, starting with least result = Hash.new{|h,k| h[k] = Hash[@summarization.map{|k,v| [ k, v.least ] }] } # iterate each tuple @operand.each do |tuple| key = TupleAlgebra.project(tuple, @by) # apply them all and create a new memo result[key] = Hash[@summarization.map{|k,v| [ k, v.happens(result[key][k], tuple) ] }] end # Merge result keys and values result.each_pair do |by,sums| tuple = Hash[@summarization.map{|k,v| [ k, v.finalize(sums[k]) ] }].merge(by) yield(tuple) end end |
#to_ast ⇒ Object
70 71 72 |
# File 'lib/bmg/operator/summarize.rb', line 70 def to_ast [ :summarize, operand.to_ast, by, summarization ] end |