virgo 0.1.16 → 0.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27b645f8978d61b8b0324df45f5b08e710ab35f6
4
- data.tar.gz: f545e49f74cd6b21b89f2194ec7b8128817e2895
3
+ metadata.gz: 580bd7bd217b956832844c3f3f3f76dd843af6a9
4
+ data.tar.gz: 5fc73ea9fd9ca9e38407adb167df994f0372903d
5
5
  SHA512:
6
- metadata.gz: 7b387eb698aba192a5b6a76c9aef4778399b4e29a687a149f0198b3113c549386f7ba9dd4c6d4d7ceeb216157a4bb3f993193cfaf66cdaefb972b2f9dbd03b84
7
- data.tar.gz: fd98543c01c0af1e2b446a8b12fb0ffd95d7beaccc86d902ccc481e04caeabf08e5826cd77c408124856ec7c1f84a9a9aae3612df69800d5978ce8d17de40aba
6
+ metadata.gz: 390057353037d414a40cb18f8778c131a22695287e7d93776d00653b254c24c5b82c96a21166171447ed8ed1e833550599f1cb1c5198a04d678a6460db97c7d4
7
+ data.tar.gz: e110457925f20ad0ff9b4f85174cd3ab6a0f1dffe27f20bb3c87b0f885b2bbfd9a1c2380feaafb0510c54dcf9f8297f560a0a912506ae9749571d72b05249b2c
@@ -213,29 +213,25 @@ module Virgo
213
213
  def track_view!
214
214
  update_columns({
215
215
  view_count: (view_count + 1),
216
- popularity: calc_popularity(:increment)
216
+ popularity: calc_popularity
217
217
  })
218
218
  end
219
219
 
220
- def calc_popularity(opt=nil)
220
+ # based on reddit "hot" algorithm:
221
+ # https://gist.github.com/jrochkind/2636355
222
+ def calc_popularity
221
223
  unless publish_at.nil?
222
- # the number of days ago the very oldest post was made
223
- days_ago_max = (Time.now - Post.minimum(:publish_at))/86400
224
- days_ago = (Time.now - publish_at)/86400
225
-
226
- # ex oldest post gets age_percentage 0.0, newest post gets 1.
227
- age_percentage = (1 - (days_ago/(days_ago_max || 1.0)))
228
-
229
- # boost from today to 10x...
230
- age_percentage = 10 if publish_at.to_date == Date.today
231
-
232
- # age factor is a number in the range of 0.1 - 1.00
233
- # that is used to moderate the weight of votes for this post
234
- age_factor = 0.1 + (0.9*age_percentage)
235
-
236
- basis = opt == :increment ? (view_count + 1) : view_count
224
+ s = view_count
225
+ displacement = Math.log( [s.abs, 1].max, 10 )
226
+ sign = if s > 0
227
+ 1
228
+ elsif s < 0
229
+ -1
230
+ else
231
+ 0
232
+ end
237
233
 
238
- basis * age_factor
234
+ rank = (displacement * sign.to_f) + ( epoch_seconds(publish_at) / 45000 )
239
235
  else
240
236
  0
241
237
  end
@@ -1,3 +1,3 @@
1
1
  module Virgo
2
- VERSION = "0.1.16"
2
+ VERSION = "0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virgo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Zaillian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-18 00:00:00.000000000 Z
11
+ date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails