本文整理汇总了Python中addons.models.AddonRecommendation类的典型用法代码示例。如果您正苦于以下问题:Python AddonRecommendation类的具体用法?Python AddonRecommendation怎么用?Python AddonRecommendation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AddonRecommendation类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scores
def test_scores(self):
ids = [5299, 1843, 2464, 7661, 5369]
scores = AddonRecommendation.scores(ids)
q = AddonRecommendation.objects.filter(addon__in=ids)
for addon, recs in itertools.groupby(q, lambda x: x.addon_id):
for rec in recs:
eq_(scores[addon][rec.other_addon_id], rec.score)
示例2: build_recs
def build_recs(cls, addon_ids):
"""Get the top ranking add-ons according to recommendation scores."""
scores = AddonRecommendation.scores(addon_ids)
d = collections.defaultdict(int)
for others in scores.values():
for addon, score in others.items():
d[addon] += score
addons = sorted(d.items(), key=lambda x: x[1], reverse=True)
return [addon for addon, score in addons if addon not in addon_ids]
示例3: build_recs
def build_recs(cls, addon_ids):
"""Get the top ranking add-ons according to recommendation scores."""
scores = AddonRecommendation.scores(addon_ids)
d = collections.defaultdict(int)
for others in scores.values():
for addon, score in others.items():
d[addon] += score
addons = [(score, addon) for addon, score in d.items()]
return [addon for _, addon in sorted(addons)]
示例4: expected_recs
def expected_recs(self):
scores, ranked = [], {}
# Get all the add-on => rank pairs.
for x in AddonRecommendation.scores(self.ids).values():
scores.extend(x.items())
# Sum up any dupes.
groups = itertools.groupby(sorted(scores), key=lambda x: x[0])
for addon, pairs in groups:
ranked[addon] = sum(x[1] for x in pairs)
addons = sorted(ranked.items(), key=lambda x: x[1], reverse=True)
return [x[0] for x in addons if x[0] not in self.ids]