mochigome 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/lib/formatting.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Mochigome
2
+ module Formatting
3
+ def self.percentify(n, d)
4
+ ("%.1f%%" % ((n.to_f*100)/d.to_f)) if (!d.nil? && d > 0)
5
+ end
6
+ end
7
+ end
data/lib/mochigome.rb CHANGED
@@ -3,6 +3,7 @@ require 'exceptions'
3
3
  require 'data_node'
4
4
  require 'query'
5
5
  require 'model_extensions'
6
+ require 'formatting'
6
7
  require 'arel_rails2_hacks'
7
8
 
8
9
  ActiveRecord::Base.send(:include, Mochigome::ModelExtensions)
data/lib/mochigome_ver.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mochigome
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -291,7 +291,7 @@ module Mochigome
291
291
  end
292
292
 
293
293
  if vals.size == 1
294
- vals << :id # TODO : Use real primary key
294
+ vals << :id # TODO : Use real primary key, only do this for appropriate agg funcs
295
295
  elsif vals.size != 2
296
296
  raise ModelSetupError.new "Wrong # of components for agg: #{obj.inspect}"
297
297
  end
data/lib/query.rb CHANGED
@@ -51,16 +51,15 @@ module Mochigome
51
51
  break
52
52
  else
53
53
  # Route it from the closest layer model
54
- @layers_path.each_with_index do |layer, i|
55
- p = self.class.path_thru([layer, link_model]) + remainder.drop(1)
54
+ @layers_path.reverse.each do |layer|
55
+ p = self.class.path_thru([layer, link_model]) + remainder.drop(1) # TODO: Handle path_thru returning nil
56
56
  next if (p.drop(1) & @layers_path).size > 0
57
57
  next if p.uniq.size != p.size
58
- if agg_path.nil? || p.size <= agg_path.size
58
+ if agg_path.nil? || p.size < agg_path.size
59
59
  agg_path = p
60
- key_path = @layers_path.take(i+1)
60
+ key_path = @layers_path
61
61
  end
62
62
  end
63
- break if agg_path # Use as much of f2d_path as we can
64
63
  end
65
64
  end
66
65
 
@@ -72,7 +71,7 @@ module Mochigome
72
71
  agg_data_rel = access_filtered_relation(agg_data_rel, @layers_path + agg_path)
73
72
  data_tbl = Arel::Table.new(data_model.table_name)
74
73
  agg_fields = data_model.mochigome_aggregation_settings.options[:fields].reject{|a| a[:in_ruby]}
75
- agg_data_rel.project
74
+ agg_data_rel.project # FIXME ??? What is this for?
76
75
  agg_fields.each_with_index do |a, i|
77
76
  agg_data_rel.project(a[:value_proc].call(data_tbl).as("d#{i}"))
78
77
  end
@@ -86,6 +85,8 @@ module Mochigome
86
85
  end
87
86
  d_rel.where(cond) if cond
88
87
 
88
+ # FIXME: This subtable won't be necessary for all forms of aggregation.
89
+ # When we can avoid it, we should, because query performance is greatly increased.
89
90
  a_rel = Arel::SelectManager.new(
90
91
  Arel::Table.engine,
91
92
  Arel.sql("(#{d_rel.to_sql}) as mochigome_data")
@@ -239,9 +239,6 @@ describe Mochigome::Query do
239
239
  assert_equal 24, data_node['Sales count']
240
240
  end
241
241
 
242
- # TODO: Include test here against the bug I saw in JSAS where
243
- # it would avoid including the focus if there was a shorter path.
244
-
245
242
  it "does not collect aggregate data for layers below focus" do
246
243
  q = Mochigome::Query.new(
247
244
  [Owner, Store, Product, Category],
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mochigome
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Mike Simon
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-11 00:00:00 Z
18
+ date: 2012-03-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement
@@ -93,6 +93,7 @@ files:
93
93
  - lib/arel_rails2_hacks.rb
94
94
  - lib/data_node.rb
95
95
  - lib/exceptions.rb
96
+ - lib/formatting.rb
96
97
  - lib/mochigome.rb
97
98
  - lib/mochigome_ver.rb
98
99
  - lib/model_extensions.rb