Beispiel #1
0
 def _load(isbn):
     """ Loading from datastore. """
     return BookRelated.get_by_user_isbn(user, isbn,
                                         load_booklist_related=False,
                                         load_rating=False,
                                         load_tags=False,
                                         load_comment=False)
Beispiel #2
0
    def _prepare_next(self, ctx, user, bl):
        """ Generate the recommendation results (at most 3) for reading next.
            @param ctx: the {} object to fill and render onto page.
            @param user: the corresponding user.
            @param bl: the Interested list (not empty).
        """
        r = random.random()
        if r <= 0.15:
            # 15% chances to randomly pick three...
            ctx['reason'] = "randomly picked"
            result_isbns = self._all_random(bl)
        elif r > 0.15 and r <= 0.3:
            # 15% chances to recommend books recently added as interested
            ctx['reason'] = "recently added"
            result_isbns = self._recently_added(bl, user)
        else:
            # 70% chances to calculate each book's score and recommend the highest ones
            ctx['reason'] = "praised by others"
            result_isbns = self._being_praised(user)

        raw_src = [BookRelated.get_by_user_isbn(user, isbn, load_comment=False) for isbn in result_isbns]
        # put those in TJ library first
        in_tj = []
        not_in_tj = []
        for src in raw_src:
            if src.book.is_tongji_linked():
                in_tj.append(src)
            else:
                not_in_tj.append(src)
        ctx['next_books'] = in_tj + not_in_tj

        ctx['list_amount'] = bl.size()
        ctx['picked_amount'] = len(ctx['next_books'])
        return