当前位置: 首页>>代码示例>>Python>>正文


Python func.random方法代码示例

本文整理汇总了Python中sqlalchemy.sql.expression.func.random方法的典型用法代码示例。如果您正苦于以下问题:Python func.random方法的具体用法?Python func.random怎么用?Python func.random使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.sql.expression.func的用法示例。


在下文中一共展示了func.random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_archived_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_archived_books(page, order):
    order = order or []
    archived_books = (
        ub.session.query(ub.ArchivedBook)
        .filter(ub.ArchivedBook.user_id == int(current_user.id))
        .filter(ub.ArchivedBook.is_archived == True)
        .all()
    )
    archived_book_ids = [archived_book.book_id for archived_book in archived_books]

    archived_filter = db.Books.id.in_(archived_book_ids)

    entries, random, pagination = calibre_db.fill_indexpage_with_archived_books(page,
                                                                                db.Books,
                                                                                archived_filter,
                                                                                order,
                                                                                allow_show_archived=True)

    name = _(u'Archived Books') + ' (' + str(len(archived_book_ids)) + ')'
    pagename = "archived"
    return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
                                 title=name, page=pagename)

# ################################### Download/Send ################################################################## 
开发者ID:janeczku,项目名称:calibre-web,代码行数:26,代码来源:web.py

示例2: index

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def index():
    sorter = request.args.get("sorter", None)
    if sorter is None:
        sorter = "random"
        initial_sorting = True
    else:
        initial_sorting = False
    order = request.args.get("order", None)
    criterion = SORTER.get(sorter, DEFAULT_SORTER)
    if order == DEFAULT_ORDER:
        criterion = desc(criterion)

    projects = Project.query.filter(Project.is_active.is_(True)).order_by(
        nullslast(criterion)
    )
    return {
        "projects": projects,
        "sorter": sorter,
        "initial_sorting": initial_sorting,
        "order": order,
        "DEFAULT_ORDER": DEFAULT_ORDER,
    } 
开发者ID:jazzband-roadies,项目名称:website,代码行数:24,代码来源:views.py

示例3: hello

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def hello(self, ctx):
		"""Says hello

		WHAT MORE DO YOU NEED TO KNOW!?!?!? IS 'Says hello' REALLY NOT CLEAR ENOUGH FOR YOU!?!!11?!!?11!!?!??"""
		dota_hellos = [
			"slark_attack_11",
			"kunk_thanks_02",
			"meepo_scepter_06",
			"puck_ability_orb_03",
			"tink_spawn_07",
			"treant_ally_08",
			"wraith_lasthit_02",
			"timb_deny_08",
			"tech_pain_39",
			"meepo_attack_08",
			"slark_lasthit_02"
		]
		dota_response = random.choice(dota_hellos)
		response = session.query(Response).filter(Response.name == dota_response).first()
		print("hello: " + response.name)
		await self.play_response(response, ctx)

	# Plays the correct command for the given keyphrase and hero, if a valid one is given 
开发者ID:mdiller,项目名称:MangoByte,代码行数:25,代码来源:dotabase.py

示例4: build_comment

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def build_comment(self):
        comment = ""
        while True:
            # For each sentence, check how close to the average comment length
            # we are, then use the remaining percentage as the chance of
            # adding another sentence. For example, if we're at 70% of the
            # average comment length, there will be a 30% chance of adding
            # another sentence. We're also adding a fixed 10% on top of that
            # just to increase the length a little, and have some chance of
            # continuing once we're past the average.
            portion_done = len(comment) / float(self.avg_comment_len)
            continue_chance = 1.0 - portion_done
            continue_chance = max(0, continue_chance)
            continue_chance += 0.1
            if random.random() > continue_chance:
                break

            new_sentence = self.make_comment_sentence()
            comment += " " + new_sentence

        comment = comment.strip()
        
        return comment 
开发者ID:Deimos,项目名称:SubredditSimulator,代码行数:25,代码来源:models.py

示例5: post_comment_on

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def post_comment_on(self, submission):
        comment = self.build_comment()

        # decide if we're going to post top-level or reply
        if (submission.num_comments == 0 or
                random.random() < 0.5):
            submission.add_comment(comment)
        else:
            comments = praw.helpers.flatten_tree(submission.comments)
            reply_to = random.choice(comments)
            reply_to.reply(comment)

        # update the database
        self.last_commented = datetime.now(pytz.utc)
        self.num_comments += 1
        db.add(self)
        db.commit() 
开发者ID:Deimos,项目名称:SubredditSimulator,代码行数:19,代码来源:models.py

示例6: create_order_line

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def create_order_line(order, discounts):
    product = Product.query.order_by(func.random()).first()
    variant = product.variant[0]
    quantity = random.randrange(1, 5)
    variant.quantity += quantity
    variant.save()
    return OrderLine.create(
        order_id=order.id,
        product_name=variant.display_product(),
        product_sku=variant.sku,
        product_id=variant.sku.split("-")[0],
        is_shipping_required=variant.is_shipping_required,
        quantity=quantity,
        variant_id=variant.id,
        unit_price_net=variant.price,
    )


# step27 
开发者ID:hjlarry,项目名称:flask-shop,代码行数:21,代码来源:random_data.py

示例7: action_acquire_random_ready

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def action_acquire_random_ready(context, owner, timestamp):
    with session_for_write() as session:
        action = (session.query(models.Action).
                  filter_by(status=consts.ACTION_READY).
                  filter_by(owner=None).
                  order_by(func.random()).
                  with_for_update().first())

        if action:
            action.owner = owner
            action.start_time = timestamp
            action.status = consts.ACTION_RUNNING
            action.status_reason = 'The action is being processed.'
            action.save(session)

            return action 
