Skip to content
Browse files

Stop get_promotions_cached from combining campaigns on same link.

  • Loading branch information...
1 parent 7398916 commit 8075fa83c3a98baa8ef17a26b41db1a743c7a3e4 @bsimpson63 bsimpson63 committed Jan 30, 2013
Showing with 14 additions and 15 deletions.
  1. +14 −15 r2/r2/lib/promote.py
View
29 r2/r2/lib/promote.py
@@ -802,23 +802,22 @@ def get_promotion_list(user, site):
def get_promotions_cached(sites):
weights = get_live_promotions(sites)
- if weights:
- available = {}
- campaigns = {}
- for sr_id, sr_weights in weights.iteritems():
- if sr_id in sites:
- for l, w, cid in sr_weights:
- available[l] = available.get(l, 0) + w
- campaigns[l] = cid
- # sort the available list by weight
- links = available.keys()
- links.sort(key=lambda x: -available[x])
- norm = sum(available.values())
- # return a sorted list of (link, norm_weight)
- return [(l, available[l] / norm, campaigns[l]) for l in links]
- else:
+ if not weights:
return []
+ promos = []
+ total = 0.
+ for sr_id, sr_weights in weights.iteritems():
+ if sr_id not in sites:
+ continue
+ for link, weight, campaign in sr_weights:
+ total += weight
+ promos.append((link, weight, campaign))
+
+ return [(link, weight / total, campaign)
+ for link, weight, campaign in promos]
+
+
def randomized_promotion_list(user, site):
promos = get_promotion_list(user, site)
# no promos, no problem

0 comments on commit 8075fa8

Please sign in to comment.
Something went wrong with that request. Please try again.