trackablaze 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -3
- data/lib/trackablaze.rb +2 -0
- data/lib/trackablaze/metric.rb +16 -0
- data/lib/trackablaze/param.rb +12 -0
- data/lib/trackablaze/tracker.rb +58 -65
- data/spec/spec_helper.rb +1 -1
- data/spec/trackablaze/trackers/sanity_spec.rb +48 -0
- data/trackers/facebook_page.yml +2 -2
- data/trackers/klout.yml +9 -9
- data/trackers/pagerank.yml +2 -2
- data/trackers/twitter.yml +4 -4
- data/version.rb +1 -1
- metadata +6 -2
data/README.markdown
CHANGED
@@ -132,8 +132,8 @@ are made of up of a **YAML config file** and a **ruby code file**.
|
|
132
132
|
|
133
133
|
|
134
134
|
A tracker must implement get_metrics() method. This method takes
|
135
|
-
in an array of configurations. Your tracker may choose to query
|
136
|
-
for each
|
135
|
+
in an array of tracker items (i.e. configurations). Your tracker may choose to query
|
136
|
+
for each tracker item one by one or use any available optimized
|
137
137
|
API calls. For example, the above code queries Twitter API once
|
138
138
|
for each user handle, but can be optimized by using the
|
139
139
|
::Twitter.users API call that takes an array of user handles.
|
@@ -152,5 +152,5 @@ please see the wiki.
|
|
152
152
|
|
153
153
|
Trackablaze and its recipes are distributed under the MIT License.
|
154
154
|
|
155
|
-
[1]:http://
|
155
|
+
[1]:http://trackablaze.com
|
156
156
|
[2]:https://github.com/aflatune/trackablaze-gem/tree/master/trackers
|
data/lib/trackablaze.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Trackablaze
|
2
|
+
class Metric
|
3
|
+
attr_accessor :name, :title, :config
|
4
|
+
|
5
|
+
def initialize(name, config)
|
6
|
+
@name = name
|
7
|
+
@title = config['title']
|
8
|
+
@default = config['default']
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def default?
|
13
|
+
@default == true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/trackablaze/tracker.rb
CHANGED
@@ -1,58 +1,68 @@
|
|
1
1
|
module Trackablaze
|
2
|
-
class Tracker
|
3
|
-
|
4
|
-
# A string that uniquely identifies this instance of the tracker
|
5
|
-
# This is to optimize multiple instances that are exactly the same
|
6
|
-
# e.g. if 100 people want to track amolk's twitter account, the tracker can
|
7
|
-
# be run only once, optimizing calls to Twitter API.
|
8
|
-
def self.key(config)
|
9
|
-
# By default we use all params and metrics
|
10
|
-
sb = []
|
11
|
-
sb.push(self.handle)
|
12
|
-
sb.push(config['params'].flatten) if config['params']
|
13
|
-
sb.push((config['metrics'] || default_metrics).flatten)
|
14
|
-
sb.flatten.join('_')
|
15
|
-
end
|
16
|
-
|
17
|
-
# A string that uniquely identifies this instance of the tracker, without the metrics list
|
18
|
-
# This is used in the csv output
|
19
|
-
def self.key2(config)
|
20
|
-
# By default we use all params and metrics
|
21
|
-
sb = []
|
22
|
-
sb.push(self.handle)
|
23
|
-
sb.push(config['params'].flatten) if config['params']
|
24
|
-
sb.flatten.join('_')
|
25
|
-
end
|
26
|
-
|
2
|
+
class Tracker
|
27
3
|
class << self
|
28
|
-
attr_accessor :trackers
|
29
|
-
|
4
|
+
attr_accessor :trackers, :info, :handle, :params, :metrics, :title, :default_metrics
|
5
|
+
|
6
|
+
def load
|
7
|
+
@info = YAML::load( File.open( File.dirname(__FILE__) + "/../../trackers/#{self.handle}.yml" ) )
|
8
|
+
@title = @info['title']
|
9
|
+
@params = {}
|
10
|
+
|
11
|
+
self.info['params'].each do |param_name, param_config|
|
12
|
+
@params[param_name] = Param.new(param_name, param_config)
|
13
|
+
end
|
14
|
+
|
15
|
+
@metrics = {}
|
16
|
+
self.info['metrics'].each do |metric_name, metric_config|
|
17
|
+
@metrics[metric_name] = Metric.new(metric_name, metric_config)
|
18
|
+
end
|
19
|
+
|
20
|
+
@default_metrics = self.info['metrics'].collect{|k, v| k if v && v['default']}.compact
|
21
|
+
end
|
22
|
+
|
23
|
+
def handle
|
24
|
+
@handle ||= self.name.split('::')[1].underscore
|
25
|
+
end
|
26
|
+
|
30
27
|
def load_trackers
|
31
28
|
@trackers = {}
|
32
29
|
Trackablaze::Tracker.subclasses.each do |t|
|
30
|
+
t.load
|
33
31
|
@trackers[t.handle] = t
|
34
32
|
end
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
33
|
+
end
|
34
|
+
|
35
|
+
# A string that uniquely identifies this instance of the tracker
|
36
|
+
# This is to optimize multiple instances that are exactly the same
|
37
|
+
# e.g. if 100 people want to track amolk's twitter account, the tracker can
|
38
|
+
# be run only once, optimizing calls to Twitter API.
|
39
|
+
def key(config)
|
40
|
+
# By default we use all params and metrics
|
41
|
+
sb = []
|
42
|
+
sb.push(self.handle)
|
43
|
+
sb.push(config['params'].flatten) if config['params']
|
44
|
+
sb.push((config['metrics'] || default_metrics).flatten)
|
45
|
+
sb.flatten.join('_')
|
46
|
+
end
|
47
|
+
|
48
|
+
# A string that uniquely identifies this instance of the tracker, without the metrics list
|
49
|
+
# This is used in the csv output
|
50
|
+
def key2(config)
|
51
|
+
# By default we use all params and metrics
|
52
|
+
sb = []
|
53
|
+
sb.push(self.handle)
|
54
|
+
sb.push(config['params'].flatten) if config['params']
|
55
|
+
sb.flatten.join('_')
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def param_title(param_name)
|
60
|
+
(params[param_name].title if params[param_name]) || param_name
|
61
|
+
end
|
62
|
+
|
63
|
+
def metric_title(metric_name)
|
64
|
+
(metrics[metric_name].title if metrics[metric_name]) || metric_name
|
65
|
+
end
|
56
66
|
end
|
57
67
|
|
58
68
|
def add_error(metrics, error, field = nil)
|
@@ -60,22 +70,5 @@ module Trackablaze
|
|
60
70
|
metrics['errors'].push({:error => error, :field => field})
|
61
71
|
end
|
62
72
|
|
63
|
-
def self.param_title(param_name)
|
64
|
-
param_info = info['params'][param_name]
|
65
|
-
if param_info
|
66
|
-
param_info['name']
|
67
|
-
else
|
68
|
-
param_name
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def self.metric_title(metric_name)
|
73
|
-
metric_info = info['metrics'][metric_name]
|
74
|
-
if metric_info
|
75
|
-
metric_info['name']
|
76
|
-
else
|
77
|
-
metric_name
|
78
|
-
end
|
79
|
-
end
|
80
73
|
end
|
81
74
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# This is a simple set of tests to make sure that
|
4
|
+
# all trackers conform to basic requirements.
|
5
|
+
|
6
|
+
Trackablaze::Tracker.trackers.each do |tracker_handle, tracker_class|
|
7
|
+
describe tracker_class do
|
8
|
+
describe 'basics' do
|
9
|
+
it("should have a handle"){ tracker_class.handle.should be_kind_of(String); tracker_class.handle.should_not be_empty }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'tracker configuration yml' do
|
13
|
+
it("should exist (#{tracker_class.handle}.yml)") { tracker_class.info.should_not be_nil; }
|
14
|
+
it("should be a hash"){ tracker_class.info.should be_kind_of(Hash); }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'tracker configuration' do
|
18
|
+
it("should have params"){ tracker_class.params.should be_kind_of(Hash); }
|
19
|
+
it("should have metrics"){ tracker_class.metrics.should be_kind_of(Hash); }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'tracker params' do
|
23
|
+
tracker_class.params.each do |param_name, param|
|
24
|
+
describe "param #{param_name}" do
|
25
|
+
it("should have a name"){ param.name.should be_kind_of(String); param.name.should_not be_empty }
|
26
|
+
it("should have a title"){ param.title.should be_kind_of(String); param.title.should_not be_empty }
|
27
|
+
it("should have a description"){ param.description.should be_kind_of(String); param.description.should_not be_empty }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'tracker metrics' do
|
33
|
+
tracker_class.metrics.each do |metric_name, metric|
|
34
|
+
describe "metric #{metric_name}" do
|
35
|
+
it("should have a name"){ metric.name.should be_kind_of(String); metric.name.should_not be_empty }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'tracker interface' do
|
41
|
+
['get_metrics'].each do |method_name|
|
42
|
+
it("should have method #{method_name}"){ tracker_class.new.should respond_to(method_name) }
|
43
|
+
end
|
44
|
+
|
45
|
+
it("get_metrics should return empty array when given an empty array"){ tracker_class.new.get_metrics([]).should == [] }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/trackers/facebook_page.yml
CHANGED
data/trackers/klout.yml
CHANGED
@@ -2,42 +2,42 @@ title: 'Klout'
|
|
2
2
|
|
3
3
|
params:
|
4
4
|
username:
|
5
|
-
|
5
|
+
title: 'Username'
|
6
6
|
description: 'Klout username'
|
7
7
|
type: string
|
8
8
|
|
9
9
|
metrics:
|
10
10
|
kscore:
|
11
|
-
|
11
|
+
title: 'Score'
|
12
12
|
description: 'Klout score'
|
13
13
|
default: true
|
14
14
|
|
15
15
|
slope:
|
16
|
-
|
16
|
+
title: 'Slope'
|
17
17
|
description: 'How fast Klout score is changing'
|
18
18
|
|
19
19
|
kclass:
|
20
|
-
|
20
|
+
title: 'Class'
|
21
21
|
description: 'Klout class assigned to the user'
|
22
22
|
default: true
|
23
23
|
|
24
24
|
network_score:
|
25
|
-
|
25
|
+
title: 'Network score'
|
26
26
|
description: 'Network Influence is the influence level of your engaged audience (see http://corp.klout.com/kscore)'
|
27
27
|
|
28
28
|
amplification_score:
|
29
|
-
|
29
|
+
title: 'Amplification probability'
|
30
30
|
description: 'Amplification Probability is the likelihood that your content will be acted upon (see http://corp.klout.com/kscore)'
|
31
31
|
|
32
32
|
true_reach:
|
33
|
-
|
33
|
+
title: 'True reach'
|
34
34
|
description: 'True Reach is the size of your engaged audience (see http://corp.klout.com/kscore)'
|
35
35
|
|
36
36
|
delta_1day:
|
37
|
-
|
37
|
+
title: '1 day delta'
|
38
38
|
description: 'Change in Klout score in 1 day'
|
39
39
|
default: true
|
40
40
|
|
41
41
|
delta_5day:
|
42
|
-
|
42
|
+
title: '5 day delta'
|
43
43
|
description: 'Change in Klout score in 5 days'
|
data/trackers/pagerank.yml
CHANGED
data/trackers/twitter.yml
CHANGED
@@ -2,15 +2,15 @@ title: 'Twitter'
|
|
2
2
|
|
3
3
|
params:
|
4
4
|
handle:
|
5
|
-
|
5
|
+
title: 'Handle'
|
6
6
|
description: 'Twitter handle, i.e. username'
|
7
7
|
type: string
|
8
8
|
|
9
9
|
metrics:
|
10
10
|
followers_count:
|
11
|
-
|
11
|
+
title: 'Followers'
|
12
12
|
default: true
|
13
13
|
friends_count:
|
14
|
-
|
14
|
+
title: 'Following'
|
15
15
|
statuses_count:
|
16
|
-
|
16
|
+
title: 'Tweets'
|
data/version.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: trackablaze
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Amol Kelkar
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-
|
13
|
+
date: 2011-06-23 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -123,6 +123,8 @@ extra_rdoc_files: []
|
|
123
123
|
|
124
124
|
files:
|
125
125
|
- lib/trackablaze/command.rb
|
126
|
+
- lib/trackablaze/metric.rb
|
127
|
+
- lib/trackablaze/param.rb
|
126
128
|
- lib/trackablaze/tracker.rb
|
127
129
|
- lib/trackablaze/tracker_item.rb
|
128
130
|
- lib/trackablaze/utils.rb
|
@@ -138,6 +140,7 @@ files:
|
|
138
140
|
- README.markdown
|
139
141
|
- version.rb
|
140
142
|
- spec/spec_helper.rb
|
143
|
+
- spec/trackablaze/trackers/sanity_spec.rb
|
141
144
|
- bin/trackablaze
|
142
145
|
has_rdoc: true
|
143
146
|
homepage: http://trackablaze.com
|
@@ -169,3 +172,4 @@ specification_version: 3
|
|
169
172
|
summary: A tool to track web metrics.
|
170
173
|
test_files:
|
171
174
|
- spec/spec_helper.rb
|
175
|
+
- spec/trackablaze/trackers/sanity_spec.rb
|