cubicle 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/CHANGELOG.rdoc +14 -0
  2. data/README.rdoc +188 -174
  3. data/cubicle.gemspec +26 -10
  4. data/lib/cubicle.rb +47 -422
  5. data/lib/cubicle/aggregation.rb +58 -7
  6. data/lib/cubicle/aggregation/ad_hoc.rb +12 -0
  7. data/lib/cubicle/aggregation/aggregation_manager.rb +212 -0
  8. data/lib/cubicle/aggregation/dsl.rb +108 -0
  9. data/lib/cubicle/aggregation/map_reduce_helper.rb +55 -0
  10. data/lib/cubicle/data.rb +29 -84
  11. data/lib/cubicle/data/hierarchy.rb +55 -0
  12. data/lib/cubicle/data/level.rb +62 -0
  13. data/lib/cubicle/data/member.rb +28 -0
  14. data/lib/cubicle/data/table.rb +56 -0
  15. data/lib/cubicle/measure.rb +30 -20
  16. data/lib/cubicle/mongo_mapper/aggregate_plugin.rb +1 -1
  17. data/lib/cubicle/ordered_hash_with_indifferent_access.rb +27 -0
  18. data/lib/cubicle/query.rb +21 -194
  19. data/lib/cubicle/query/dsl.rb +118 -0
  20. data/lib/cubicle/query/dsl/time_intelligence.rb +89 -0
  21. data/lib/cubicle/ratio.rb +28 -12
  22. data/lib/cubicle/version.rb +2 -2
  23. data/test/cubicle/aggregation/ad_hoc_test.rb +21 -0
  24. data/test/cubicle/cubicle_aggregation_test.rb +84 -20
  25. data/test/cubicle/cubicle_query_test.rb +36 -0
  26. data/test/cubicle/data/data_test.rb +30 -0
  27. data/test/cubicle/data/level_test.rb +42 -0
  28. data/test/cubicle/data/member_test.rb +40 -0
  29. data/test/cubicle/{cubicle_data_test.rb → data/table_test.rb} +50 -50
  30. data/test/cubicle/duration_test.rb +46 -48
  31. data/test/cubicle/ordered_hash_with_indifferent_access_test.rb +19 -0
  32. data/test/cubicles/defect_cubicle.rb +31 -31
  33. data/test/log/test.log +102066 -0
  34. metadata +26 -10
  35. data/lib/cubicle/data_level.rb +0 -60
  36. data/test/cubicle/cubicle_data_level_test.rb +0 -58
  37. data/test/cubicle/cubicle_test.rb +0 -85
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 3
9
+ version: 0.1.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Nathan Stults
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-20 00:00:00 -07:00
17
+ date: 2010-03-25 00:00:00 -07:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -76,9 +76,16 @@ files:
76
76
  - cubicle.log
77
77
  - lib/cubicle.rb
78
78
  - lib/cubicle/aggregation.rb
79
+ - lib/cubicle/aggregation/ad_hoc.rb
80
+ - lib/cubicle/aggregation/aggregation_manager.rb
81
+ - lib/cubicle/aggregation/dsl.rb
82
+ - lib/cubicle/aggregation/map_reduce_helper.rb
79
83
  - lib/cubicle/calculated_measure.rb
80
84
  - lib/cubicle/data.rb
81
- - lib/cubicle/data_level.rb
85
+ - lib/cubicle/data/hierarchy.rb
86
+ - lib/cubicle/data/level.rb
87
+ - lib/cubicle/data/member.rb
88
+ - lib/cubicle/data/table.rb
82
89
  - lib/cubicle/date_time.rb
83
90
  - lib/cubicle/dimension.rb
84
91
  - lib/cubicle/duration.rb
@@ -87,18 +94,24 @@ files:
87
94
  - lib/cubicle/member_list.rb
88
95
  - lib/cubicle/mongo_environment.rb
89
96
  - lib/cubicle/mongo_mapper/aggregate_plugin.rb
97
+ - lib/cubicle/ordered_hash_with_indifferent_access.rb
90
98
  - lib/cubicle/query.rb
99
+ - lib/cubicle/query/dsl.rb
100
+ - lib/cubicle/query/dsl/time_intelligence.rb
91
101
  - lib/cubicle/ratio.rb
92
102
  - lib/cubicle/support.rb
93
103
  - lib/cubicle/version.rb
94
104
  - test/config/database.yml
105
+ - test/cubicle/aggregation/ad_hoc_test.rb
95
106
  - test/cubicle/cubicle_aggregation_test.rb
96
- - test/cubicle/cubicle_data_level_test.rb
97
- - test/cubicle/cubicle_data_test.rb
98
107
  - test/cubicle/cubicle_query_test.rb
99
- - test/cubicle/cubicle_test.rb
108
+ - test/cubicle/data/data_test.rb
109
+ - test/cubicle/data/level_test.rb
110
+ - test/cubicle/data/member_test.rb
111
+ - test/cubicle/data/table_test.rb
100
112
  - test/cubicle/duration_test.rb
