aggtive_record 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/VERSION +1 -1
- data/aggtive_record.gemspec +1 -1
- data/lib/aggtive_record/egg_scopes/collation/rate_per.rb +7 -2
- data/spec/functional/collation_spec.rb +9 -1
- data/spec/lib/rate_spec.rb +11 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGVmOTFmZTQ3MGExYjRlM2M5ZWViMDM0NzQ5ZjRiNTM0NGU4YzE1Yg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MGNlMThmOTU1NmYxYjNjMGJmM2QwZjU0YzczOWU3YzJhNjY3MjQzZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjUxNmM0NDg4ZmI1NzE1ZjEyZjdiY2IzOWFmMjZhZWI3ZTk4NDhkYmY4ZGU0
|
10
|
+
NTUyNjVhOGMzZjk4YjUwNmU3NDMxN2NlYTc2Nzk0M2JlMTIzNGQ2ODRkYzUx
|
11
|
+
NjM5NmU3N2M5NmY0ZDUwYTA4YzFlMjkxY2JiNGJhZjc2MTZhMDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjU5NGQ2YmRiZTkwZWQwMGVmOTdmOGFmMWU5NmQ2OTEyOGRmYTU1NzExY2Vi
|
14
|
+
YzY2YjFjYzcxODdiYWFiMGE2YTc5NzMyMDBmOWZkNzk0MWQ1YTY4ZTE5ZDlk
|
15
|
+
MGNmYWM0NzJmNjNkMjU3Y2ExNzdiODdjYWIwOWMyNTY2MjU2NTE=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/aggtive_record.gemspec
CHANGED
@@ -22,12 +22,17 @@ module AggtiveRecord
|
|
22
22
|
timespan_in_seconds ||= self.timespan_to_now(records)
|
23
23
|
|
24
24
|
# return 0 if no timespan_in_seconds
|
25
|
-
return 0 if timespan_in_seconds.to_i ==0
|
25
|
+
return 0 if timespan_in_seconds.to_i == 0
|
26
26
|
|
27
27
|
# eg. :hour is 3600 seconds
|
28
28
|
time_period_in_secs = AggtiveRecord::Time.to_seconds(time_period)
|
29
|
+
|
30
|
+
# if the rate query is #per_year, and the only record was created 1 day ago
|
31
|
+
# then the rate should be _no greater_ than 1 per year (as opposed to 365 per year)
|
32
|
+
time_denominator = [time_period_in_secs, timespan_in_seconds].max
|
33
|
+
|
29
34
|
|
30
|
-
return records.size.to_f * time_period_in_secs /
|
35
|
+
return records.size.to_f * time_period_in_secs / time_denominator
|
31
36
|
end
|
32
37
|
|
33
38
|
# defines rate_per_year, rate_per_hour
|
@@ -52,9 +52,17 @@ describe AggtiveRecord do
|
|
52
52
|
old_time = MusicRecord.order('published_at').pluck(:published_at).first
|
53
53
|
new_time = Time.now
|
54
54
|
|
55
|
-
expect(MusicRecord.rate_per_week(:overall)).to eq
|
55
|
+
expect(MusicRecord.rate_per_week(:overall)).to eq MusicRecord.count.to_f * AggtiveRecord::Time.to_seconds(:week) / (new_time - old_time)
|
56
56
|
end
|
57
57
|
|
58
|
+
it '#rate_per_month(:overall)' do
|
59
|
+
old_time = MusicRecord.order('published_at').pluck(:published_at).first
|
60
|
+
new_time = Time.now
|
61
|
+
|
62
|
+
expect(MusicRecord.rate_per_month(:overall)).to eq MusicRecord.count.to_f * AggtiveRecord::Time.to_seconds(:month) / (new_time - old_time)
|
63
|
+
end
|
64
|
+
|
65
|
+
|
58
66
|
|
59
67
|
it '#rate_per_week(:past_14_days)' do
|
60
68
|
expect(MusicRecord.rate_per_week(:past_14_days)).to eq 0.5
|
data/spec/lib/rate_spec.rb
CHANGED
@@ -23,10 +23,20 @@ describe "AggtiveRecord::EggScopes -- .rate" do
|
|
23
23
|
MusicRecord.create published_at: 59.minutes.ago
|
24
24
|
expect(MusicRecord.rate_per_hour ).to be_within(0.1).of 2
|
25
25
|
end
|
26
|
-
|
27
26
|
end
|
28
27
|
|
29
28
|
|
29
|
+
context 'when time span of all records is less than the time period' do
|
30
|
+
context 'it should have a minimum rate of per that time_period' do
|
31
|
+
it 'should have rate no less than 1 per month' do
|
32
|
+
Timecop.freeze
|
33
|
+
MusicRecord.create published_at: 1.day.ago
|
34
|
+
|
35
|
+
expect(MusicRecord.rate_per_month).to eq 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
30
40
|
it 'should raise an error when a non-time period is passed in'
|
31
41
|
|
32
42
|
end
|