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


Python func.count方法代码示例

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


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

示例1: _validate_unique_container_name

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def _validate_unique_container_name(self, context, name):
        if not CONF.compute.unique_container_name_scope:
            return
        lowername = name.lower()
        base_query = model_query(models.Container).\
            filter(func.lower(models.Container.name) == lowername)
        if CONF.compute.unique_container_name_scope == 'project':
            container_with_same_name = base_query.\
                filter_by(project_id=context.project_id).count()
        elif CONF.compute.unique_container_name_scope == 'global':
            container_with_same_name = base_query.count()
        else:
            return

        if container_with_same_name > 0:
            raise exception.ContainerAlreadyExists(field='name',
                                                   value=lowername) 
开发者ID:openstack,项目名称:zun,代码行数:19,代码来源:api.py

示例2: exposed_db_count_netlocs

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def exposed_db_count_netlocs():
	'''
	Select and count the number of instances for each netloc in
	the database.

	Returns the netlocs sorted by count in decending order.
	'''

	with db.session_context() as sess:
		q = sess.query(db.WebPages.netloc, func.count(db.WebPages.netloc).label("count")) \
			.group_by(db.WebPages.netloc)\
			.order_by(desc(func.count(db.WebPages.netloc)))
		print("Doing query.")
		res = q.all()
		res = list(res)
		for row in res:
			print("Row: ", row)

		with open("nl_counts.json", "w") as fp:
			json.dump(res, fp) 
开发者ID:fake-name,项目名称:ReadableWebProxy,代码行数:22,代码来源:WebMirrorManage.py

示例3: _get_issues_by_account

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def _get_issues_by_account(self):
        acct_alias = aliased(IssueProperty)

        issues = (
            db.query(func.count(Issue.issue_id), Account.account_name)
                .join(acct_alias, Issue.issue_id == acct_alias.issue_id)
                .join(Account, acct_alias.value == Account.account_id)
                .filter(
                Account.account_type_id == aws_account_type_id,
                Account.enabled == 1,
                Issue.issue_type_id == reqtag_type_id,
                acct_alias.name == 'account_id'
            )
                .group_by(Account.account_name)
                .all()
        )

        return defaultdict(int, map(reversed, issues)) 
开发者ID:RiotGames,项目名称:cloud-inquisitor,代码行数:20,代码来源:stats.py

示例4: __getitem__

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def __getitem__(self,key):
        if isinstance(key, slice):
            start, stop, step = key.start, key.stop, key.step
            if step != None:
                raise IndexError("SQL backend dos not support steps in slices")
            if key.start == None:
                start = 0
            if key.stop == None:
                stop = len(self)
            if start < 0:
                start = len(self) + start
            if stop < 0:
                stop = len(self) + stop
            qs = copy.copy(self)
            if start:
                qs.offset(start)
            qs.limit(stop-start)
            qs.objects = None
            qs.count = None
            return qs
        if self.deserialized_objects is None:
            self.get_deserialized_objects()
        return self.deserialized_objects[key] 
开发者ID:adewes,项目名称:blitzdb,代码行数:25,代码来源:queryset.py

示例5: append

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def append(self,obj):
        with self.obj.backend.transaction(implicit = True):

            #if the object is not yet in a DB, we save it first.

            if obj.pk is None:
                self.obj.backend.save(obj)

            relationship_table = self.params['relationship_table']
            condition = and_(relationship_table.c[self.params['related_pk_field_name']] == obj.pk,
                             relationship_table.c[self.params['pk_field_name']] == self.obj.pk)
            s = select([func.count(text('*'))]).where(condition)
            result = self.obj.backend.connection.execute(s)
            cnt = result.first()[0]
            if cnt:
                return #the object is already inside
            values = {
                self.params['pk_field_name'] : self.obj.pk,
                self.params['related_pk_field_name'] : obj.pk
            }
            insert = relationship_table.insert().values(**values)
            self.obj.backend.connection.execute(insert)
            self._queryset = None 