101
113
  - test/cubicle/mongo_mapper/aggregate_plugin_test.rb
114
+ - test/cubicle/ordered_hash_with_indifferent_access_test.rb
102
115
  - test/cubicles/defect_cubicle.rb
103
116
  - test/log/test.log
104
117
  - test/models/defect.rb
@@ -134,13 +147,16 @@ signing_key:
134
147
  specification_version: 3
135
148
  summary: Pseudo-Multi Dimensional analysis / simplified aggregation for MongoDB in Ruby (NOLAP ;))
136
149
  test_files:
150
+ - test/cubicle/aggregation/ad_hoc_test.rb
137
151
  - test/cubicle/cubicle_aggregation_test.rb
138
- - test/cubicle/cubicle_data_level_test.rb
139
- - test/cubicle/cubicle_data_test.rb
140
152
  - test/cubicle/cubicle_query_test.rb
141
- - test/cubicle/cubicle_test.rb
153
+ - test/cubicle/data/data_test.rb
154
+ - test/cubicle/data/level_test.rb
155
+ - test/cubicle/data/member_test.rb
156
+ - test/cubicle/data/table_test.rb
142
157
  - test/cubicle/duration_test.rb
143
158
  - test/cubicle/mongo_mapper/aggregate_plugin_test.rb
159
+ - test/cubicle/ordered_hash_with_indifferent_access_test.rb
144
160
  - test/cubicles/defect_cubicle.rb
145
161
  - test/models/defect.rb
146
162
  - test/test_helper.rb
