minuteman 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +24 -5
- data/lib/minuteman.rb +24 -5
- data/lib/minuteman/time_events.rb +1 -1
- data/minuteman.gemspec +1 -1
- data/test/unit/minuteman_test.rb +22 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Freenode - #cuba.rb - 2012/10/30 15:20 UYT
|
|
17
17
|
|
18
18
|
**conanbatt:** i use google analytics for the page itself, and its good, but for the webapp its really not useful
|
19
19
|
|
20
|
-
**tizoc: conanbatt:**
|
20
|
+
**tizoc: conanbatt:** http://amix.dk/blog/post/19714 you can port this (if an equivalent doesn't exist already)
|
21
21
|
|
22
22
|
**conanbatt:** the metrics link is excellent but its python and released 5 days ago lol
|
23
23
|
|
@@ -28,9 +28,9 @@ Freenode - #cuba.rb - 2012/10/30 15:20 UYT
|
|
28
28
|
|
29
29
|
## Inspiration
|
30
30
|
|
31
|
-
*
|
32
|
-
*
|
33
|
-
*
|
31
|
+
* http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/
|
32
|
+
* http://amix.dk/blog/post/19714
|
33
|
+
* http://en.wikipedia.org/wiki/Bit_array
|
34
34
|
|
35
35
|
## Installation
|
36
36
|
|
@@ -80,7 +80,11 @@ analytics.day("login:successful", Time.now.utc)
|
|
80
80
|
analytics.hour("login:successful", Time.now.utc)
|
81
81
|
analytics.minute("login:successful", Time.now.utc)
|
82
82
|
|
83
|
-
#
|
83
|
+
# Lists all the tracked events
|
84
|
+
analytics.events
|
85
|
+
#=> ["login:successful", "programming:login:ruby"]
|
86
|
+
|
87
|
+
# Check event length on a given time
|
84
88
|
today_events.length
|
85
89
|
#=> 2
|
86
90
|
|
@@ -94,3 +98,18 @@ today_events.include?(admin.id)
|
|
94
98
|
today_events.include?(User.all.map(&:id))
|
95
99
|
#=> [true, true, false, false]
|
96
100
|
```
|
101
|
+
|
102
|
+
## Bitwise operations
|
103
|
+
|
104
|
+
You can intersect sets using AND(`&`), OR(`|`), NOT(`-`) and XOR(`^`).
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
invited = analytics.month("email:invitation", Time.now.utc)
|
108
|
+
successful_buys = analytics.month("buy:complete", Time.now.utc)
|
109
|
+
|
110
|
+
successful_buys_after_invitation = invited & successful_buys
|
111
|
+
successful_buys_after_invitation.include?(user.id)
|
112
|
+
|
113
|
+
# Clean up all the operations cache
|
114
|
+
analytics.reset_operations_cache
|
115
|
+
```
|
data/lib/minuteman.rb
CHANGED
@@ -64,14 +64,23 @@ class Minuteman
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
# Public: List all the events given the minuteman namespace
|
68
|
+
#
|
69
|
+
def events
|
70
|
+
keys = @redis.keys([PREFIX, "*", "????"].join("_"))
|
71
|
+
keys.map { |key| key.split("_")[1] }
|
72
|
+
end
|
73
|
+
|
74
|
+
# Public: List all the operations executed in a given the minuteman namespace
|
75
|
+
#
|
76
|
+
def operations
|
77
|
+
@redis.keys([operations_cache_key_prefix, "*"].join("_"))
|
78
|
+
end
|
79
|
+
|
67
80
|
# Public: Resets the bit operation cache keys
|
68
81
|
#
|
69
82
|
def reset_operations_cache
|
70
|
-
|
71
|
-
PREFIX, Minuteman::BitOperations::BIT_OPERATION_PREFIX
|
72
|
-
].join("_")
|
73
|
-
|
74
|
-
keys = @redis.keys([prefix, "*"].join("_"))
|
83
|
+
keys = @redis.keys([operations_cache_key_prefix, "*"].join("_"))
|
75
84
|
@redis.del(keys) if keys.any?
|
76
85
|
end
|
77
86
|
|
@@ -81,4 +90,14 @@ class Minuteman
|
|
81
90
|
keys = @redis.keys([PREFIX, "*"].join("_"))
|
82
91
|
@redis.del(keys) if keys.any?
|
83
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
# Private: The prefix key of all the operations
|
97
|
+
#
|
98
|
+
def operations_cache_key_prefix
|
99
|
+
[
|
100
|
+
PREFIX, Minuteman::BitOperations::BIT_OPERATION_PREFIX
|
101
|
+
].join("_")
|
102
|
+
end
|
84
103
|
end
|
data/minuteman.gemspec
CHANGED
data/test/unit/minuteman_test.rb
CHANGED
@@ -7,7 +7,7 @@ describe Minuteman do
|
|
7
7
|
today = Time.now.utc
|
8
8
|
last_month = today - (3600 * 24 * 30)
|
9
9
|
last_week = today - (3600 * 24 * 7)
|
10
|
-
last_minute = today -
|
10
|
+
last_minute = today - 120
|
11
11
|
|
12
12
|
@analytics.mark("login", 12)
|
13
13
|
@analytics.mark("login", [2, 42])
|
@@ -51,6 +51,27 @@ describe Minuteman do
|
|
51
51
|
assert @last_month_events.include?(567)
|
52
52
|
end
|
53
53
|
|
54
|
+
it "should list all the events" do
|
55
|
+
assert_equal ["login:successful", "login"], @analytics.events
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should reset all the keys" do
|
59
|
+
assert_equal 2, @analytics.events.size
|
60
|
+
|
61
|
+
@analytics.reset_all
|
62
|
+
|
63
|
+
assert_equal 0, @analytics.events.size
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should reset all bit operation keys" do
|
67
|
+
@week_events & @last_week_events
|
68
|
+
assert_equal 1, @analytics.operations.size
|
69
|
+
|
70
|
+
@analytics.reset_operations_cache
|
71
|
+
|
72
|
+
assert_equal 0, @analytics.operations.size
|
73
|
+
end
|
74
|
+
|
54
75
|
it "should accept the AND bitwise operations" do
|
55
76
|
and_operation = @week_events & @last_week_events
|
56
77
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minuteman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|