开发者ID:adewes,项目名称:blitzdb,代码行数:25,代码来源:relations.py

示例6: stats

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def stats(self, survey_id):
        """Get stats for a survey."""
        result = (
            self.session
            .query(
                func.max(Survey.created_on),
                func.min(Submission.save_time),
                func.max(Submission.save_time),
                func.count(Submission.id),
            )
            .select_from(Submission)
            .join(Survey)
            # TODO: ask @jmwohl what this line is supposed to do
            # .filter(User.id == self.current_user_model.id)
            .filter(Submission.survey_id == survey_id)
            .one()
        )

        response = {
            "created_on": result[0],
            "earliest_submission_time": result[1],
            "latest_submission_time": result[2],
            "num_submissions": result[3]
        }
        return response 
开发者ID:SEL-Columbia,项目名称:dokomoforms,代码行数:27,代码来源:surveys.py

示例7: _get_project_quota_usages

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def _get_project_quota_usages(context, session, project_id):
    rows = (model_query(context, models.QuotaUsage,
                        read_deleted="no",
                        session=session).
            filter_by(project_id=project_id).
            filter(models.QuotaUsage.share_type_id is None).
            with_lockmode('update').
            all())
    result = dict()
    # Get the total count of in_use,reserved
    for row in rows:
        if row.resource in result:
            result[row.resource]['in_use'] += row.in_use
            result[row.resource]['reserved'] += row.reserved
            result[row.resource]['total'] += (row.in_use + row.reserved)
        else:
            result[row.resource] = dict(in_use=row.in_use,
                                        reserved=row.reserved,
                                        total=row.in_use + row.reserved)
    return result 
开发者ID:openstack,项目名称:manila,代码行数:22,代码来源:api.py

示例8: share_delete

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def share_delete(context, share_id):
    session = get_session()

    with session.begin():
        share_ref = share_get(context, share_id, session)

        if len(share_ref.instances) > 0:
            msg = _("Share %(id)s has %(count)s share instances.") % {
                'id': share_id, 'count': len(share_ref.instances)}
            raise exception.InvalidShare(msg)

        share_ref.soft_delete(session=session)

        (session.query(models.ShareMetadata).
            filter_by(share_id=share_id).soft_delete())


################### 
开发者ID:openstack,项目名称:manila,代码行数:20,代码来源:api.py

示例9: snapshot_data_get_for_project

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def snapshot_data_get_for_project(context, project_id, user_id,
                                  share_type_id=None, session=None):
    query = (model_query(context, models.ShareSnapshot,
                         func.count(models.ShareSnapshot.id),
                         func.sum(models.ShareSnapshot.size),
                         read_deleted="no",
                         session=session).
             filter_by(project_id=project_id))

    if share_type_id:
        query = query.join(
            models.ShareInstance,
            models.ShareInstance.share_id == models.ShareSnapshot.share_id,
        ).filter_by(share_type_id=share_type_id)
    elif user_id:
        query = query.filter_by(user_id=user_id)
    result = query.first()

    return result[0] or 0, result[1] or 0 
开发者ID:openstack,项目名称:manila,代码行数:21,代码来源:api.py

示例10: share_replica_data_get_for_project

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def share_replica_data_get_for_project(context, project_id, user_id=None,
                                       session=None, share_type_id=None):
    session = session or get_session()
    query = model_query(
        context, models.ShareInstance,
        func.count(models.ShareInstance.id),
        func.sum(models.Share.size),
        read_deleted="no",
        session=session).join(
        models.Share,
        models.ShareInstance.share_id == models.Share.id).filter(
        models.Share.project_id == project_id).filter(
        models.ShareInstance.replica_state.isnot(None))

    if share_type_id:
        query = query.filter(
            models.ShareInstance.share_type_id == share_type_id)
    elif user_id:
        query = query.filter(models.Share.user_id == user_id)

    result = query.first()
    return result[0] or 0, result[1] or 0 
