ran_a_lytics 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +42 -22
- data/lib/ran_a_lytics/version.rb +1 -1
- data/ran_a_lytics.gemspec +1 -1
- metadata +5 -45
data/README
CHANGED
@@ -4,30 +4,50 @@ Quickstart
|
|
4
4
|
1) Follow the instructins on setting up an Infobright MySQL instance
|
5
5
|
2) Grab the sample database from http://bit.ly/gBQnaD
|
6
6
|
|
7
|
-
# -*- encoding: utf-8 -*-
|
8
|
-
$:.push File.expand_path("../lib", __FILE__)
|
9
|
-
require 'rubygems'
|
10
|
-
require 'ran_a_lytics'
|
11
|
-
require 'active_record'
|
12
|
-
require 'time'
|
13
|
-
puts "Gathering data"
|
7
|
+
# -*- encoding: utf-8 -*-
|
8
|
+
$:.push File.expand_path("../lib", __FILE__)
|
9
|
+
require 'rubygems'
|
10
|
+
require 'ran_a_lytics'
|
11
|
+
require 'active_record'
|
12
|
+
require 'time'
|
13
|
+
puts "Gathering data"
|
14
14
|
#Connect to a database
|
15
|
-
ActiveRecord::Base.establish_connection(
|
15
|
+
ActiveRecord::Base.establish_connection(
|
16
16
|
:adapter => "mysql",
|
17
|
-
:host => "localhost",
|
18
|
-
:username => "root",
|
17
|
+
:host => "localhost",
|
18
|
+
:username => "root",
|
19
19
|
:password => "",”
|
20
|
-
:database => "carsales",
|
21
|
-
:socket => "/tmp/mysql-ib.sock"
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
:database => "carsales",
|
21
|
+
:socket => "/tmp/mysql-ib.sock"
|
22
|
+
)
|
23
|
+
|
24
|
+
|
25
|
+
#Define the model
|
26
|
+
class FactSalesWide < ActiveRecord::Basero
|
27
|
+
set_table_name "fact_sales_wide"
|
25
28
|
make_pivotable
|
26
|
-
end
|
27
|
-
|
29
|
+
end
|
30
|
+
|
28
31
|
#Pivot a query for 10,000 rows into car_make rows, by transaction types columns for two measures
|
29
|
-
starttime = Time.now
|
30
|
-
ma = FactSalesWide.PivotTable(:columns=> ['dlr_trans_type as Transaction'],:rows=>['dim_cars.make_name as make'],:measures=>['sum(sales_commission) as sum_sales_commission', 'sum(sales_discount) as sum_sales_discount'], :joins => ['JOIN dim_cars ON fact_sales_wide.make_id = dim_cars.make_id'])
|
31
|
-
endtime = Time.now
|
32
|
-
puts ma.to_json
|
33
|
-
|
32
|
+
starttime = Time.now
|
33
|
+
ma = FactSalesWide.PivotTable(:columns=> ['dlr_trans_type as Transaction'],:rows=>['dim_cars.make_name as make'],:measures=>['sum(sales_commission) as sum_sales_commission', 'sum(sales_discount) as sum_sales_discount'], :joins => ['JOIN dim_cars ON fact_sales_wide.make_id = dim_cars.make_id'])
|
34
|
+
endtime = Time.now
|
35
|
+
puts ma.to_json
|
36
|
+
|
37
|
+
Details
|
38
|
+
|
39
|
+
Model
|
40
|
+
make_pivotable
|
41
|
+
end
|
42
|
+
|
43
|
+
Controller
|
44
|
+
def pivot_me
|
45
|
+
rows = ['sql_field_or_exp as alias','...'] # Get combined as row_fld1-row_fld2-...
|
46
|
+
columns = ['sql_field_or_exp as alias','...'] #Get converted into unique col1_value1-col2_value1-...
|
47
|
+
measures = ['aggregate_fn(field(s)) as alias','...'] #Indivual measure totals by pivot columsn,rows, gtotl
|
48
|
+
|
49
|
+
pvt_ary = Model_singualr.PivotTable(:rows=>rows, :columns=>columns,:measures=>measures, :conditions=>[sql_exp(s),...], :joins=>['join dim on fact.fk_dim = dim.id']
|
50
|
+
puts pvt_ary.to_json #Displays an array of hashes
|
51
|
+
#[row_alias=>'value', :col_alias1=>{measure1_alias=>value,measure2_alias=>value,...}, :col[2-N]..., {measure1_alias=>value,measure2_alias=>value,...} as row_totals]
|
52
|
+
#[{measure1_alias=>value,measure2_alias=>value,...} as grand_totals]
|
53
|
+
end
|
data/lib/ran_a_lytics/version.rb
CHANGED
data/ran_a_lytics.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = "Robert Hall"
|
10
10
|
s.email = "robert.hall@itatc.com"
|
11
|
-
s.homepage = "http://github.com/golsombe/
|
11
|
+
s.homepage = "http://github.com/golsombe/Ran-a-lytics"
|
12
12
|
s.summary = "An Infobright compainion Rails extention"
|
13
13
|
s.description = "Providing analytics as a DSL to an InfobrightCE database"
|
14
14
|
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ran_a_lytics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.3
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Robert Hall
|
@@ -15,8 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-04-
|
19
|
-
default_executable:
|
13
|
+
date: 2011-04-22 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
16
|
name: activerecord
|
@@ -26,11 +20,6 @@ dependencies:
|
|
26
20
|
requirements:
|
27
21
|
- - ">="
|
28
22
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 7
|
30
|
-
segments:
|
31
|
-
- 3
|
32
|
-
- 0
|
33
|
-
- 0
|
34
23
|
version: 3.0.0
|
35
24
|
type: :runtime
|
36
25
|
version_requirements: *id001
|
@@ -42,11 +31,6 @@ dependencies:
|
|
42
31
|
requirements:
|
43
32
|
- - ">="
|
44
33
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 23
|
46
|
-
segments:
|
47
|
-
- 1
|
48
|
-
- 0
|
49
|
-
- 0
|
50
34
|
version: 1.0.0
|
51
35
|
type: :development
|
52
36
|
version_requirements: *id002
|
@@ -58,11 +42,6 @@ dependencies:
|
|
58
42
|
requirements:
|
59
43
|
- - ">="
|
60
44
|
- !ruby/object:Gem::Version
|
61
|
-
hash: 15
|
62
|
-
segments:
|
63
|
-
- 2
|
64
|
-
- 0
|
65
|
-
- 0
|
66
45
|
version: 2.0.0
|
67
46
|
type: :development
|
68
47
|
version_requirements: *id003
|
@@ -74,11 +53,6 @@ dependencies:
|
|
74
53
|
requirements:
|
75
54
|
- - "="
|
76
55
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 15
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
- 5
|
81
|
-
- 2
|
82
56
|
version: 0.5.2
|
83
57
|
type: :development
|
84
58
|
version_requirements: *id004
|
@@ -90,11 +64,6 @@ dependencies:
|
|
90
64
|
requirements:
|
91
65
|
- - ">="
|
92
66
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 45
|
94
|
-
segments:
|
95
|
-
- 2
|
96
|
-
- 8
|
97
|
-
- 1
|
98
67
|
version: 2.8.1
|
99
68
|
type: :development
|
100
69
|
version_requirements: *id005
|
@@ -119,8 +88,7 @@ files:
|
|
119
88
|
- ran_a_lytics.gemspec
|
120
89
|
- ran_a_lytics.komodoproject
|
121
90
|
- ran_a_lytics.kpf
|
122
|
-
|
123
|
-
homepage: http://github.com/golsombe/Ran_a_lytics
|
91
|
+
homepage: http://github.com/golsombe/Ran-a-lytics
|
124
92
|
licenses: []
|
125
93
|
|
126
94
|
post_install_message:
|
@@ -133,25 +101,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
133
101
|
requirements:
|
134
102
|
- - ">="
|
135
103
|
- !ruby/object:Gem::Version
|
136
|
-
hash: 3
|
137
|
-
segments:
|
138
|
-
- 0
|
139
104
|
version: "0"
|
140
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
106
|
none: false
|
142
107
|
requirements:
|
143
108
|
- - ">="
|
144
109
|
- !ruby/object:Gem::Version
|
145
|
-
hash: 23
|
146
|
-
segments:
|
147
|
-
- 1
|
148
|
-
- 3
|
149
|
-
- 6
|
150
110
|
version: 1.3.6
|
151
111
|
requirements: []
|
152
112
|
|
153
113
|
rubyforge_project: ran_a_lytics
|
154
|
-
rubygems_version: 1.
|
114
|
+
rubygems_version: 1.7.2
|
155
115
|
signing_key:
|
156
116
|
specification_version: 3
|
157
117
|
summary: An Infobright compainion Rails extention
|