metrify 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/app/controllers/metrify_controller.rb +91 -0
- data/app/helpers/metrify_helper.rb +25 -0
- data/app/views/metrify/_chart.html.erb +31 -0
- data/app/views/metrify/_graph.html.erb +83 -0
- data/lib/metrify.rb +132 -0
- data/spec/database.yml +9 -0
- data/spec/debug.log +2848 -0
- data/spec/metrify.yml +38 -0
- data/spec/metrify_spec.rb +137 -0
- data/spec/schema.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +17 -0
- metadata +98 -0
data/spec/metrify.yml
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
stats:
|
|
2
|
+
element_a_count:
|
|
3
|
+
display_name: Element A Count
|
|
4
|
+
element_b_count:
|
|
5
|
+
display_name: Element B Count
|
|
6
|
+
element_c_count:
|
|
7
|
+
display_name: Element C Count
|
|
8
|
+
element_1_count:
|
|
9
|
+
display_name: Element 1 Count
|
|
10
|
+
element_2_count:
|
|
11
|
+
display_name: Element 2 Count
|
|
12
|
+
element_3_count:
|
|
13
|
+
display_name: Element 3 Count
|
|
14
|
+
element_4_count:
|
|
15
|
+
display_name: Element 4 Count
|
|
16
|
+
element_cat_count:
|
|
17
|
+
display_name: Cat Count
|
|
18
|
+
element_dog_count:
|
|
19
|
+
display_name: Dog Count
|
|
20
|
+
|
|
21
|
+
filters:
|
|
22
|
+
type:
|
|
23
|
+
numbers:
|
|
24
|
+
set: [element_1_count, element_2_count, element_3_count, element_4_count]
|
|
25
|
+
description: 'Numbers'
|
|
26
|
+
letters:
|
|
27
|
+
set: [element_a_count, element_b_count, element_c_count]
|
|
28
|
+
description: 'Letts'
|
|
29
|
+
animals:
|
|
30
|
+
set: [element_cat_count, element_dog_count]
|
|
31
|
+
description: 'Animals'
|
|
32
|
+
furriness:
|
|
33
|
+
furry:
|
|
34
|
+
set: [element_cat_count, element_dog_count]
|
|
35
|
+
description: 'Furry'
|
|
36
|
+
not_furry:
|
|
37
|
+
set: [element_1_count, element_2_count, element_3_count, element_4_count, element_a_count, element_b_count, element_c_count]
|
|
38
|
+
description: 'Not Furry'
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require 'set'
|
|
3
|
+
|
|
4
|
+
DATE_1 = Date::strptime('20/10/2010', '%d/%m/%Y')
|
|
5
|
+
DATE_2 = Date::strptime('21/10/2010', '%d/%m/%Y')
|
|
6
|
+
DATE_3 = Date::strptime('22/10/2010', '%d/%m/%Y')
|
|
7
|
+
|
|
8
|
+
RANGE_1 = 100
|
|
9
|
+
RANGE_2 = 10
|
|
10
|
+
|
|
11
|
+
#Abstract, really
|
|
12
|
+
class InvalidMetric < ActiveRecord::Base
|
|
13
|
+
include Metrify
|
|
14
|
+
acts_as_site_stat 'spec/metrify.yml', true
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
def element_a_count(start_date, end_date)
|
|
18
|
+
return 204 if (start_date == (DATE_1-1) && end_date == DATE_1)
|
|
19
|
+
return 23 if (start_date == (DATE_1-7) && end_date == DATE_1)
|
|
20
|
+
5
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def element_c_count(start_date, end_date)
|
|
24
|
+
15
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def element_1_count(start_date, end_date)
|
|
28
|
+
15
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def element_2_count(start_date, end_date)
|
|
32
|
+
15
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def element_3_count(start_date, end_date)
|
|
36
|
+
15
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def element_4_count(start_date, end_date)
|
|
40
|
+
15
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def element_cat_count(start_date, end_date)
|
|
44
|
+
15
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def element_dog_count(start_date, end_date)
|
|
48
|
+
15
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class Metric < InvalidMetric
|
|
54
|
+
class << self
|
|
55
|
+
def element_b_count(start_date, end_date)
|
|
56
|
+
5
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe "Metrify" do
|
|
62
|
+
|
|
63
|
+
before(:each) do
|
|
64
|
+
|
|
65
|
+
@site_stat = Metric.new
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "should present a stat display name as a method of format $STAT_name" do
|
|
69
|
+
@site_stat.element_a_count_name.should eql "Element A Count"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# it "should raise MetrifyInclusionError when stat method not implemented" do
|
|
73
|
+
# @site_stat = InvalidMetric.new
|
|
74
|
+
# lambda{@site_stat.historical_values(DATE_1, 1, :day)}.should raise_error(Metrify::MetrifyInclusionError)
|
|
75
|
+
# end
|
|
76
|
+
|
|
77
|
+
# TODO?
|
|
78
|
+
it "should present a stat default display name when not specified in config" do
|
|
79
|
+
@site_stat.element_c_count_name.should eql "Element C Count"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it "should return historical stats, per date range requested, with correct number of days" do
|
|
83
|
+
@historical_site_stats = @site_stat.historical_values(DATE_1, RANGE_1, :day)
|
|
84
|
+
@historical_site_stats.size.should eql 100
|
|
85
|
+
(0..RANGE_1-1).each do |idx|
|
|
86
|
+
@historical_site_stats[idx].finish_date.should eql DATE_1-(RANGE_1-1-idx)
|
|
87
|
+
@historical_site_stats[idx].number_of_days.should eql 1
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
@historical_site_stats = @site_stat.historical_values(DATE_1, RANGE_2, :month)
|
|
91
|
+
(0..RANGE_2-1).each do |idx|
|
|
92
|
+
@historical_site_stats[idx].finish_date.should eql DATE_1-(RANGE_2-1-idx).months
|
|
93
|
+
@historical_site_stats[idx].number_of_days.should eql 30
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "should send start and correctly calculated end dates correctly to biz stat methods" do
|
|
98
|
+
historical_site_stats = @site_stat.historical_values(DATE_1, 1, :day)
|
|
99
|
+
|
|
100
|
+
historical_site_stats[0].element_a_count.should eql 204
|
|
101
|
+
historical_site_stats = @site_stat.historical_values(DATE_1, 2, :day)
|
|
102
|
+
historical_site_stats[0].element_a_count.should eql 5
|
|
103
|
+
historical_site_stats = @site_stat.historical_values(DATE_1, 1, :week)
|
|
104
|
+
historical_site_stats[0].element_a_count.should eql 23
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
it "should return filters with hash of hashes" do
|
|
108
|
+
@site_stat.filters['type'].keys.to_set.should eql ['numbers', 'letters', 'animals'].to_set
|
|
109
|
+
@site_stat.filters['type']['numbers']['set'].to_set.should eql ['element_1_count', 'element_2_count', 'element_3_count', 'element_4_count'].to_set
|
|
110
|
+
@site_stat.filters['furriness'].keys.to_set.should eql ['furry', 'not_furry'].to_set
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should return all stat names with no filters" do
|
|
114
|
+
@site_stat.stat_names.to_set.should eql Set.new ['element_a_count', 'element_b_count', 'element_c_count', 'element_1_count', 'element_2_count', 'element_3_count', 'element_4_count', 'element_cat_count', 'element_dog_count']
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "should honor filters when returning stat names" do
|
|
118
|
+
filters = {'type' => ['numbers', 'letters'], 'furriness' => ['furry', 'not_furry']}
|
|
119
|
+
@site_stat.stat_names(filters).to_set.should eql Set.new ['element_a_count', 'element_b_count', 'element_c_count', 'element_1_count', 'element_2_count', 'element_3_count', 'element_4_count']
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
it "should return an object with stats for a designated date and range" do
|
|
124
|
+
|
|
125
|
+
#@site_stat.find_stats_for(DATE_1, RANGE_1)
|
|
126
|
+
#@site_stat.
|
|
127
|
+
# def find_stats_for(end_date, days)
|
|
128
|
+
# s = lookup(end_date, days)
|
|
129
|
+
# s ||= generate(end_date, days)
|
|
130
|
+
# end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# it "should return the evaluation of the class method for a stat value method" do
|
|
134
|
+
# @site_stat.element_a_count.should eql 293
|
|
135
|
+
# end
|
|
136
|
+
|
|
137
|
+
end
|
data/spec/schema.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ActiveRecord::Schema.define(:version => 0) do
|
|
2
|
+
create_table :metrics, :force => true do |t|
|
|
3
|
+
t.date :finish_date
|
|
4
|
+
t.integer :number_of_days
|
|
5
|
+
t.string :stat_hash
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
create_table :invalid_metrics, :force => true do |t|
|
|
9
|
+
t.date :finish_date
|
|
10
|
+
t.integer :number_of_days
|
|
11
|
+
t.string :stat_hash
|
|
12
|
+
end
|
|
13
|
+
end
|
data/spec/spec.opts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
3
|
+
require 'metrify'
|
|
4
|
+
require 'spec'
|
|
5
|
+
require 'spec/autorun'
|
|
6
|
+
require 'rubygems'
|
|
7
|
+
require 'active_record'
|
|
8
|
+
|
|
9
|
+
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + '/debug.log')
|
|
10
|
+
ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
|
11
|
+
ActiveRecord::Base.establish_connection(ENV['DB'] || 'mysql')
|
|
12
|
+
|
|
13
|
+
load(File.dirname(__FILE__) + '/schema.rb')
|
|
14
|
+
|
|
15
|
+
Spec::Runner.configure do |config|
|
|
16
|
+
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: metrify
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.1.0
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Stephen Abrams
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-10-26 00:00:00 -04:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies:
|
|
21
|
+
- !ruby/object:Gem::Dependency
|
|
22
|
+
name: rspec
|
|
23
|
+
prerelease: false
|
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
hash: 13
|
|
30
|
+
segments:
|
|
31
|
+
- 1
|
|
32
|
+
- 2
|
|
33
|
+
- 9
|
|
34
|
+
version: 1.2.9
|
|
35
|
+
type: :development
|
|
36
|
+
version_requirements: *id001
|
|
37
|
+
description: Framework to aggregate and display data over time. Assumes highcharts installation.
|
|
38
|
+
email: abrams.stephen@gmail.com
|
|
39
|
+
executables: []
|
|
40
|
+
|
|
41
|
+
extensions: []
|
|
42
|
+
|
|
43
|
+
extra_rdoc_files:
|
|
44
|
+
- LICENSE
|
|
45
|
+
- README.rdoc
|
|
46
|
+
files:
|
|
47
|
+
- README.rdoc
|
|
48
|
+
- app/controllers/metrify_controller.rb
|
|
49
|
+
- app/helpers/metrify_helper.rb
|
|
50
|
+
- app/views/metrify/_chart.html.erb
|
|
51
|
+
- app/views/metrify/_graph.html.erb
|
|
52
|
+
- lib/metrify.rb
|
|
53
|
+
- spec/database.yml
|
|
54
|
+
- spec/debug.log
|
|
55
|
+
- spec/metrify.yml
|
|
56
|
+
- spec/metrify_spec.rb
|
|
57
|
+
- spec/schema.rb
|
|
58
|
+
- spec/spec.opts
|
|
59
|
+
- spec/spec_helper.rb
|
|
60
|
+
- LICENSE
|
|
61
|
+
has_rdoc: true
|
|
62
|
+
homepage: http://github.com/sabrams/metrify
|
|
63
|
+
licenses: []
|
|
64
|
+
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options:
|
|
67
|
+
- --charset=UTF-8
|
|
68
|
+
require_paths:
|
|
69
|
+
- lib
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
hash: 3
|
|
76
|
+
segments:
|
|
77
|
+
- 0
|
|
78
|
+
version: "0"
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
none: false
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
hash: 3
|
|
85
|
+
segments:
|
|
86
|
+
- 0
|
|
87
|
+
version: "0"
|
|
88
|
+
requirements: []
|
|
89
|
+
|
|
90
|
+
rubyforge_project:
|
|
91
|
+
rubygems_version: 1.3.7
|
|
92
|
+
signing_key:
|
|
93
|
+
specification_version: 3
|
|
94
|
+
summary: Framework to aggregate and display data over time
|
|
95
|
+
test_files:
|
|
96
|
+
- spec/metrify_spec.rb
|
|
97
|
+
- spec/schema.rb
|
|
98
|
+
- spec/spec_helper.rb
|