Loggedin spotlight: pick winner in advance.

This commit is contained in:
bsimpson63
2013-02-25 16:14:40 -05:00
parent 94a7ee0eb9
commit c15a87be86
2 changed files with 30 additions and 16 deletions

View File

@@ -283,19 +283,27 @@ class HotController(FixListing, ListingController):
organic_fullnames.extend(g.live_config['sr_discovery_links'])
n_promoted = 100
n_build = 10
promo_tuples = promote.sample_promoted_links(c.user, c.site,
n=n_promoted)
promo_tuples = sorted(promo_tuples,
key=lambda p: p.weight,
reverse=True)
promo_build = promo_tuples[:n_build]
promo_stub = promo_tuples[n_build:]
b = CampaignBuilder(promo_build,
wrap=self.builder_wrapper,
keep_fn=promote.is_promoted)
promoted_links = b.get_items()[0]
promoted_links.extend(promo_stub)
n_build = 1 if c.user_is_loggedin else 10
picker = (promote.lottery_promoted_links if c.user_is_loggedin else
promote.sample_promoted_links)
promo_tuples = picker(c.user, c.site, n=n_promoted)
if not c.user_is_loggedin:
promo_tuples.sort(key=lambda t: t.weight, reverse=True)
b = CampaignBuilder(
promo_tuples,
wrap=self.builder_wrapper,
keep_fn=organic.keep_fresh_links,
num=n_build,
skip=True,
)
promoted_links, first, last, before, after = b.get_items()
if promoted_links and last:
lookup = {t.campaign: i for i, t in enumerate(promo_tuples)}
last_index = lookup[last.campaign]
stubs = promo_tuples[last_index + 1:]
promoted_links.extend(stubs)
if not (organic_fullnames or promoted_links):
return None
@@ -321,7 +329,8 @@ class HotController(FixListing, ListingController):
interestbar_prob=interestbar_prob,
promotion_prob=promotion_prob,
max_num = self.listing_obj.max_num,
max_score = self.listing_obj.max_score).listing()
max_score = self.listing_obj.max_score,
predetermined_winner=c.user_is_loggedin).listing()
return s
def query(self):

View File

@@ -144,6 +144,7 @@ class SpotlightListing(Listing):
promoted_links = kw.get('promoted_links', [])
organic_links = kw.get('organic_links', [])
predetermined_winner = kw.get('predetermined_winner', False)
self.links = []
for l in organic_links:
@@ -157,14 +158,18 @@ class SpotlightListing(Listing):
)
total = sum(float(l.weight) for l in promoted_links)
for l in promoted_links:
for i, l in enumerate(promoted_links):
link = l._fullname if isinstance(l, Wrapped) else l.link
if predetermined_winner:
weight = 1 if i == 0 else 0
else:
weight = l.weight / total
self.links.append(
SpotlightTuple(
link=link,
is_promo=True,
campaign=l.campaign,
weight=l.weight / total,
weight=weight,
)
)