[odrs-web/oscp] Boost recent reviews and decay old ones



commit f5f0ec724736e30e4c136784c6d65f6c57b6424f
Author: Michael Terry <mike mterry name>
Date:   Sun Aug 23 22:06:30 2020 -0400

    Boost recent reviews and decay old ones
    
    Recent reviews will get a boost for a few months. Then we start
    depressing scores as reviews age through the years.

 app_data/odrs/views_api.py | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
---
diff --git a/app_data/odrs/views_api.py b/app_data/odrs/views_api.py
index e3f0c76..153381c 100644
--- a/app_data/odrs/views_api.py
+++ b/app_data/odrs/views_api.py
@@ -34,17 +34,7 @@ def _get_client_address():
         return request.headers.getlist('X-Forwarded-For')[0]
     return request.remote_addr
 
-def _get_review_score(review, item):
-    """ Gets a review score given certain parameters """
-    ku = review.karma_up
-    kd = review.karma_down
-
-    # hardcode some penalties
-    if review.version != item['version']:
-        kd = kd + 1
-    if review.distro != item['distro']:
-        kd = kd + 1
-
+def _wilson(ku, kd):
     # algorithm from http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
     wilson = 0
     if ku > 0 or kd > 0:
@@ -54,6 +44,29 @@ def _get_review_score(review, item):
         wilson *= 100
     return int(wilson)
 
+def _get_review_score(review, item):
+    """ Gets a review score given certain parameters """
+    ku = review.karma_up
+    kd = review.karma_down
+
+    created = datetime.datetime.fromtimestamp(review.date_created)
+    months_old = (datetime.datetime.now() - created).days // 30
+
+    # If the review is very new, provide a temporary visibility boost.
+    # The floor of 4 is arbitrary and may need adjustment in the future.
+    ku = max(ku, 4 - months_old)
+
+    # For every year that has passed and for a mismatched version or distro, we
+    # add a penalty. Penalties will reduce the final score.
+    penalties = months_old // 12
+    if review.version != item['version']:
+        penalties += 1
+    if review.distro != item['distro']:
+        penalties += 1
+
+    w = _wilson(ku, kd)
+    return max(0, w - penalties * 10)
+
 def _check_str(val):
     """ Return with success if the summary and description """
     if val.find('<') != -1:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]