metrify 0.3.2 → 0.4.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/README.rdoc +20 -14
- data/app/controllers/metrify_controller.rb +10 -3
- data/app/helpers/metrify_helper.rb +1 -1
- data/app/views/metrify/_chart.html.erb +1 -1
- data/app/views/metrify/_time_links.erb +3 -0
- data/lib/metrify.rb +32 -17
- data/spec/debug.log +3692 -3240
- data/spec/metrify_spec.rb +36 -37
- data/spec/schema.rb +4 -4
- metadata +5 -5
data/spec/metrify_spec.rb
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
require 'set'
|
|
3
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')
|
|
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
|
+
DATE_1 = Time.utc(2010,"oct",20,0,0,0)
|
|
9
|
+
DATE_2 = Time.utc(2010,"oct",21,0,0,0)
|
|
10
|
+
DATE_3 = Time.utc(2010,"oct",22,0,0,0)
|
|
7
11
|
|
|
8
12
|
RANGE_1 = 100
|
|
9
13
|
RANGE_2 = 10
|
|
@@ -14,37 +18,37 @@ class InvalidMetric < ActiveRecord::Base
|
|
|
14
18
|
acts_as_metrify 'spec/metrify.yml', true
|
|
15
19
|
|
|
16
20
|
class << self
|
|
17
|
-
def element_a_count(start_date,
|
|
18
|
-
return 204 if (start_date == (DATE_1-1.day) &&
|
|
19
|
-
return 23 if (start_date == (DATE_1-7.days) &&
|
|
21
|
+
def element_a_count(start_date, end_time)
|
|
22
|
+
return 204 if (start_date == (DATE_1-1.day) && end_time == DATE_1)
|
|
23
|
+
return 23 if (start_date == (DATE_1-7.days) && end_time == DATE_1)
|
|
20
24
|
5
|
|
21
25
|
end
|
|
22
26
|
|
|
23
|
-
def element_c_count(start_date,
|
|
27
|
+
def element_c_count(start_date, end_time)
|
|
24
28
|
15
|
|
25
29
|
end
|
|
26
30
|
|
|
27
|
-
def element_1_count(start_date,
|
|
31
|
+
def element_1_count(start_date, end_time)
|
|
28
32
|
15
|
|
29
33
|
end
|
|
30
34
|
|
|
31
|
-
def element_2_count(start_date,
|
|
35
|
+
def element_2_count(start_date, end_time)
|
|
32
36
|
15
|
|
33
37
|
end
|
|
34
38
|
|
|
35
|
-
def element_3_count(start_date,
|
|
39
|
+
def element_3_count(start_date, end_time)
|
|
36
40
|
15
|
|
37
41
|
end
|
|
38
42
|
|
|
39
|
-
def element_4_count(start_date,
|
|
43
|
+
def element_4_count(start_date, end_time)
|
|
40
44
|
15
|
|
41
45
|
end
|
|
42
46
|
|
|
43
|
-
def element_cat_count(start_date,
|
|
47
|
+
def element_cat_count(start_date, end_time)
|
|
44
48
|
15
|
|
45
49
|
end
|
|
46
50
|
|
|
47
|
-
def element_dog_count(start_date,
|
|
51
|
+
def element_dog_count(start_date, end_time)
|
|
48
52
|
15
|
|
49
53
|
end
|
|
50
54
|
end
|
|
@@ -52,70 +56,65 @@ end
|
|
|
52
56
|
|
|
53
57
|
class Metric < InvalidMetric
|
|
54
58
|
class << self
|
|
55
|
-
def element_b_count(start_date,
|
|
59
|
+
def element_b_count(start_date, end_time)
|
|
56
60
|
5
|
|
57
61
|
end
|
|
58
62
|
end
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
describe "Metrify" do
|
|
62
|
-
|
|
63
|
-
before(:each) do
|
|
64
|
-
|
|
65
|
-
@site_stat = Metric.new
|
|
66
|
-
end
|
|
67
66
|
|
|
68
67
|
it "should present a stat display name as a method of format $STAT_name" do
|
|
69
|
-
|
|
68
|
+
Metric.element_a_count_name.should eql "Element A Count"
|
|
70
69
|
end
|
|
71
70
|
|
|
72
71
|
# it "should raise MetrifyInclusionError when stat method not implemented" do
|
|
73
|
-
#
|
|
74
|
-
# lambda{
|
|
72
|
+
# Metric = InvalidMetric.new
|
|
73
|
+
# lambda{Metric.historical_values(DATE_1, 1, :day)}.should raise_error(Metrify::MetrifyInclusionError)
|
|
75
74
|
# end
|
|
76
75
|
|
|
77
76
|
it "should present a stat default display name when not specified in config" do
|
|
78
|
-
|
|
77
|
+
Metric.element_c_count_name.should eql "Element C Count"
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
it "should return historical stats, per date range requested, with correct number of days" do
|
|
82
|
-
@historical_site_stats =
|
|
81
|
+
@historical_site_stats = Metric.historical_values(DATE_1, RANGE_1, :day)
|
|
83
82
|
@historical_site_stats.size.should eql 100
|
|
84
83
|
(0..RANGE_1-1).each do |idx|
|
|
85
|
-
@historical_site_stats[idx].
|
|
86
|
-
@historical_site_stats[idx].
|
|
84
|
+
@historical_site_stats[idx].number_of_hours.should eql 24
|
|
85
|
+
@historical_site_stats[idx].finish_time.should eql DATE_1-(RANGE_1-1-idx).days
|
|
87
86
|
end
|
|
88
87
|
|
|
89
|
-
@historical_site_stats =
|
|
88
|
+
@historical_site_stats = Metric.historical_values(DATE_1, RANGE_2, :month)
|
|
90
89
|
(0..RANGE_2-1).each do |idx|
|
|
91
|
-
@historical_site_stats[idx].
|
|
92
|
-
@historical_site_stats[idx].
|
|
90
|
+
@historical_site_stats[idx].number_of_hours.should eql 30*24
|
|
91
|
+
@historical_site_stats[idx].finish_time.should eql DATE_1-(RANGE_2-1-idx).months
|
|
93
92
|
end
|
|
94
93
|
end
|
|
95
94
|
|
|
96
95
|
it "should send start and correctly calculated end dates correctly to biz stat methods" do
|
|
97
|
-
historical_site_stats =
|
|
96
|
+
historical_site_stats = Metric.historical_values(DATE_1, 1, :day)
|
|
98
97
|
|
|
99
98
|
historical_site_stats[0].element_a_count.should eql 204
|
|
100
|
-
historical_site_stats =
|
|
99
|
+
historical_site_stats = Metric.historical_values(DATE_1, 2, :day)
|
|
101
100
|
historical_site_stats[0].element_a_count.should eql 5
|
|
102
|
-
historical_site_stats =
|
|
101
|
+
historical_site_stats = Metric.historical_values(DATE_1, 1, :week)
|
|
103
102
|
historical_site_stats[0].element_a_count.should eql 23
|
|
104
103
|
end
|
|
105
104
|
|
|
106
105
|
it "should return filters with hash of hashes" do
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
Metric.filters['type'].keys.to_set.should eql ['numbers', 'letters', 'animals'].to_set
|
|
107
|
+
Metric.filters['type']['numbers']['set'].to_set.should eql ['element_1_count', 'element_2_count', 'element_3_count', 'element_4_count'].to_set
|
|
108
|
+
Metric.filters['furriness'].keys.to_set.should eql ['furry', 'not_furry'].to_set
|
|
110
109
|
end
|
|
111
110
|
|
|
112
111
|
it "should return all stat names with no filters" do
|
|
113
|
-
|
|
112
|
+
Metric.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']
|
|
114
113
|
end
|
|
115
114
|
|
|
116
115
|
it "should honor filters when returning stat names" do
|
|
117
116
|
filters = {'type' => ['numbers', 'letters'], 'furriness' => ['furry', 'not_furry']}
|
|
118
|
-
|
|
117
|
+
Metric.stat_names(nil, 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']
|
|
119
118
|
end
|
|
120
119
|
|
|
121
120
|
end
|
data/spec/schema.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
ActiveRecord::Schema.define(:version => 0) do
|
|
2
2
|
create_table :metrics, :force => true do |t|
|
|
3
|
-
t.
|
|
4
|
-
t.integer :
|
|
3
|
+
t.datetime :finish_time
|
|
4
|
+
t.integer :number_of_hours
|
|
5
5
|
t.string :stat_hash
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
create_table :invalid_metrics, :force => true do |t|
|
|
9
|
-
t.
|
|
10
|
-
t.integer :
|
|
9
|
+
t.datetime :finish_time
|
|
10
|
+
t.integer :number_of_hours
|
|
11
11
|
t.string :stat_hash
|
|
12
12
|
end
|
|
13
13
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metrify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 15
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 4
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.4.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Stephen Abrams
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-11-
|
|
18
|
+
date: 2010-11-22 00:00:00 -05:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|