Sha256: 75ab3a12f3f5110502c570df9c1568c782c223a4c893e4f65aa04a0bf9fa5b36

Contents?: true

Size: 1.47 KB

Versions: 28

Compression:

Stored size: 1.47 KB

Contents

module Bmg
  module Operator
    #
    # Summarize operator.
    #
    # Makes a summarization by some attributes, applying aggregations
    # to the corresponding images.
    #
    class Summarize
      include Operator::Unary

      def initialize(type, operand, by, summarization)
        @type = type
        @operand = operand
        @by = by
        @summarization = Summarizer.summarization(summarization)
      end

    protected

      attr_reader :by, :summarization

    public

      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

      def to_ast
        [ :summarize, operand.to_ast, by, summarization ]
      end

    protected ### inspect

      def args
        [ by, summarization ]
      end

    end # class Summarize
  end # module Operator
end # module Bmg

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
bmg-0.23.0 lib/bmg/operator/summarize.rb
bmg-0.21.5 lib/bmg/operator/summarize.rb
bmg-0.21.4 lib/bmg/operator/summarize.rb
bmg-0.20.5 lib/bmg/operator/summarize.rb
bmg-0.19.3 lib/bmg/operator/summarize.rb
bmg-0.21.3 lib/bmg/operator/summarize.rb
bmg-0.21.2 lib/bmg/operator/summarize.rb
bmg-0.21.0 lib/bmg/operator/summarize.rb
bmg-0.20.4 lib/bmg/operator/summarize.rb
bmg-0.20.2 lib/bmg/operator/summarize.rb
bmg-0.20.1 lib/bmg/operator/summarize.rb
bmg-0.20.0 lib/bmg/operator/summarize.rb
bmg-0.19.2 lib/bmg/operator/summarize.rb
bmg-0.19.1 lib/bmg/operator/summarize.rb
bmg-0.19.0 lib/bmg/operator/summarize.rb
bmg-0.18.15 lib/bmg/operator/summarize.rb
bmg-0.18.14 lib/bmg/operator/summarize.rb
bmg-0.18.13 lib/bmg/operator/summarize.rb
bmg-0.18.12 lib/bmg/operator/summarize.rb
bmg-0.18.11 lib/bmg/operator/summarize.rb