trackoid 0.1.9 → 0.1.10
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 +31 -16
- data/VERSION +1 -1
- data/lib/trackoid/tracker.rb +11 -9
- data/lib/trackoid/tracker_aggregates.rb +12 -12
- data/spec/aggregates_spec.rb +24 -15
- data/spec/spec_helper.rb +1 -1
- data/spec/trackoid_spec.rb +14 -14
- data/trackoid.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -187,20 +187,35 @@ For comparison, this README is already 8.5Kb in size.
|
|
187
187
|
|
188
188
|
= Revision History
|
189
189
|
|
190
|
-
0.1.
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
0.1.
|
205
|
-
|
190
|
+
0.1.10 - Renamed accessor methods from "all", "last", "first" to
|
191
|
+
"all_values", "first_value" and "last_value" so as not to
|
192
|
+
conflict with traditional ActiveRecord accessors.
|
193
|
+
- Aggregate methods with a key returns a single instance, not an
|
194
|
+
Array. For example:
|
195
|
+
|
196
|
+
@page.visits.browser("mozilla").today
|
197
|
+
# Returns now a number instead of an Array
|
198
|
+
|
199
|
+
- Arguments are now passed thru aggregator accessors. For example:
|
200
|
+
|
201
|
+
@page.visits.brosers("mozilla").last_days(15)
|
202
|
+
# Should correctly return now an array with 15 elements.
|
203
|
+
|
204
|
+
0.1.9 - Refactored TrackerAggregates to include all accessor methods
|
205
|
+
(all, last, first, etc.)
|
206
|
+
|
207
|
+
0.1.8 - Another maintenance release. Sorry. :-)
|
208
|
+
|
209
|
+
0.1.7 - Maintenance Release: A little error with the index on aggregated
|
210
|
+
fields
|
211
|
+
|
212
|
+
0.1.6 - Enabled support for String dates in operators. This string date
|
213
|
+
must be DateTime parseable.
|
214
|
+
For example: @spain.world_cups.inc("2010-07-11")
|
215
|
+
- Normalized Date and DateTime objects to use only Date methods.
|
216
|
+
- Added "first" / "first_date" / "last" / "last_date" accessors.
|
217
|
+
- Added "all" accessor.
|
218
|
+
|
219
|
+
0.1.5 - Added support for namespaced models and aggregations
|
220
|
+
- Enabled "set" operations on aggregates
|
206
221
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.10
|
data/lib/trackoid/tracker.rb
CHANGED
@@ -86,14 +86,6 @@ module Mongoid #:nodoc:
|
|
86
86
|
|
87
87
|
|
88
88
|
# Access methods
|
89
|
-
def first
|
90
|
-
data_for(first_date)
|
91
|
-
end
|
92
|
-
|
93
|
-
def last
|
94
|
-
data_for(last_date)
|
95
|
-
end
|
96
|
-
|
97
89
|
def today
|
98
90
|
data_for(Date.today)
|
99
91
|
end
|
@@ -102,6 +94,14 @@ module Mongoid #:nodoc:
|
|
102
94
|
data_for(Date.today - 1)
|
103
95
|
end
|
104
96
|
|
97
|
+
def first_value
|
98
|
+
data_for(first_date)
|
99
|
+
end
|
100
|
+
|
101
|
+
def last_value
|
102
|
+
data_for(last_date)
|
103
|
+
end
|
104
|
+
|
105
105
|
def last_days(how_much = 7)
|
106
106
|
return [today] unless how_much > 0
|
107
107
|
date, values = Date.today, []
|
@@ -114,7 +114,7 @@ module Mongoid #:nodoc:
|
|
114
114
|
data_for(date)
|
115
115
|
end
|
116
116
|
|
117
|
-
def
|
117
|
+
def all_values
|
118
118
|
on(first_date..last_date) if first_date
|
119
119
|
end
|
120
120
|
|
@@ -122,6 +122,7 @@ module Mongoid #:nodoc:
|
|
122
122
|
def first_date
|
123
123
|
# We are guaranteed _m and _d to exists unless @data is a malformed
|
124
124
|
# hash, so we need to do this nasty "return nil", sorry...
|
125
|
+
# TODO: I'm open to change this to a cleaner algorithm :-)
|
125
126
|
return nil unless _y = @data.keys.min
|
126
127
|
return nil unless _m = @data[_y].keys.min
|
127
128
|
return nil unless _d = @data[_y][_m].keys.min
|
@@ -131,6 +132,7 @@ module Mongoid #:nodoc:
|
|
131
132
|
def last_date
|
132
133
|
# We are guaranteed _m and _d to exists unless @data is a malformed
|
133
134
|
# hash, so we need to do this nasty "return nil", sorry...
|
135
|
+
# TODO: I'm open to change this to a cleaner algorithm :-)
|
134
136
|
return nil unless _y = @data.keys.max
|
135
137
|
return nil unless _m = @data[_y].keys.max
|
136
138
|
return nil unless _d = @data[_y][_m].keys.max
|
@@ -6,12 +6,12 @@ module Mongoid #:nodoc:
|
|
6
6
|
|
7
7
|
def initialize(owner, token, key_selector, track_field = nil)
|
8
8
|
@owner, @token = owner, token
|
9
|
-
@key = key_selector
|
9
|
+
@key = key_selector.first
|
10
10
|
@track_field = track_field
|
11
11
|
|
12
12
|
@accessor = @owner.class.send(:internal_accessor_name, @token)
|
13
13
|
@selector = {:ns => @token}
|
14
|
-
@selector.merge!(:key => @key
|
14
|
+
@selector.merge!(:key => @key) if @key
|
15
15
|
@criteria = @owner.send(@accessor).where(@selector)
|
16
16
|
end
|
17
17
|
|
@@ -20,21 +20,21 @@ module Mongoid #:nodoc:
|
|
20
20
|
@criteria.send(name)
|
21
21
|
end
|
22
22
|
|
23
|
-
# Access the aggregation collection with "collection" so that we can
|
24
|
-
# use the original mongoid methods like "all", "first", etc.
|
25
|
-
def collection
|
26
|
-
@criteria
|
27
|
-
end
|
28
|
-
|
29
23
|
# Define all accessors here. Basically we are delegating to the Track
|
30
24
|
# object for every object in the criteria
|
31
|
-
[ :today, :yesterday, :last_days, :
|
25
|
+
[ :today, :yesterday, :last_days, :all_values, :first_value, :last_value,
|
32
26
|
:first_date, :last_date
|
33
27
|
].each {|name|
|
34
28
|
define_method(name) do |*args|
|
35
|
-
@
|
36
|
-
|
37
|
-
|
29
|
+
return nil unless @track_field
|
30
|
+
if @key
|
31
|
+
res = @criteria.first
|
32
|
+
res.send(@track_field).send(name, *args) if res
|
33
|
+
else
|
34
|
+
@criteria.collect {|c|
|
35
|
+
[c.key, c.send(@track_field).send(name, *args)]
|
36
|
+
}
|
37
|
+
end
|
38
38
|
end
|
39
39
|
}
|
40
40
|
|
data/spec/aggregates_spec.rb
CHANGED
@@ -161,18 +161,18 @@ describe Mongoid::Tracking::Aggregates do
|
|
161
161
|
|
162
162
|
it "should correctly save all aggregation keys as strings (inc)" do
|
163
163
|
@mock.something("test").inc
|
164
|
-
@mock.something.aggregate_one.
|
165
|
-
@mock.something.aggregate_two.
|
166
|
-
@mock.something.aggregate_three.
|
167
|
-
@mock.something.aggregate_four.
|
164
|
+
@mock.something.aggregate_one.first.key.is_a?(String).should be_true
|
165
|
+
@mock.something.aggregate_two.first.key.is_a?(String).should be_true
|
166
|
+
@mock.something.aggregate_three.first.key.is_a?(String).should be_true
|
167
|
+
@mock.something.aggregate_four.first.key.is_a?(String).should be_true
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should correctly save all aggregation keys as strings (set)" do
|
171
171
|
@mock.something("test").set(5)
|
172
|
-
@mock.something.aggregate_one.
|
173
|
-
@mock.something.aggregate_two.
|
174
|
-
@mock.something.aggregate_three.
|
175
|
-
@mock.something.aggregate_four.
|
172
|
+
@mock.something.aggregate_one.first.key.is_a?(String).should be_true
|
173
|
+
@mock.something.aggregate_two.first.key.is_a?(String).should be_true
|
174
|
+
@mock.something.aggregate_three.first.key.is_a?(String).should be_true
|
175
|
+
@mock.something.aggregate_four.first.key.is_a?(String).should be_true
|
176
176
|
end
|
177
177
|
|
178
178
|
end
|
@@ -217,8 +217,8 @@ describe Mongoid::Tracking::Aggregates do
|
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should have 0 visits yesterday" do
|
220
|
-
@mock.visits.browsers.
|
221
|
-
@mock.visits.referers.
|
220
|
+
@mock.visits.browsers.yesterday.should == [["mozilla", 0]]
|
221
|
+
@mock.visits.referers.yesterday.should == [["firefox", 0]]
|
222
222
|
end
|
223
223
|
|
224
224
|
it "should have 1 visits last 7 days" do
|
@@ -226,6 +226,11 @@ describe Mongoid::Tracking::Aggregates do
|
|
226
226
|
@mock.visits.referers.last_days(7).should == [["firefox", [0, 0, 0, 0, 0, 0, 1]]]
|
227
227
|
end
|
228
228
|
|
229
|
+
it "should work also for arbitrary days" do
|
230
|
+
@mock.visits.browsers.last_days(15).should == [["mozilla", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]]
|
231
|
+
@mock.visits.referers.last_days(15).should == [["firefox", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]]
|
232
|
+
end
|
233
|
+
|
229
234
|
it "should work adding 1 visit with different aggregation data" do
|
230
235
|
@mock.visits("Google Chrome").inc
|
231
236
|
@mock.visits.browsers.today.should == [["mozilla", 1], ["google", 1]]
|
@@ -235,6 +240,10 @@ describe Mongoid::Tracking::Aggregates do
|
|
235
240
|
@mock.visits.browsers.today.inject(0) {|total, c| total + c.last }.should == 2
|
236
241
|
end
|
237
242
|
|
243
|
+
it "should return only values when specifying the aggregation key" do
|
244
|
+
@mock.visits.browsers("mozilla").today.should == 1
|
245
|
+
end
|
246
|
+
|
238
247
|
it "should work also with set" do
|
239
248
|
@mock.visits("Google Chrome").set(5)
|
240
249
|
@mock.visits.browsers.today.should == [["mozilla", 1], ["google", 5]]
|
@@ -278,12 +287,12 @@ describe Mongoid::Tracking::Aggregates do
|
|
278
287
|
@mock.visits("Internet Explorer").set(6, "2010-07-16")
|
279
288
|
end
|
280
289
|
|
281
|
-
it "should return the correct values for .
|
282
|
-
@mock.visits.
|
290
|
+
it "should return the correct values for .all_values" do
|
291
|
+
@mock.visits.all_values.should == [1, 2, 3, 4, 5, 6]
|
283
292
|
end
|
284
293
|
|
285
294
|
it "should return the all values for every aggregate" do
|
286
|
-
@mock.visits.browsers.
|
295
|
+
@mock.visits.browsers.all_values.should == [
|
287
296
|
["mozilla", [1, 0, 0, 4]],
|
288
297
|
["google", [2, 0, 0, 5]],
|
289
298
|
["internet", [3, 0, 0, 6]]
|
@@ -307,7 +316,7 @@ describe Mongoid::Tracking::Aggregates do
|
|
307
316
|
end
|
308
317
|
|
309
318
|
it "should return the first value for aggregates" do
|
310
|
-
@mock.visits.browsers.
|
319
|
+
@mock.visits.browsers.first_value.should == [
|
311
320
|
["mozilla", 1],
|
312
321
|
["google", 2],
|
313
322
|
["internet", 3]
|
@@ -315,7 +324,7 @@ describe Mongoid::Tracking::Aggregates do
|
|
315
324
|
end
|
316
325
|
|
317
326
|
it "should return the last value for aggregates" do
|
318
|
-
@mock.visits.browsers.
|
327
|
+
@mock.visits.browsers.last_value.should == [
|
319
328
|
["mozilla", 4],
|
320
329
|
["google", 5],
|
321
330
|
["internet", 6]
|
data/spec/spec_helper.rb
CHANGED
data/spec/trackoid_spec.rb
CHANGED
@@ -153,11 +153,11 @@ describe Mongoid::Tracking do
|
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should give the first value" do
|
156
|
-
@mock.visits.
|
156
|
+
@mock.visits.first_value.should == 1
|
157
157
|
end
|
158
158
|
|
159
159
|
it "should give the last value" do
|
160
|
-
@mock.visits.
|
160
|
+
@mock.visits.last_value.should == 2
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
@@ -177,16 +177,16 @@ describe Mongoid::Tracking do
|
|
177
177
|
@mock.visits.last_date.should be_nil
|
178
178
|
end
|
179
179
|
|
180
|
-
it "should return nil for .
|
181
|
-
@mock.visits.
|
180
|
+
it "should return nil for .first_date" do
|
181
|
+
@mock.visits.first_value.should be_nil
|
182
182
|
end
|
183
183
|
|
184
|
-
it "should return nil for .
|
185
|
-
@mock.visits.
|
184
|
+
it "should return nil for .last_value" do
|
185
|
+
@mock.visits.last_value.should be_nil
|
186
186
|
end
|
187
187
|
|
188
|
-
it "should return nil for .
|
189
|
-
@mock.visits.
|
188
|
+
it "should return nil for .all_values" do
|
189
|
+
@mock.visits.all_values.should be_nil
|
190
190
|
end
|
191
191
|
end
|
192
192
|
|
@@ -198,21 +198,21 @@ describe Mongoid::Tracking do
|
|
198
198
|
@mock = Test.first
|
199
199
|
end
|
200
200
|
|
201
|
-
it "should return the correct values for .
|
201
|
+
it "should return the correct values for .all_values" do
|
202
202
|
@mock.visits.set(1, "2010-07-11")
|
203
203
|
@mock.visits.set(2, "2010-07-12")
|
204
204
|
@mock.visits.set(3, "2010-07-13")
|
205
205
|
|
206
|
-
@mock.visits.
|
206
|
+
@mock.visits.all_values.should == [1, 2, 3]
|
207
207
|
end
|
208
208
|
|
209
|
-
it "should return the correct values for .
|
209
|
+
it "should return the correct values for .all_values (Take II)" do
|
210
210
|
@mock.visits.set(5, "2010-07-01")
|
211
211
|
@mock.visits.set(10, "2010-07-30")
|
212
212
|
|
213
|
-
@mock.visits.
|
214
|
-
@mock.visits.
|
215
|
-
@mock.visits.
|
213
|
+
@mock.visits.all_values.should == [5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10]
|
214
|
+
@mock.visits.last_value.should == 10
|
215
|
+
@mock.visits.first_value.should == 5
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
data/trackoid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{trackoid}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.10"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jose Miguel Perez"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-22}
|
13
13
|
s.description = %q{Trackoid uses an embeddable approach to track analytics data using the poweful features of MongoDB for scalability}
|
14
14
|
s.email = %q{josemiguel@perezruiz.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 10
|
10
|
+
version: 0.1.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jose Miguel Perez
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-22 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|