コード例 #1
0
    def test_score(self):
        """Should score things based on a cool formula."""
        now = str(time.time())

        # 4 users, 9000 views, no gold
        listing1 = {
            'listing_id': 1,
            'quantity': 1,
            'state': 'active',
            'views': 9000,
            'materials': [],
            'users': 4,
            'original_creation_tsz': now,
        }

        # 40 users, 9 views, 10 quantity, no gold
        listing2 = {
            'listing_id': 2,
            'quantity': 10,
            'state': 'active',
            'views': 9,
            'materials': [],
            'users': 40,
            'original_creation_tsz': now,
        }

        # 1 user, 10 views, 10 quantity, gold
        listing3 = {
            'listing_id': 3,
            'quantity': 10,
            'state': 'active',
            'views': 10,
            'materials': ['gold'],
            'users': 1,
            'original_creation_tsz': now,
        }

        score_listing(listing1)
        score_listing(listing2)
        score_listing(listing3)

        assert r.zscore('treasures', '1') < r.zscore('treasures', '2')
        assert r.zscore('treasures', '2') < r.zscore('treasures', '3')
コード例 #2
0
    def test_score_decays_with_age(self):
        """Should score older things lower."""
        now = time.time()

        listing1 = {
            'listing_id': 1,
            'quantity': 1,
            'state': 'active',
            'views': 9000,
            'materials': [],
            'users': 4,
            'original_creation_tsz': str(now),
        }

        listing2 = {
            'listing_id': 2,
            'quantity': 1,
            'state': 'active',
            'views': 9000,
            'materials': [],
            'users': 4,
            'original_creation_tsz': str(now - 100),
        }

        listing3 = {
            'listing_id': 3,
            'quantity': 1,
            'state': 'active',
            'views': 9000,
            'materials': [],
            'users': 4,
            'original_creation_tsz': str(now - 500),
        }

        score_listing(listing1) 
        score_listing(listing2)
        score_listing(listing3)

        assert r.zscore('treasures', '1') > r.zscore('treasures', '2')
        assert r.zscore('treasures', '2') > r.zscore('treasures', '3')
コード例 #3
0
    def test_never_negative(self):
        """Event the oldest things shouldn't have negative scores."""
        score_listing({
            'listing_id': 1,
            'quantity': 1,
            'state': 'active',
            'views': 9000,
            'materials': [],
            'users': 4,
            'original_creation_tsz': '1',
        })

        assert r.zscore('treasures', '1') > 0