aggtive_record 0.2.2 → 0.2.3

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
- YmZlNDM4YTRiZTMwOGVlZjYwOWIwOWE2NmExNTAzODEzNTA0ZmI1OQ==
4
+ NGVmOTFmZTQ3MGExYjRlM2M5ZWViMDM0NzQ5ZjRiNTM0NGU4YzE1Yg==
5
5
  data.tar.gz: !binary |-
6
- MDQwZjE3ZWQ0ZTZhNDgwY2RhNzMwOTI5YzM1NDU0NjcwNDRhN2FlMQ==
6
+ MGNlMThmOTU1NmYxYjNjMGJmM2QwZjU0YzczOWU3YzJhNjY3MjQzZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzA2YjM5ZjVkMTlmMjViMTBmOTQwNjBjODUzMTJiZDRiNmM5ODBmMTYxNzc0
10
- NTllNDc4ZGJkZmQ0ZTRiOGJkMTdjZTIwOWMyYWZhMDA4MDA0ZGY5ZDM0Y2Rk
11
- MTNiNGI0ZDk2OGUxYjFjNDkyMWU3MDBiY2Y3MzEyNTkxNWFmY2E=
9
+ YjUxNmM0NDg4ZmI1NzE1ZjEyZjdiY2IzOWFmMjZhZWI3ZTk4NDhkYmY4ZGU0
10
+ NTUyNjVhOGMzZjk4YjUwNmU3NDMxN2NlYTc2Nzk0M2JlMTIzNGQ2ODRkYzUx
11
+ NjM5NmU3N2M5NmY0ZDUwYTA4YzFlMjkxY2JiNGJhZjc2MTZhMDM=
12
12
  data.tar.gz: !binary |-
13
- ODBiNTU3ZTBmN2E2YzJkNGMyMjAwODY4MjY3NzU1OGYzM2ViYzFhMzI3Y2Qw
14
- YjA5NmZlMDkzMzcxZGE5NzI2ZTRkMzc3MDI3YmY3OWQ3YWE0NTU4ODAxOTIx
15
- Mzk2ZjQwMWJmOGM2ZGU5ZmUyOGJlODJiYTljMWY1YWQzOTNkZWE=
13
+ YjU5NGQ2YmRiZTkwZWQwMGVmOTdmOGFmMWU5NmQ2OTEyOGRmYTU1NzExY2Vi
14
+ YzY2YjFjYzcxODdiYWFiMGE2YTc5NzMyMDBmOWZkNzk0MWQ1YTY4ZTE5ZDlk
15
+ MGNmYWM0NzJmNjNkMjU3Y2ExNzdiODdjYWIwOWMyNTY2MjU2NTE=
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "aggtive_record"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dan Nguyen"]
@@ -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 / timespan_in_seconds
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 4.0 * AggtiveRecord::Time.to_seconds(:week) / (new_time - old_time)
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aggtive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Nguyen