aggtive_record 0.2.1 → 0.2.2
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.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmZlNDM4YTRiZTMwOGVlZjYwOWIwOWE2NmExNTAzODEzNTA0ZmI1OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDQwZjE3ZWQ0ZTZhNDgwY2RhNzMwOTI5YzM1NDU0NjcwNDRhN2FlMQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA2YjM5ZjVkMTlmMjViMTBmOTQwNjBjODUzMTJiZDRiNmM5ODBmMTYxNzc0
|
10
|
+
NTllNDc4ZGJkZmQ0ZTRiOGJkMTdjZTIwOWMyYWZhMDA4MDA0ZGY5ZDM0Y2Rk
|
11
|
+
MTNiNGI0ZDk2OGUxYjFjNDkyMWU3MDBiY2Y3MzEyNTkxNWFmY2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODBiNTU3ZTBmN2E2YzJkNGMyMjAwODY4MjY3NzU1OGYzM2ViYzFhMzI3Y2Qw
|
14
|
+
YjA5NmZlMDkzMzcxZGE5NzI2ZTRkMzc3MDI3YmY3OWQ3YWE0NTU4ODAxOTIx
|
15
|
+
Mzk2ZjQwMWJmOGM2ZGU5ZmUyOGJlODJiYTljMWY1YWQzOTNkZWE=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
data/aggtive_record.gemspec
CHANGED
@@ -14,17 +14,19 @@ module AggtiveRecord
|
|
14
14
|
#
|
15
15
|
# Returns float indicating rate of records per given time period
|
16
16
|
def rate_per(time_period, timespan_in_seconds = nil)
|
17
|
+
|
17
18
|
# tk: this may be unnecessary
|
18
19
|
records = self.scoped.to_a
|
19
20
|
|
20
|
-
|
21
|
-
time_period_in_secs = AggtiveRecord::Time.to_seconds(time_period)
|
22
|
-
|
23
|
-
#e.g. whatever is passed in, or all of them from the beginning to end of reconrds
|
21
|
+
#e.g. whatever is passed in, or all of them from the beginning to end of reconrds
|
24
22
|
timespan_in_seconds ||= self.timespan_to_now(records)
|
25
23
|
|
26
|
-
|
24
|
+
# return 0 if no timespan_in_seconds
|
25
|
+
return 0 if timespan_in_seconds.to_i ==0
|
27
26
|
|
27
|
+
# eg. :hour is 3600 seconds
|
28
|
+
time_period_in_secs = AggtiveRecord::Time.to_seconds(time_period)
|
29
|
+
|
28
30
|
return records.size.to_f * time_period_in_secs / timespan_in_seconds
|
29
31
|
end
|
30
32
|
|
@@ -3,6 +3,30 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe AggtiveRecord do
|
5
5
|
|
6
|
+
context 'collation with zero' do
|
7
|
+
|
8
|
+
describe '.rate_by' do
|
9
|
+
it 'should return rates of 0 with no records' do
|
10
|
+
|
11
|
+
expect(MusicRecord.rate_per_week(:past_month)).to eq 0
|
12
|
+
expect(MusicRecord.rate_per_hour(:past_year)).to eq 0
|
13
|
+
expect(MusicRecord.rate_per_hour(:overall)).to eq 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.past_' do
|
18
|
+
it 'should be empty with no records' do
|
19
|
+
expect(MusicRecord.past_year).to be_empty
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.count_by' do
|
24
|
+
it 'should be empty with no records' do
|
25
|
+
expect(MusicRecord.count_by_month).to be_empty
|
26
|
+
expect(MusicRecord.past_year.count_by_month).to be_empty
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
6
30
|
|
7
31
|
context 'collation methods acting in concert' do
|
8
32
|
before(:each) do
|
@@ -22,6 +46,8 @@ describe AggtiveRecord do
|
|
22
46
|
expect(MusicRecord.overall.count).to eq 4
|
23
47
|
end
|
24
48
|
|
49
|
+
|
50
|
+
|
25
51
|
it '#rate_per_week(:overall)' do
|
26
52
|
old_time = MusicRecord.order('published_at').pluck(:published_at).first
|
27
53
|
new_time = Time.now
|