streak 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/lib/streak/collector.rb +16 -16
- data/lib/streak/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/streak.gemspec +0 -2
- metadata +10 -10
data/CHANGELOG.md
CHANGED
data/lib/streak/collector.rb
CHANGED
@@ -14,35 +14,35 @@ module Streak
|
|
14
14
|
def aggregate(id, count)
|
15
15
|
if count >= 0
|
16
16
|
previous_data = Streak.redis.multi do |transaction|
|
17
|
-
transaction.get("#{Streak
|
18
|
-
transaction.get("#{Streak
|
17
|
+
transaction.get("#{Streak.namespace}:#{Streak.positive_key}:#{id}")
|
18
|
+
transaction.get("#{Streak.namespace}:#{Streak.positive_streak_key}:#{id}")
|
19
19
|
end
|
20
20
|
|
21
21
|
previous_wins = previous_data[0].to_i
|
22
22
|
previous_streak = previous_data[1].to_i
|
23
23
|
|
24
24
|
Streak.redis.multi do |transaction|
|
25
|
-
transaction.set("#{Streak
|
26
|
-
transaction.incrby("#{Streak
|
27
|
-
transaction.incrby("#{Streak
|
28
|
-
transaction.set("#{Streak
|
29
|
-
transaction.incrby("#{Streak
|
25
|
+
transaction.set("#{Streak.namespace}:#{Streak.positive_streak_key}:#{id}", [previous_wins + count, previous_streak].max)
|
26
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.positive_key}:#{id}", count.abs)
|
27
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.positive_total_key}:#{id}", count.abs)
|
28
|
+
transaction.set("#{Streak.namespace}:#{Streak.negative_key}:#{id}", 0)
|
29
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.total_key}:#{id}", count.abs)
|
30
30
|
end
|
31
31
|
else
|
32
32
|
previous_data = Streak.redis.multi do |transaction|
|
33
|
-
transaction.get("#{Streak
|
34
|
-
transaction.get("#{Streak
|
33
|
+
transaction.get("#{Streak.namespace}:#{Streak.negative_key}:#{id}")
|
34
|
+
transaction.get("#{Streak.namespace}:#{Streak.negative_streak_key}:#{id}")
|
35
35
|
end
|
36
36
|
|
37
37
|
previous_losses = previous_data[0].to_i
|
38
38
|
previous_streak = previous_data[1].to_i
|
39
39
|
|
40
40
|
Streak.redis.multi do |transaction|
|
41
|
-
transaction.set("#{Streak
|
42
|
-
transaction.incrby("#{Streak
|
43
|
-
transaction.incrby("#{Streak
|
44
|
-
transaction.set("#{Streak
|
45
|
-
transaction.incrby("#{Streak
|
41
|
+
transaction.set("#{Streak.namespace}:#{Streak.negative_streak_key}:#{id}", [previous_losses + count.abs, previous_streak].max)
|
42
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.negative_key}:#{id}", count.abs)
|
43
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.negative_total_key}:#{id}", count.abs)
|
44
|
+
transaction.set("#{Streak.namespace}:#{Streak.positive_key}:#{id}", 0)
|
45
|
+
transaction.incrby("#{Streak.namespace}:#{Streak.total_key}:#{id}", count.abs)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -61,7 +61,7 @@ module Streak
|
|
61
61
|
def statistics(id, keys = [Streak.positive_key, Streak.positive_total_key, Streak.positive_streak_key, Streak.negative_key, Streak.negative_total_key, Streak.negative_streak_key, Streak.total_key])
|
62
62
|
values = Streak.redis.multi do |transaction|
|
63
63
|
keys.each do |key|
|
64
|
-
transaction.get("#{Streak
|
64
|
+
transaction.get("#{Streak.namespace}:#{key}:#{id}")
|
65
65
|
end
|
66
66
|
end.map(&:to_i)
|
67
67
|
|
@@ -74,7 +74,7 @@ module Streak
|
|
74
74
|
def reset_statistics(id)
|
75
75
|
Streak.redis.multi do |transaction|
|
76
76
|
[Streak.positive_key, Streak.positive_total_key, Streak.positive_streak_key, Streak.negative_key, Streak.negative_total_key, Streak.negative_streak_key, Streak.total_key].each do |key|
|
77
|
-
transaction.set("#{Streak
|
77
|
+
transaction.set("#{Streak.namespace}:#{key}:#{id}", 0)
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
data/lib/streak/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/streak.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: streak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: redis
|
16
|
-
requirement: &
|
16
|
+
requirement: &70352190361800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70352190361800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70352190361340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70352190361340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70352190360860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70352190360860
|
47
47
|
description: Streak is a gem for calculating win/loss streaks
|
48
48
|
email:
|
49
49
|
- me@davidczarnecki.com
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
segments:
|
83
83
|
- 0
|
84
|
-
hash:
|
84
|
+
hash: 4141444244431860570
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: 4141444244431860570
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
96
|
rubygems_version: 1.8.10
|