ran_a_lytics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ # .gitignore
5
+ Gemfile.lock
6
+ *.log
7
+ *.sqlite3
8
+ :dev
9
+ test*.rb
10
+ *.komodoproject
data/:dev ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ran_a_lytics.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ran_a_lytics (0.0.1)
5
+ activerecord (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activemodel (3.0.5)
11
+ activesupport (= 3.0.5)
12
+ builder (~> 2.1.2)
13
+ i18n (~> 0.4)
14
+ activerecord (3.0.5)
15
+ activemodel (= 3.0.5)
16
+ activesupport (= 3.0.5)
17
+ arel (~> 2.0.2)
18
+ tzinfo (~> 0.3.23)
19
+ activesupport (3.0.5)
20
+ arel (2.0.9)
21
+ builder (2.1.2)
22
+ database_cleaner (0.5.2)
23
+ diff-lcs (1.1.2)
24
+ i18n (0.5.0)
25
+ mysql (2.8.1)
26
+ rspec (2.5.0)
27
+ rspec-core (~> 2.5.0)
28
+ rspec-expectations (~> 2.5.0)
29
+ rspec-mocks (~> 2.5.0)
30
+ rspec-core (2.5.1)
31
+ rspec-expectations (2.5.0)
32
+ diff-lcs (~> 1.1.2)
33
+ rspec-mocks (2.5.0)
34
+ tzinfo (0.3.25)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler (>= 1.0.0)
41
+ database_cleaner (= 0.5.2)
42
+ mysql (>= 2.8.1)
43
+ ran_a_lytics!
44
+ rspec (>= 2.0.0)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,103 @@
1
+ module RanALytics
2
+ module Pivot
3
+ extend ActiveSupport::Concern
4
+ module ClassMethods
5
+ def pivotable?
6
+ true
7
+ end
8
+ def PivotTable(spec = nil)
9
+ case spec
10
+ when nil
11
+ raise "Not enough paramters specified"
12
+ when Symbol, String
13
+ spec = spec.symbolize_keys
14
+ end
15
+ #Break out the SPEC into vars
16
+ columns = spec[:columns]
17
+ rows = spec[:rows]
18
+ measures = spec[:measures]
19
+ conditions = spec[:conditions]
20
+ joins = spec[:joins]
21
+
22
+ #Clean up any SQL as stmnts
23
+ grpCols = Array.new
24
+ grpRows = Array.new
25
+ grpMeasures = Array.new
26
+ columns.each{|r| grpCols << r.sub(/.* as /,'')}
27
+ rows.each{|r| grpRows << r.sub(/.* as /,'')}
28
+ measures.each{|r| grpMeasures << r.sub(/.* as /,'')}
29
+ raw = self.find(:all, :select=> (rows + columns + measures).join(','), :joins => joins, :group=> (grpRows + grpCols).join(','),:order=>(grpRows + grpCols).join(','), :conditions=> conditions)
30
+ turnMe(raw, :rows=>grpRows, :columns=>grpCols, :measures=>grpMeasures)
31
+ end
32
+
33
+ def turnMe(rset, spec)
34
+ columns = spec[:columns]
35
+ rows = spec[:rows]
36
+ measures = spec[:measures]
37
+ exp = ''
38
+ #G are globals
39
+ gblTotals = Array.new(measures.size)
40
+ gblTotals.collect!{|m| m = 0}
41
+ #r are rows
42
+ rowTotals = gblTotals
43
+ #m are measure
44
+ msrTotals = gblTotals
45
+ measureHash = Hash.new
46
+ #c are columns
47
+ colTotals = gblTotals
48
+ columnHash = Hash.new
49
+
50
+ ucol = Array.new()
51
+ urow = Array.new()
52
+ gen_row = ""
53
+ gen_col = ""
54
+
55
+ ma = rset
56
+ ma.collect do |m|
57
+ gen_row = rows.collect{|r| "m." + r.to_s + ".delete('" + r.to_s + "')"}
58
+ gen_col = columns.collect{|c| "m." + c.to_s + ".delete('" + c.to_s + "')"}
59
+ eval("urow << [" + gen_row.join(',') + "].join('-')")
60
+ eval("ucol << [" + gen_col.join(',') + "].join('-')")
61
+ end
62
+ grd = Array.new(urow.uniq.size+1)
63
+ cur = 0
64
+ gblTotals.collect!{|c| c = 0}
65
+ urow.uniq.sort!.each do |ur|
66
+ rowTotals.collect!{|m| m = 0}
67
+ out = Hash.new()
68
+ out = {"'" + rows.join('-') + "'" => "'" + ur.to_s + "'"}
69
+ exp = "ma.select{|p| p." + rows.join('-') + "== '" + ur.to_s + "'}"
70
+ sr = eval(exp)
71
+ ucol.uniq.sort!.each do |uc|
72
+ msrTotals.collect!{|mt| mt = 0}
73
+ #sc = sr.select{|p| [p.yr,p.mth].join('-') == uc}
74
+ exp = "sr.select{|q| q." + columns.join('-') + "=='" + uc.to_s + "'}"
75
+ sc = eval(exp)
76
+ sc.each do |cCol|
77
+ msrTotals.each_index do |mt|
78
+ msrTotals[mt] += eval("cCol." + measures[mt] + ".to_f")
79
+ measureHash[measures[mt].to_s] = msrTotals[mt]
80
+ end
81
+ end
82
+ columnHash[uc.to_s] = measureHash
83
+
84
+ rowTotals.each_index{|rt| rowTotals[rt] += msrTotals[rt]}
85
+ out.merge!(columnHash)
86
+ end
87
+ gblTotals.each_index{|gt| gblTotals[gt] += rowTotals[gt]}
88
+ measureHash.each_with_index do |msrArray,mi|
89
+ measureHash[msrArray[0]] = rowTotals[mi]
90
+ end
91
+ out.merge!(measureHash)
92
+ grd[cur] = out
93
+ cur += 1
94
+ end
95
+ measureHash.each_with_index{|msrArray,mi| measureHash[msrArray[0]] = gblTotals[mi] }
96
+ grd[cur] = measureHash
97
+ endtime = Time.now()
98
+ return grd
99
+ end
100
+ end
101
+ end
102
+ end
103
+
@@ -0,0 +1,3 @@
1
+ module RanALytics
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ # -*- encoding: utf-8 -*-
4
+ $:.push File.expand_path("../lib", __FILE__)
5
+ require 'ran_a_lytics/pivot.rb'
6
+
7
+ module RanALytics
8
+
9
+ def make_pivotable
10
+ puts "This will make me pivotable"
11
+ include Pivot
12
+ end
13
+
14
+ end
15
+
16
+ ActiveRecord::Base.extend RanALytics
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ran_a_lytics/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ran_a_lytics"
7
+ s.version = RanALytics::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = "Robert Hall"
10
+ s.email = "robert.hall@itatc.com"
11
+ s.homepage = "http://github.com/golsombe/ran_a_lytics"
12
+ s.summary = "An Infobright compainion Rails extention"
13
+ s.description = "Providing analytics as a DSL to an InfobrightCE database"
14
+
15
+ s.required_rubygems_version = ">= 1.3.6"
16
+ s.rubyforge_project = "ran_a_lytics"
17
+
18
+ s.add_dependency "activerecord", ">= 3.0.0"
19
+ s.add_development_dependency "bundler", ">= 1.0.0"
20
+ s.add_development_dependency "rspec", ">= 2.0.0"
21
+ s.add_development_dependency "database_cleaner", "0.5.2"
22
+ s.add_development_dependency "mysql", ">= 2.8.1"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,29 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Komodo Project File - DO NOT EDIT -->
3
+ <project id="0ffa9187-35a3-45f2-b45e-841ffa1fe299" kpf_version="5" name="ran_a_lytics.komodoproject">
4
+ <preference-set idref="0ffa9187-35a3-45f2-b45e-841ffa1fe299">
5
+ <preference-set id="Invocations">
6
+ <preference-set id="default">
7
+ <string id="cookieparams"></string>
8
+ <string relative="path" id="cwd"></string>
9
+ <string id="documentRoot"></string>
10
+ <string id="executable-params"></string>
11
+ <string relative="path" id="filename">test.rb</string>
12
+ <string id="getparams"></string>
13
+ <string id="language">Ruby</string>
14
+ <string id="mpostparams"></string>
15
+ <string id="params"></string>
16
+ <string id="postparams"></string>
17
+ <string id="posttype">application/x-www-form-urlencoded</string>
18
+ <string id="request-method">GET</string>
19
+ <boolean id="show-dialog">1</boolean>
20
+ <boolean id="sim-cgi">0</boolean>
21
+ <boolean id="use-console">1</boolean>
22
+ <string id="userCGIEnvironment"></string>
23
+ <string id="userEnvironment"></string>
24
+ </preference-set>
25
+ </preference-set>
26
+ <string id="lastInvocation">default</string>
27
+ <string id="mappedPaths">::file://robert-hp/home/robert/rails3/ran_a_lytics/&lt;internal:lib/rubygems##file:///home/robert/.rvm/rubies/ruby-1.9.2-p136/bin</string>
28
+ </preference-set>
29
+ </project>
data/ran_a_lytics.kpf ADDED
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Komodo Project File - DO NOT EDIT -->
3
+ <project id="0ffa9187-35a3-45f2-b45e-841ffa1fe299" kpf_version="4" name="ran_a_lytics.kpf">
4
+ <preference-set idref="0ffa9187-35a3-45f2-b45e-841ffa1fe299">
5
+ <boolean id="import_live">1</boolean>
6
+ </preference-set>
7
+ <preference-set idref="0ffa9187-35a3-45f2-b45e-841ffa1fe299/test.rb">
8
+ <preference-set id="Invocations">
9
+ <preference-set id="default">
10
+ <string id="cookieparams"></string>
11
+ <string id="cwd"></string>
12
+ <string id="documentRoot"></string>
13
+ <string id="executable-params"></string>
14
+ <string relative="path" id="filename">test.rb</string>
15
+ <string id="getparams"></string>
16
+ <string id="language">Ruby</string>
17
+ <string id="mpostparams"></string>
18
+ <string id="params"></string>
19
+ <string id="postparams"></string>
20
+ <string id="posttype">application/x-www-form-urlencoded</string>
21
+ <string id="request-method">GET</string>
22
+ <boolean id="show-dialog">1</boolean>
23
+ <boolean id="sim-cgi">0</boolean>
24
+ <boolean id="use-console">0</boolean>
25
+ <string id="userCGIEnvironment"></string>
26
+ <string id="userEnvironment"></string>
27
+ </preference-set>
28
+ </preference-set>
29
+ <string id="lastInvocation">default</string>
30
+ </preference-set>
31
+ </project>
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ran_a_lytics
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Robert Hall
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-04-21 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: activerecord
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 3.0.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.0.0
36
+ type: :development
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
47
+ type: :development
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: database_cleaner
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - "="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.5.2
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: mysql
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.8.1
69
+ type: :development
70
+ version_requirements: *id005
71
+ description: Providing analytics as a DSL to an InfobrightCE database
72
+ email: robert.hall@itatc.com
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - ":dev"
82
+ - Gemfile
83
+ - Gemfile.lock
84
+ - Rakefile
85
+ - lib/ran_a_lytics.rb
86
+ - lib/ran_a_lytics/pivot.rb
87
+ - lib/ran_a_lytics/version.rb
88
+ - ran_a_lytics.gemspec
89
+ - ran_a_lytics.komodoproject
90
+ - ran_a_lytics.kpf
91
+ has_rdoc: true
92
+ homepage: http://github.com/golsombe/ran_a_lytics
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options: []
97
+
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 1.3.6
112
+ requirements: []
113
+
114
+ rubyforge_project: ran_a_lytics
115
+ rubygems_version: 1.5.0
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: An Infobright compainion Rails extention
119
+ test_files: []
120
+