Module: Cubicle::Aggregation::Dsl
- Included in:
- Cubicle::Aggregation
- Defined in:
- lib/cubicle/aggregation/dsl.rb
Instance Method Summary collapse
- #aggregation(*member_list) ⇒ Object
- #average(*args) ⇒ Object (also: #avg)
- #average_duration(*args) ⇒ Object (also: #avg_duration)
- #bucketize(dimension_name, source_measure_name, bucket_range, options = {}, &block) ⇒ Object (also: #categorize)
- #count(*args) ⇒ Object
- #define(name, expression) ⇒ Object
- #difference(member_name, left, right) ⇒ Object
- #dimension(*args) ⇒ Object
- #dimensions(*args) ⇒ Object
- #duration(*args) ⇒ Object
- #duration_since(*args) ⇒ Object (also: #age_since, #elapsed)
- #durations_in(unit_of_time = nil) ⇒ Object (also: #duration_unit)
- #expand(*args) ⇒ Object
- #expansions ⇒ Object
- #filter(query = nil) ⇒ Object
- #measure(*args) ⇒ Object
- #measures(*args) ⇒ Object
- #named_expressions ⇒ Object
- #ratio(member_name, numerator, denominator) ⇒ Object
- #source_collection_name(collection_name = nil, query = {}) ⇒ Object (also: #source_collection_name=, #source_collection)
- #sum(*args) ⇒ Object
- #target_collection_name(collection_name = nil) ⇒ Object (also: #target_collection_name=)
- #time_dimension(*args) ⇒ Object (also: #time_dimension=, #date, #time)
- #total_duration(*args) ⇒ Object
Instance Method Details
#aggregation(*member_list) ⇒ Object
133 134 135 136 |
# File 'lib/cubicle/aggregation/dsl.rb', line 133 def aggregation(*member_list) member_list = member_list[0] if member_list[0].is_a?(Array) aggregations << member_list end |
#average(*args) ⇒ Object Also known as: avg
67 68 69 70 71 72 73 74 |
# File 'lib/cubicle/aggregation/dsl.rb', line 67 def average(*args) = args. [:aggregation_method] = :average measure(*(args << )) #Averaged fields need a count of non-null values to properly calculate the average args[0] = "#{args[0]}_count".to_sym count *args end |
#average_duration(*args) ⇒ Object Also known as: avg_duration
91 92 93 |
# File 'lib/cubicle/aggregation/dsl.rb', line 91 def average_duration(*args) duration(*args) end |
#bucketize(dimension_name, source_measure_name, bucket_range, options = {}, &block) ⇒ Object Also known as: categorize
126 127 128 129 130 |
# File 'lib/cubicle/aggregation/dsl.rb', line 126 def bucketize(dimension_name, source_measure_name, bucket_range, ={}, &block) source_measure = measures[source_measure_name] raise "#{source_measure_name} does not appear to be a valid measure name. bucketize/categorize declarations must be placed AFTER any measures it uses have been defined." unless source_measure dimensions << BucketizedDimension.new(dimension_name, source_measure, bucket_range, , &block) end |
#count(*args) ⇒ Object
61 62 63 64 65 |
# File 'lib/cubicle/aggregation/dsl.rb', line 61 def count(*args) = args. [:aggregation_method] = :count measure(*(args << )) end |
#define(name, expression) ⇒ Object
146 147 148 |
# File 'lib/cubicle/aggregation/dsl.rb', line 146 def define(name,expression) named_expressions[name] = expression end |
#difference(member_name, left, right) ⇒ Object
122 123 124 |
# File 'lib/cubicle/aggregation/dsl.rb', line 122 def difference(member_name, left, right) measures << Difference.new(member_name,left,right) end |
#dimension(*args) ⇒ Object
25 26 27 28 |
# File 'lib/cubicle/aggregation/dsl.rb', line 25 def dimension(*args) dimensions << Cubicle::Dimension.new(*args) dimensions[-1] end |
#dimensions(*args) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/cubicle/aggregation/dsl.rb', line 42 def dimensions(*args) return (@dimensions ||= Cubicle::MemberList.new) if args.length < 1 args = args[0] if args.length == 1 && args[0].is_a?(Array) args.each {|dim| dimension dim } @dimensions end |
#duration(*args) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/cubicle/aggregation/dsl.rb', line 83 def duration(*args) = args. [:in] ||= durations_in args << measures << (dur = Duration.new(*args)) count("#{dur.name}_count".to_sym, :expression=>dur.expression, :condition=>dur.condition) if dur.aggregation_method == :average end |
#duration_since(*args) ⇒ Object Also known as: age_since, elapsed
102 103 104 105 106 107 |
# File 'lib/cubicle/aggregation/dsl.rb', line 102 def duration_since(*args) = args. ms1 = args.length > 1 ? args.delete_at(1) : args.shift [ms1] = :now duration(*(args<<)) end |
#durations_in(unit_of_time = nil) ⇒ Object Also known as: duration_unit
111 112 113 114 |
# File 'lib/cubicle/aggregation/dsl.rb', line 111 def durations_in(unit_of_time = nil) return (@duration_unit ||= :seconds) unless unit_of_time @duration_unit = unit_of_time.to_s.pluralize.to_sym end |
#expand(*args) ⇒ Object
30 31 32 |
# File 'lib/cubicle/aggregation/dsl.rb', line 30 def (*args) expansions << Cubicle::Expansion.new(*args) end |
#expansions ⇒ Object
34 35 36 |
# File 'lib/cubicle/aggregation/dsl.rb', line 34 def expansions return @expansions ||= [] end |
#filter(query = nil) ⇒ Object
20 21 22 23 |
# File 'lib/cubicle/aggregation/dsl.rb', line 20 def filter(query=nil) return (@query ||= nil) unless query @query = query end |
#measure(*args) ⇒ Object
49 50 51 52 |
# File 'lib/cubicle/aggregation/dsl.rb', line 49 def measure(*args) measures << Measure.new(*args) measures[-1] end |
#measures(*args) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/cubicle/aggregation/dsl.rb', line 54 def measures(*args) return (@measures ||= Cubicle::MemberList.new) if args.length < 1 args = args[0] if args.length == 1 && args[0].is_a?(Array) args.each {|m| measure m} @measures end |
#named_expressions ⇒ Object
38 39 40 |
# File 'lib/cubicle/aggregation/dsl.rb', line 38 def named_expressions return @named_expressions ||= OrderedHashWithIndifferentAccess.new end |
#ratio(member_name, numerator, denominator) ⇒ Object
118 119 120 |
# File 'lib/cubicle/aggregation/dsl.rb', line 118 def ratio(member_name, numerator, denominator) measures << Ratio.new(member_name, numerator, denominator) end |
#source_collection_name(collection_name = nil, query = {}) ⇒ Object Also known as: source_collection_name=, source_collection
5 6 7 8 9 |
# File 'lib/cubicle/aggregation/dsl.rb', line 5 def source_collection_name(collection_name = nil, query={}) filter query unless query.blank? return @source_collection = collection_name if collection_name @source_collection ||= name.chomp("Cubicle").chomp("Cube").chomp("Aggregation").underscore.pluralize end |
#sum(*args) ⇒ Object
77 78 79 80 81 |
# File 'lib/cubicle/aggregation/dsl.rb', line 77 def sum(*args) = args. [:aggregation_method] = :sum measure(*(args << )) end |
#target_collection_name(collection_name = nil) ⇒ Object Also known as: target_collection_name=
13 14 15 16 17 |
# File 'lib/cubicle/aggregation/dsl.rb', line 13 def target_collection_name(collection_name = nil) return nil if transient? return @target_name = collection_name if collection_name @target_name ||= "cubicle.fact.#{name.blank? ? source_collection_name : name.underscore}" end |
#time_dimension(*args) ⇒ Object Also known as: time_dimension=, date, time
138 139 140 141 |
# File 'lib/cubicle/aggregation/dsl.rb', line 138 def time_dimension(*args) return (@time_dimension ||= nil) unless args.length > 0 @time_dimension = dimension(*args) end |
#total_duration(*args) ⇒ Object
96 97 98 99 100 |
# File 'lib/cubicle/aggregation/dsl.rb', line 96 def total_duration(*args) = args. [:aggregation_method] = :sum duration(*(args<<)) end |