Introduce rating functions
These hotness and confidence calculation algorithms come from Reddit and have been tweaked based on our experience on the Dillo project.
This commit is contained in:
@@ -184,3 +184,31 @@ class NodeSetattrTest(unittest.TestCase):
|
||||
|
||||
node_setattr(node, 'b.complex', {None: 5})
|
||||
self.assertEqual({'b': {'complex': {None: 5}}}, node)
|
||||
|
||||
|
||||
class TestRating(unittest.TestCase):
|
||||
def test_hotness(self):
|
||||
"""We expect the sorted values to reflect the original order in the
|
||||
list.
|
||||
"""
|
||||
from datetime import datetime, timezone
|
||||
from pillar.api.utils.rating import hot
|
||||
t = datetime(2017, 2, 11, 0, 0, 0, 0, timezone.utc)
|
||||
y = datetime(2017, 2, 10, 0, 0, 0, 0, timezone.utc)
|
||||
w = datetime(2017, 2, 5, 0, 0, 0, 0, timezone.utc)
|
||||
cases = [
|
||||
(hot(1, 8, t), 'today super bad'),
|
||||
(hot(0, 3, t), 'today slightly worse'),
|
||||
(hot(0, 2, y), 'yesterday bad'),
|
||||
(hot(0, 2, t), 'today bad'),
|
||||
(hot(4, 4, w), 'last week controversial'),
|
||||
(hot(7, 1, w), 'last week very good'),
|
||||
(hot(5, 1, y), 'yesterday medium'),
|
||||
(hot(5, 0, y), 'yesterday good'),
|
||||
(hot(7, 1, y), 'yesterday very good'),
|
||||
(hot(4, 4, t), 'today controversial'),
|
||||
(hot(7, 1, t), 'today very good'),
|
||||
]
|
||||
sorted_by_hot = sorted(cases, key=lambda tup: tup[0])
|
||||
for idx, t in enumerate(sorted_by_hot):
|
||||
self.assertEqual(cases[idx][0], t[0])
|
||||
|
Reference in New Issue
Block a user