开发者ID:openstack,项目名称:senlin,代码行数:18,代码来源:api.py

示例8: GetTextCorpus

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def GetTextCorpus(self, shuffle: bool) -> str:
    """Concatenate the entire corpus into a string.

    Args:
      shuffle: If true, randomize order of contentfiles.

    Returns:
      A concatenated corpus string.
    """
    with self.preprocessed.Session() as session:
      query = session.query(preprocessed.PreprocessedContentFile.text).filter(
        preprocessed.PreprocessedContentFile.preprocessing_succeeded == True
      )
      if shuffle:
        query = query.order_by(func.random())
      return self.config.contentfile_separator.join([x[0] for x in query]) 
开发者ID:ChrisCummins,项目名称:clgen,代码行数:18,代码来源:corpuses.py

示例9: index

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def index(page):
    entries, random, pagination = calibre_db.fill_indexpage(page, db.Books, True, [db.Books.timestamp.desc()])
    return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
                                 title=_(u"Recently Added Books"), page="root") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:6,代码来源:web.py

示例10: render_hot_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_hot_books(page):
    if current_user.check_visibility(constants.SIDEBAR_HOT):
        if current_user.show_detail_random():
            random = calibre_db.session.query(db.Books).filter(calibre_db.common_filters()) \
                .order_by(func.random()).limit(config.config_random_books)
        else:
            random = false()
        off = int(int(config.config_books_per_page) * (page - 1))
        all_books = ub.session.query(ub.Downloads, func.count(ub.Downloads.book_id)).order_by(
            func.count(ub.Downloads.book_id).desc()).group_by(ub.Downloads.book_id)
        hot_books = all_books.offset(off).limit(config.config_books_per_page)
        entries = list()
        for book in hot_books:
            downloadBook = calibre_db.session.query(db.Books).filter(calibre_db.common_filters()).filter(
                db.Books.id == book.Downloads.book_id).first()
            if downloadBook:
                entries.append(downloadBook)
            else:
                ub.delete_download(book.Downloads.book_id)
                # ub.session.query(ub.Downloads).filter(book.Downloads.book_id == ub.Downloads.book_id).delete()
                # ub.session.commit()
        numBooks = entries.__len__()
        pagination = Pagination(page, config.config_books_per_page, numBooks)
        return render_title_template('index.html', random=random, entries=entries, pagination=pagination,
                                     title=_(u"Hot Books (Most Downloaded)"), page="hot")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:29,代码来源:web.py

示例11: render_publisher_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_publisher_books(page, book_id, order):
    publisher = calibre_db.session.query(db.Publishers).filter(db.Publishers.id == book_id).first()
    if publisher:
        entries, random, pagination = calibre_db.fill_indexpage(page,
                                                                db.Books,
                                                                db.Books.publishers.any(db.Publishers.id == book_id),
                                                                [db.Series.name, order[0], db.Books.series_index],
                                                                db.books_series_link,
                                                                db.Series)
        return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
                                     title=_(u"Publisher: %(name)s", name=publisher.name), page="publisher")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:15,代码来源:web.py

示例12: render_series_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_series_books(page, book_id, order):
    name = calibre_db.session.query(db.Series).filter(db.Series.id == book_id).first()
    if name:
        entries, random, pagination = calibre_db.fill_indexpage(page,
                                                                db.Books,
                                                                db.Books.series.any(db.Series.id == book_id),
                                                                [db.Books.series_index, order[0]])
        return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
                                     title=_(u"Series: %(serie)s", serie=name.name), page="series")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:13,代码来源:web.py

示例13: render_formats_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_formats_books(page, book_id, order):
    name = calibre_db.session.query(db.Data).filter(db.Data.format == book_id.upper()).first()
    if name:
        entries, random, pagination = calibre_db.fill_indexpage(page,
                                                                db.Books,
                                                                db.Books.data.any(db.Data.format == book_id.upper()),
                                                                [db.Books.timestamp.desc(), order[0]])
        return render_title_template('index.html', random=random, pagination=pagination, entries=entries, id=book_id,
                                     title=_(u"File format: %(format)s", format=name.format), page="formats")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:13,代码来源:web.py

示例14: render_category_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_category_books(page, book_id, order):
    name = calibre_db.session.query(db.Tags).filter(db.Tags.id == book_id).first()
    if name:
        entries, random, pagination = calibre_db.fill_indexpage(page,
                                                                db.Books,
                                                                db.Books.tags.any(db.Tags.id == book_id),
                                                                [order[0], db.Series.name, db.Books.series_index],
                                                                db.books_series_link, db.Series)
        return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=book_id,
                                     title=_(u"Category: %(name)s", name=name.name), page="category")
    else:
        abort(404) 
开发者ID:janeczku,项目名称:calibre-web,代码行数:14,代码来源:web.py

示例15: render_language_books

# 需要导入模块: from sqlalchemy.sql.expression import func [as 别名]
# 或者: from sqlalchemy.sql.expression.func import random [as 别名]
def render_language_books(page, name, order):
    try:
        cur_l = LC.parse(name)
        lang_name = cur_l.get_language_name(get_locale())
    except UnknownLocaleError:
        try:
            lang_name = _(isoLanguages.get(part3=name).name)
        except KeyError:
            abort(404)
    entries, random, pagination = calibre_db.fill_indexpage(page,
                                                            db.Books,
                                                            db.Books.languages.any(db.Languages.lang_code == name),
                                                            [db.Books.timestamp.desc(), order[0]])
    return render_title_template('index.html', random=random, entries=entries, pagination=pagination, id=name,
                                 title=_(u"Language: %(name)s", name=lang_name), page="language") 
开发者ID:janeczku,项目名称:calibre-web,代码行数:17,代码来源:web.py


注:本文中的sqlalchemy.sql.expression.func.random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。