@@ -1,60 +0,0 @@
1
- module Cubicle
2
- class DataLevel < OrderedHash
3
-
4
- def initialize(name = "Unknown Level", initial_data = {})
5
- @name = name
6
- merge!(initial_data.stringify_keys)
7
- end
8
-
9
- attr_reader :name
10
- attr_accessor :missing_member_default
11
-
12
- alias member_names keys
13
-
14
- def [](key)
15
- key = key.to_s
16
- self[key] = [] unless self.keys.include?(key)
17
- super(key)
18
- end
19
-
20
- def []=(key,val)
21
- super(key.to_s,val)
22
- end
23
-
24
- def include?(key)
25
- super(key.to_s)
26
- end
27
-
28
- def flatten(member_name = nil, opts={}, &block)
29
-
30
- default_val = opts[:default] || @missing_member_default || 0
31
-
32
- self.inject([]) do |output, (key, data)|
33
- data.inject(output) do |flattened, value|
34
- value.missing_member_default = default_val if value.respond_to?(:missing_member_default)
35
-
36
- if block_given?
37
- flat_val = block.arity == 1 ? (yield value) : (value.instance_eval(&block))
38
- end
39
- flat_val ||= value[member_name] if member_name && value.include?(member_name)
40
- flat_val ||= default_val
41
- flattened << flat_val
42
- end
43
- end
44
-
45
- end
46
-
47
- def leaf_level?
48
- return self.length < 1 ||
49
- !self[self.keys[0]].is_a?(Cubicle::DataLevel)
50
- end
51
-
52
- def method_missing(sym,*args,&block)
53
- return self[sym.to_s[0..-2]] = args[0] if sym.to_s =~ /.*=$/
54
- return self[sym] if self.keys.include?(sym.to_s)
55
- missing_member_default
56
- end
57
-
58
-
59
- end
60
- end
@@ -1,58 +0,0 @@
1
- require "test_helper"
2
-
3
- class CubicleDataLevelTest < ActiveSupport::TestCase
4
- context "Cubicle::CubicleDataLevel#new" do
5
- should "succeed with no arguments" do
6
- assert_nothing_raised do
7
- Cubicle::DataLevel.new
8
- end
9
- end
10
- should "Choose a default name if none is provided" do
11
- assert_equal "Unknown Level", Cubicle::DataLevel.new.name
12
- end
13
- should "Set the name using the first argument" do
14
- assert_equal :me, Cubicle::DataLevel.new(:me).name
15
- end
16
- end
17
- context "Indexing into a Cubicle::CubicleDataLevel" do
18
- should "provide indifferent access" do
19
- level = Cubicle::DataLevel.new
20
- level[:hello] = "hi"
21
- assert_equal "hi", level["hello"]
22
- level["hi"] = :hello
23
- assert_equal :hello, level[:hi]
24
- end
25
- should "Provide an empty array as a default value for missing keys" do
26
- assert_equal [], Cubicle::DataLevel.new["hello there"]
27
- l = Cubicle::DataLevel.new
28
- l[:hi] << 1 << 2 << 3
29
- assert_equal [1,2,3], l[:hi]
30
- end
31
- should "allow method missing to index into hash" do
32
- l = Cubicle::DataLevel.new
33
- l.hello = "goodbye"
34
- assert_equal "goodbye", l[:hello]
35
- assert_equal "goodbye", l.hello
36
- end
37
- end
38
- context "CubeDataLevel.leaf_level?" do
39
- should "Correctly identify a leaf level" do
40
- l = Cubicle::DataLevel.new(:happy)
41
- assert l.leaf_level?
42
- l[:a] = []
43
- assert l.leaf_level?
44
- end
45
- should "Corrently identify non-leaf level" do
46
- l = Cubicle::DataLevel.new(:happy)
47
- l[:a] = Cubicle::DataLevel.new(:sad)
48
- assert_not_equal true, l.leaf_level?
49
- end
50
- end
51
- context "CubeDataLevel.flatten" do
52
- should "Flatten using a provided member name" do
53
- l = Cubicle::DataLevel.new(:happy,{:a=>[{:a=>3,:b=>2}],:b=>[{:a=>4,:b=>1}]})
54
- assert_equal [2,1], l.flatten(:b)
55
- end
56
- end
57
-
58
- end
@@ -1,85 +0,0 @@
1
- require "test_helper"
2
-
3
- class CubicleTest < ActiveSupport::TestCase
4
-
5
- context "Given a query with several dimensions and measures" do
6
- context "Cubicle#select" do
7
- setup do
8
- Defect.create_test_data
9
- end
10
- context "without arguments" do
11
- setup do
12
- @results = DefectCubicle.query
13
- end
14
- should "return a collection of appropriate aggregated values based on the cubicle parameters" do
15
- assert_equal 4, @results.length
16
-
17
- assert_equal "2009-12-09", @results[0]["manufacture_date"]
18
- assert_equal "2009-12", @results[0]["month"]
19
- assert_equal "2009", @results[0]["year"]
20
- assert_equal "Brush Fire Bottle Rockets", @results[0]["product"]
21
- assert_equal "South", @results[0]["region"]
22
- assert_equal "Buddy", @results[0]["operator"]
23
- assert_equal "Repaired", @results[0]["outcome"]
24
- assert_equal 1, @results[0]["total_defects"]
25
- assert_equal 0, @results[0]["preventable_defects"]
26
- assert_equal 0.43, @results[0]["total_cost"]
27
- assert_equal 0.43, @results[0]["avg_cost"]
28
- assert_equal 0, @results[0]["preventable_pct"]
29
-
30
- assert_equal "2010-01-01", @results[1]["manufacture_date"]
31
- assert_equal "2010-01", @results[1]["month"]
32
- assert_equal "2010", @results[1]["year"]
33
- assert_equal "Sad Day Moonshine", @results[1]["product"]
34
- assert_equal "West", @results[1]["region"]
35
- assert_equal "Franny", @results[1]["operator"]
36
- assert_equal "Repaired", @results[1]["outcome"]
37
- assert_equal 2, @results[1]["total_defects"]
38
- assert_equal 1, @results[1]["preventable_defects"]
39
- assert_in_delta 12.97, @results[1]["total_cost"], 0.0001
40
- assert_in_delta 6.485, @results[1]["avg_cost"],0.0001
41
- assert_equal 0.5, @results[1]["preventable_pct"]
42
-
43
- assert_equal "2010-01-05", @results[2]["manufacture_date"]
44
- assert_equal "2010-01", @results[2]["month"]
45
- assert_equal "2010", @results[2]["year"]
46
- assert_equal "Evil's Pickling Spice", @results[2]["product"]
47
- assert_equal "Midwest", @results[2]["region"]
48
- assert_equal "Seymour", @results[2]["operator"]
49
- assert_equal "Discarded", @results[2]["outcome"]
50
- assert_equal 1, @results[2]["total_defects"]
51
- assert_equal 1, @results[2]["preventable_defects"]
52
- assert_equal 0.02, @results[2]["total_cost"]
53
- assert_equal 0.02, @results[2]["avg_cost"]
54
- assert_equal 1, @results[2]["preventable_pct"]
55
-
56
- assert_equal "2010-02-01", @results[3]["manufacture_date"]
57
- assert_equal "2010-02", @results[3]["month"]
58
- assert_equal "2010", @results[3]["year"]
59
- assert_equal "Sad Day Moonshine", @results[3]["product"]
60
- assert_equal "West", @results[3]["region"]
61
- assert_equal "Zooey", @results[3]["operator"]
62
- assert_equal "Consumed", @results[3]["outcome"]
63
- assert_equal 1, @results[3]["total_defects"]
64
- assert_equal 1, @results[3]["preventable_defects"]
65
- assert_equal 2.94, @results[3]["total_cost"]
66
- assert_equal 2.94, @results[3]["avg_cost"]
67
- assert_equal 1, @results[3]["preventable_pct"]
68
- end
69
- end
70
-
71
- context "Processing a cube" do
72
- setup do
73
- DefectCubicle.expire!
74
- DefectCubicle.process
75
- end
76
- should "should create the specified aggregations" do
77
- assert Cubicle.mongo.database.collection_names.include? "defect_cubicles_cubicle_aggregation_month.product.year"
78
- assert Cubicle.mongo.database.collection_names.include? "defect_cubicles_cubicle_aggregation_month.region"
79
- end
80
-
81
- end
82
- end
83
- end
84
-
85
- end