def extract_popularity_trending_boost(cls, obj): # 0 is a special region when considering popularity/trending, it's the # one holding the global value. ALL_REGIONS_ID = 0 def get_dict(obj, prop): if obj.is_dummy_content_for_qa(): return {} qs = getattr(obj, prop).filter(region__in=MATURE_REGION_IDS + [ALL_REGIONS_ID]) return dict(qs.values_list('region', 'value')) extend = { 'boost': get_boost(obj), } trending = get_dict(obj, 'trending') popularity = get_dict(obj, 'popularity') # Global popularity. extend['trending'] = trending.get(ALL_REGIONS_ID, 0) extend['popularity'] = popularity.get(ALL_REGIONS_ID, 0) # For all mature regions, store in ES the value from the queries we # made, or 0 if none was found. As in the # attach_trending_and_popularity_mappings() method above, no neeed to # store anything for the adolescent regions. for region_id in MATURE_REGION_IDS: extend['trending_%s' % region_id] = trending.get(region_id, 0) extend['popularity_%s' % region_id] = popularity.get(region_id, 0) return extend
def extract_popularity_trending_boost(cls, obj): # 0 is a special region when considering popularity/trending, it's the # one holding the global value. ALL_REGIONS_ID = 0 def get_dict(obj, prop): if obj.is_dummy_content_for_qa(): return {} qs = getattr(obj, prop).filter( region__in=MATURE_REGION_IDS + [ALL_REGIONS_ID]) return dict(qs.values_list('region', 'value')) extend = { 'boost': get_boost(obj), } trending = get_dict(obj, 'trending') popularity = get_dict(obj, 'popularity') # Global popularity. extend['trending'] = trending.get(ALL_REGIONS_ID, 0) extend['popularity'] = popularity.get(ALL_REGIONS_ID, 0) # For all mature regions, store in ES the value from the queries we # made, or 0 if none was found. As in the # attach_trending_and_popularity_mappings() method above, no neeed to # store anything for the adolescent regions. for region_id in MATURE_REGION_IDS: extend['trending_%s' % region_id] = trending.get(region_id, 0) extend['popularity_%s' % region_id] = popularity.get(region_id, 0) return extend
def extract_popularity_trending_boost(cls, obj): extend = { 'boost': get_boost(obj), 'popularity': get_popularity(obj), 'trending': get_trending(obj) } for region in mkt.regions.ALL_REGIONS: extend['trending_%s' % region.id] = get_trending(obj, region) extend['popularity_%s' % region.id] = get_popularity(obj, region) return extend
def test_installs_to_popularity(self): # No installs. obj, doc = self._get_doc() # Boost is multiplied by 4 if it's public. eq_(doc['boost'], 1 * 4) eq_(doc['popularity'], 0) # Many installs. self.app.popularity.create(region=0, value=50.0) # Test an adolescent region. self.app.popularity.create(region=2, value=10.0) # Test a mature region. self.app.popularity.create(region=7, value=10.0) obj, doc = self._get_doc() eq_(doc['boost'], get_boost(self.app)) eq_(doc['popularity'], 50) eq_(doc['popularity_7'], 10) # Adolescent regions popularity value is not stored. ok_('popularity_2' not in doc)
def test_installs_to_popularity(self): # No installs. obj, doc = self._get_doc() # Boost is multiplied by 4 if it's public. eq_(doc['boost'], 1 * 4) eq_(doc['popularity'], 0) # Many installs. self.app.popularity.create(region=0, value=50.0) # Test an adolescent region. self.app.popularity.create(region=2, value=10.0) # Test a mature region. self.app.popularity.create(region=7, value=10.0) obj, doc = self._get_doc() eq_(doc['boost'], get_boost(self.app)) eq_(doc['popularity'], 50) # An adolescent region uses the global trending value. eq_(doc['popularity_2'], 50) eq_(doc['popularity_7'], 10)
def test_installs_to_popularity(self): # No installs. obj, doc = self._get_doc() # Boost is multiplied by BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT if it's # public. eq_(doc['boost'], 1 * BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT) eq_(doc['popularity'], 0) # Many installs. self.app.popularity.create(region=0, value=50.0) # Test an adolescent region. self.app.popularity.create(region=2, value=10.0) # Test a mature region. self.app.popularity.create(region=42, value=10.0) obj, doc = self._get_doc() eq_(doc['boost'], get_boost(self.app)) eq_(doc['popularity'], 50) eq_(doc['popularity_42'], 10) # Adolescent regions popularity value is not stored. ok_('popularity_2' not in doc)
def test_installs_to_popularity(self): self.obj = website_factory() # No installs. doc = self._get_doc() # Boost is multiplied by 4 if it's public. eq_(doc['boost'], 1.0 * 4) eq_(doc['popularity'], 0) # Add some popularity. self.obj.popularity.create(region=0, value=50.0) # Test an adolescent region. self.obj.popularity.create(region=2, value=10.0) # Test a mature region. self.obj.popularity.create(region=7, value=10.0) doc = self._get_doc() eq_(doc['boost'], get_boost(self.obj)) eq_(doc['popularity'], 50) eq_(doc['popularity_7'], 10) # Adolescent regions popularity value is not stored. ok_('popularity_2' not in doc)
def test_installs_to_popularity(self): self.obj = website_factory() # No installs. doc = self._get_doc() # Boost is multiplied by 4 if it's public. eq_(doc["boost"], 1.0 * 4) eq_(doc["popularity"], 0) # Add some popularity. self.obj.popularity.create(region=0, value=50.0) # Test an adolescent region. self.obj.popularity.create(region=2, value=10.0) # Test a mature region. self.obj.popularity.create(region=7, value=10.0) doc = self._get_doc() eq_(doc["boost"], get_boost(self.obj)) eq_(doc["popularity"], 50) # An adolescent region uses the global trending value. eq_(doc["popularity_2"], 50) eq_(doc["popularity_7"], 10)
def test_popularity(self): extension, version = self._extension_factory() # No installs. doc = self._get_doc(extension) # Boost is multiplied by BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT if it's # public. eq_(doc['boost'], 1.0 * BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT) eq_(doc['popularity'], 0) # Add some popularity. extension.popularity.create(region=0, value=50.0) # Test an adolescent region. extension.popularity.create(region=2, value=10.0) # Test a mature region. extension.popularity.create(region=42, value=10.0) doc = self._get_doc(extension) eq_(doc['boost'], get_boost(extension)) eq_(doc['popularity'], 50) eq_(doc['popularity_42'], 10) # Adolescent regions popularity value is not stored. ok_('popularity_2' not in doc)
def test_installs_to_popularity(self): self.obj = website_factory() # No installs. doc = self._get_doc() # Boost is multiplied by BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT if it's # public. eq_(doc["boost"], 1.0 * BOOST_MULTIPLIER_FOR_PUBLIC_CONTENT) eq_(doc["popularity"], 0) # Add some popularity. self.obj.popularity.create(region=0, value=50.0) # Test an adolescent region. self.obj.popularity.create(region=2, value=10.0) # Test a mature region. self.obj.popularity.create(region=42, value=10.0) doc = self._get_doc() eq_(doc["boost"], get_boost(self.obj)) eq_(doc["popularity"], 50) eq_(doc["popularity_42"], 10) # Adolescent regions popularity value is not stored. ok_("popularity_2" not in doc)
def test_get_boost_website(self): website = website_factory() website.popularity.create(region=0, value=1000.0) eq_(get_boost(website), log10(1 + 1000) * 4)
def test_get_boost_app_not_approved(self): app = app_factory(status=STATUS_REJECTED) app.popularity.create(region=0, value=1000.0) eq_(get_boost(app), log10(1 + 1000))
def test_get_boost_app(self): app = app_factory() app.popularity.create(region=0, value=1000.0) eq_(get_boost(app), log10(1 + 1000) * 4)