开发者ID:openstack,项目名称:manila,代码行数:24,代码来源:api.py

示例11: fairness_chart

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def fairness_chart(self):
        query = db.session.query(
            Fairness.name.label('t'),
            func.count(distinct(DocumentFairness.doc_id))
        )\
            .join(DocumentFairness)\
            .join(Document, DocumentFairness.doc_id == Document.id)\
            .group_by('t')

        rows = self.filter(query).all()
        counts = dict(rows)
        counts.setdefault('Fair', 0)

        # missing documents are considered fair
        counts['Fair'] += len(self.doc_ids) - sum(counts.itervalues())

        return {
            'values': counts
        } 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:21,代码来源:dashboard.py

示例12: count_utterances

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def count_utterances(self, ids):
        """
        Return dict from person ID to number of utterances they had in
        these documents.
        """
        rows = db.session.query(
                Person.id,
                func.count(1).label('count')
                )\
                .join(Entity, Entity.person_id == Person.id)\
                .join(Utterance, Utterance.entity_id == Entity.id)\
                .filter(Utterance.doc_id.in_(self.doc_ids))\
                .filter(Person.id.in_(ids))\
                .group_by(Person.id)\
                .all()

        return dict((p[0], p[1]) for p in rows) 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:19,代码来源:sources.py

示例13: origin_worksheet

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def origin_worksheet(self, wb):
        from dexter.models.views import DocumentsView

        ws = wb.add_worksheet('origins')

        query = db.session.query(
            DocumentsView.c.origin,
            func.count(1).label('count')
        )\
            .join(Document)\
            .group_by('origin')
        rows = self.filter(query).all()
        rownum = 3 + self.write_table(ws, 'Origins', rows)

        query = db.session.query(
            DocumentsView.c.origin_group,
            func.count(1).label('count')
        )\
            .join(Document)\
            .group_by('origin_group')
        rows = self.filter(query).all()
        self.write_table(ws, 'OriginGroups', rows, rownum=rownum) 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:24,代码来源:xlsx_export.py

示例14: topic_worksheet

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def topic_worksheet(self, wb):
        from dexter.models.views import DocumentsView

        ws = wb.add_worksheet('topics')

        # topic groups
        rows = self.filter(
            db.session.query(
                DocumentsView.c.topic_group,
                func.count(1).label('count')
            )
            .join(Document)
            .group_by('topic_group')).all()
        rownum = 3 + self.write_table(ws, 'TopicGroups', rows)

        # topics
        rows = self.filter(
            db.session.query(
                DocumentsView.c.topic,
                func.count(1).label('count')
            )
            .join(Document)
            .group_by('topic')).all()
        self.write_table(ws, 'Topics', rows, rownum=rownum) 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:26,代码来源:xlsx_export.py

示例15: age_scores

# 需要导入模块: from sqlalchemy.sql import func [as 别名]
# 或者: from sqlalchemy.sql.func import count [as 别名]
def age_scores(self, row):
        """ Counts of source ages per medium, and their entropy. """
        self.scores_ws.write(row, 0, 'Child Ages')

        rows = self.filter(
            db.session.query(
                Medium.name,
                SourceAge.name,
                func.count(1).label('freq'))
            .join(Document)
            .join(DocumentSource)
            .join(SourceAge)
            .filter(DocumentSource.source_type == 'child')
            .group_by(Medium.name, SourceAge.name)
            .order_by(Medium.name)
        ).all()

        ages = list(set(r[1] for r in rows))
        ages.sort()

        row = self.write_score_table(ages, rows, row) + 1
        self.write_simple_score_row('Diversity of Ages', self.entropy(rows), row)

        return row 
开发者ID:Code4SA,项目名称:mma-dexter,代码行数:26,代码来源:ratings.py


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