Python sqlalchemy 模块,asc() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.asc()

项目:sqlakeyset    作者:djrobstep    | 项目源码 | 文件源码
def test_oc():
    a = asc('a')
    b = desc('a')
    c = asc('b')
    n = nullslast(desc('a'))

    a = OC(a)
    b = OC(b)
    c = OC(c)
    n = OC(n)

    assert str(a) == str(OC('a'))
    assert a.is_ascending
    assert not b.is_ascending
    assert not n.reversed.reversed.is_ascending
    assert str(a.element) == str(b.element) == str(n.element)
    assert str(a) == str(b.reversed)
    assert str(n.reversed.reversed) == str(n)

    assert a.name == 'a'
    assert n.name == 'a'
    assert n.quoted_full_name == 'a'
    assert repr(n) == '<OC: a DESC NULLS LAST>'
项目:trio2o    作者:openstack    | 项目源码 | 文件源码
def get_latest_failed_jobs(context):
    jobs = []
    query = context.session.query(models.Job.type, models.Job.resource_id,
                                  sql.func.count(models.Job.id))
    query = query.group_by(models.Job.type, models.Job.resource_id)
    for job_type, resource_id, count in query:
        _query = context.session.query(models.Job)
        _query = _query.filter_by(type=job_type, resource_id=resource_id)
        _query = _query.order_by(sql.desc('timestamp'))
        # when timestamps of job entries are the same, sort entries by status
        # so "Fail" job is placed before "New" and "Success" jobs
        _query = _query.order_by(sql.asc('status'))
        latest_job = _query[0].to_dict()
        if latest_job['status'] == constants.JS_Fail:
            jobs.append(latest_job)
    return jobs
项目:csirtg-smrt-py    作者:csirtgadgets    | 项目源码 | 文件源码
def cache_provider(self, provider):
        if self.memcached_provider == provider:
            return

        self.memcached_provider = provider
        self.memcache = {}
        logger.info("Caching archived indicators for provider {}".format(provider))
        q = self.handle().query(Indicator) \
            .filter_by(provider=provider) \
            .order_by(asc(Indicator.lasttime), asc(Indicator.firsttime), asc(Indicator.created_at))

        q = q.options(load_only("indicator", "group", "tags", "firsttime", "lasttime"))
        q = q.yield_per(1000)
        for i in q:
            self.memcache[i.indicator] = (i.group, i.tags, i.firsttime, i.lasttime)

        logger.info("Cached provider {} in memory, {} objects".format(provider, len(self.memcache)))
项目:video_annotation    作者:danoneata    | 项目源码 | 文件源码
def get_all_annotations():
    video_name = request.args["selected_video"]
    video = Video.query.filter(Video.name == video_name).first()
    user = current_user
    # pdb.set_trace()
    annotation_list = Annotation.query.filter(
        (Annotation.user_id == current_user.id) &
        (Annotation.video_id == video.id)).order_by(sqlalchemy.asc(Annotation.id)).all()
    return jsonify([
        {
            'selected_video': video.name,
            'time_start': row.start_frame / FPS,
            'time_end': row.end_frame / FPS,
            'select_vocab_child': row.keywords_child,
            'select_vocab_therapist': row.keywords_therapist,
            'description': row.description,
            'description_type': row.description_type,
            'ann_number': row.id,
        }
        for row in annotation_list
    ])
项目:Intelligent-Public-Grievance-System    作者:devyash    | 项目源码 | 文件源码
def  showDetailedIssue(I_Id):
    if 'logged_in' not in login_session:
        flash('You need to login first.')
        return redirect(url_for('login'))
    else:
        showDetailedIssue = session.query(Issue).filter_by(id = I_Id).one()
        showDetailedComment = session.query(Comment).filter_by(id = I_Id).order_by(asc(Comment.sqNo)).all()
        showDetailedUser= session.query(User).filter_by(id= showDetailedIssue.author).one()
        Author=showDetailedUser.name
        #temporarily harcoding the likes and dislikes part
        like=showDetailedIssue.like
        dislike=showDetailedIssue.dislike
        #showDetailedVote = session.query(Issue).filter_by(id = I_Id).all()
        #showDetailedVote = session,query(func.count())   SELECT count(*) 
        #    FROM (SELECT V_flag FROM Votes where V_IssueId = %s AND V_flag = true)
        # AS likes  GROUP BY V_flag;""",(I_Id,))
        if showDetailedIssue.anonFlag == 1:
           Author="Anonymous"
        return render_template('showdetailedissue.html', Issue=showDetailedIssue, Comment=showDetailedComment, like=like, dislike=dislike, Author=Author)
项目:sciz    作者:erk3    | 项目源码 | 文件源码
def trigger(self):
        if not self.revoked and self.url != None:
            try:
                # Find the events
                events = sg.db.session.query(EVENT).filter(EVENT.id > self.last_event_id, EVENT.notif_to_push == True, EVENT.group_id == self.group_id).order_by(asc(EVENT.time)).all()
                res = []
                max_id = 0
                for event in events:
                    max_id = max(event.id, max_id)
                    res.append({'id': event.id, 'notif': event.notif.encode(sg.DEFAULT_CHARSET)})
                # Send the data
                if len(res) > 0 :
                    try:
                        headers = {'Authorization': self.jwt}
                        r = requests.post(self.url, headers = headers, json = res, timeout = 1)
                        # Update the hook
                        self.last_event_id = max_id
                        sg.db.session.add(self)
                        sg.db.session.commit()
                    except requests.RequestException as e:
                        sg.logger.warning('Unable to send events for reverse hook %s (%s) and url %s : %s' % (self.name, self.id, self.url, str(e), ))
            except NoResultFound:
                sg.logger.warning('No event found corresponding to the reverse hook %s (%s)' % (self.name, self.id, ))
项目:kort-core    作者:kort    | 项目源码 | 文件源码
def get_achievements(user_id, lang):
    try:
        all_badges = db_session.query(api.models.Badge).order_by(asc(api.models.Badge.sorting)).all()

        all_acquired_badges = db_session.query(api.models.UserBadge) \
            .filter(api.models.UserBadge.user_id == user_id)

        all_acquired_badges_dict = {}
        for badge in all_acquired_badges:
            all_acquired_badges_dict[badge.badge_id] = badge

        badges_achieved = []
        for badge in all_badges:
            achievement_date = None
            achieved = False
            if badge.id in all_acquired_badges_dict:
                achievement_date = all_acquired_badges_dict[badge.id].create_date
                achieved = True
            badges_achieved.append(badge.dump(language=lang, achieved=achieved, achievementDate=achievement_date))

        return badges_achieved

    except Exception as e:
        logger.error(traceback.format_exc())
        return []
项目:biweeklybudget    作者:jantman    | 项目源码 | 文件源码
def get(self):
        resdata = []
        prices = db_session.query(
            FuelFill
        ).filter(
            FuelFill.cost_per_gallon.__ne__(None)
        ).order_by(asc(FuelFill.date))
        for point in prices.all():
            ds = point.date.strftime('%Y-%m-%d')
            resdata.append({
                'date': ds,
                'price': float(point.cost_per_gallon)
            })
        res = {
            'data': resdata
        }
        return jsonify(res)
项目:suite    作者:Staffjoy    | 项目源码 | 文件源码
def post(self):
        """ Assign a scheduling task """
        s = Schedule2.query\
            .join(Role)\
            .join(Location)\
            .join(Organization)\
            .filter(Schedule2.state == "mobius-queue", Organization.active == True)\
            .order_by(asc(Schedule2.last_update))\
            .first()

        if s is None:
            abort(404)

        s.transition_to_mobius_processing()

        role = Role.query.get(s.role_id)
        loc = Location.query.get(role.location_id)

        return {
            "schedule_id": s.id,
            "role_id": role.id,
            "location_id": loc.id,
            "organization_id": loc.organization_id,
        }
项目:suite    作者:Staffjoy    | 项目源码 | 文件源码
def post(self):
        """ Assign a scheduling task """
        s = Schedule2.query\
            .join(Role)\
            .join(Location)\
            .join(Organization)\
            .filter(Schedule2.state == "chomp-queue", Organization.active == True)\
            .order_by(asc(Schedule2.last_update))\
            .first()

        if s is None:
            abort(404)

        s.transition_to_chomp_processing()

        role = Role.query.get(s.role_id)
        loc = Location.query.get(role.location_id)

        return {
            "schedule_id": s.id,
            "role_id": role.id,
            "location_id": loc.id,
            "organization_id": loc.organization_id,
        }
项目:peter_sslers    作者:aptise    | 项目源码 | 文件源码
def domain_focus__calendar(self):
        rval = {}
        dbDomain = self._domain_focus()
        weekly_certs = self.request.api_context.dbSession.query(year_week(SslServerCertificate.timestamp_signed).label('week_num'),
                                                                sqlalchemy.func.count(SslServerCertificate.id)
                                                                )\
            .join(SslUniqueFQDNSet2SslDomain,
                  SslServerCertificate.ssl_unique_fqdn_set_id == SslUniqueFQDNSet2SslDomain.ssl_unique_fqdn_set_id,
                  )\
            .filter(SslUniqueFQDNSet2SslDomain.ssl_domain_id == dbDomain.id,
                    )\
            .group_by('week_num')\
            .order_by(sqlalchemy.asc('week_num'))\
            .all()
        rval['issues'] = {}
        for wc in weekly_certs:
            rval['issues'][str(wc[0])] = wc[1]
        return rval

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
项目:peter_sslers    作者:aptise    | 项目源码 | 文件源码
def unique_fqdn_set_focus__calendar(self):
        rval = {}
        dbUniqueFQDNSet = self._unique_fqdn_set_focus()
        weekly_certs = self.request.api_context.dbSession.query(year_week(SslServerCertificate.timestamp_signed).label('week_num'),
                                                                sqlalchemy.func.count(SslServerCertificate.id)
                                                                )\
            .filter(SslServerCertificate.ssl_unique_fqdn_set_id == dbUniqueFQDNSet.id,
                    )\
            .group_by('week_num')\
            .order_by(sqlalchemy.asc('week_num'))\
            .all()
        rval['issues'] = {}
        for wc in weekly_certs:
            rval['issues'][str(wc[0])] = wc[1]
        return rval

    # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
项目:bday-app    作者:pybites    | 项目源码 | 文件源码
def search():
    name = request.args.get('name')
    if not name.isalpha():
        print('Not isalpha string')
        return redirect(request.referrer)

    bdays = (Birthday.query
             .filter(Birthday.name.like("%{}%".format(name)))
             .order_by(asc(Birthday.bday)).all())

    now = _get_current_date()
    title = 'Search'
    tabs = [title] + TABS[1:]

    return render_template("index.html",
                           data=bdays,
                           now=now,
                           active_tab=title,
                           tabs=tabs)
项目:quupod    作者:alvinwan    | 项目源码 | 文件源码
def get_latest(**kwargs) -> db.Model:
        """Return latest unresolved inquiry for the current queue.

        This will filter the keyword arguments provided. Specifically, it will:
        - Remove all filters will falsey values.
        - This will remove the 'category' field if the category is 'all'.
        """
        kwargs = {k: v for k, v in kwargs.items() if v}

        if kwargs.get('category', None) == 'all':
            kwargs.pop('category')

        return Inquiry.query.filter_by(
            status='unresolved',
            queue_id=g.queue.id,
            **kwargs).order_by(asc(Inquiry.created_at)).first()
项目:glare    作者:openstack    | 项目源码 | 文件源码
def get_all(context, session, filters=None, marker=None, limit=None,
            sort=None, latest=False):
    """List all visible artifacts

    :param filters: dict of filter keys and values.
    :param marker: artifact id after which to start page
    :param limit: maximum number of artifacts to return
    :param sort: a tuple (key, dir, type) where key is an attribute by
     which results should be sorted, dir is a direction: 'asc' or 'desc',
     and type is type of the attribute: 'bool', 'string', 'numeric' or 'int' or
     None if attribute is base.
    :param latest: flag that indicates, that only artifacts with highest
     versions should be returned in output
    """
    artifacts = _get_all(
        context, session, filters, marker, limit, sort, latest)
    return [af.to_dict() for af in artifacts]
项目:uchan    作者:Floens    | 项目源码 | 文件源码
def find_by_type(page_type: str) -> 'List[PageModel]':
    _check_page_type(page_type)

    lc = local_cache.get(cache_key('type', page_type))
    if lc:
        return list(map(lambda i: i.copy(), lc))

    pages_by_type_cached = cache.get(cache_key('pages_by_type', page_type))
    if pages_by_type_cached is not None:
        res = list(map(lambda i: PageModel.from_cache(i), pages_by_type_cached))
    else:
        with session() as s:
            q = s.query(PageOrmModel).filter_by(type=page_type)
            q = q.order_by(asc(PageOrmModel.order))
            res = list(map(lambda i: PageModel.from_orm_model(i), q.all()))

            cache.set(cache_key('pages_by_type', page_type), list(map(lambda i: i.to_cache(), res)))

            s.commit()

    local_cache.set(cache_key('type', page_type), res)

    return res
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullsfirst_op,
            wraps_column_expression=False)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _create_nullslast(cls, column):
        """Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullslast` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullslast

            stmt = select([users_table]).\\
                        order_by(nullslast(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS LAST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullslast`, rather than as its standalone
        function version, as in::

            stmt = select([users_table]).\\
                        order_by(users_table.c.name.desc().nullslast())

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullsfirst`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullslast_op,
            wraps_column_expression=False)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _create_desc(cls, column):
        """Produce a descending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import desc

            stmt = select([users_table]).order_by(desc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name DESC

        The :func:`.desc` function is a standalone version of the
        :meth:`.ColumnElement.desc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.desc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.desc` operation.

        .. seealso::

            :func:`.asc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.desc_op,
            wraps_column_expression=False)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _create_asc(cls, column):
        """Produce an ascending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import asc
            stmt = select([users_table]).order_by(asc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name ASC

        The :func:`.asc` function is a standalone version of the
        :meth:`.ColumnElement.asc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.asc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.asc` operation.

        .. seealso::

            :func:`.desc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.asc_op,
            wraps_column_expression=False)
项目:github-catalog    作者:yogykwan    | 项目源码 | 文件源码
def show_categories():
    categories = session.query(Category).order_by(asc(Category.name))
    return render('showcategories.html', categories=categories)
项目:github-catalog    作者:yogykwan    | 项目源码 | 文件源码
def categories_json():
    categories = session.query(Category).order_by(asc(Category.name))
    return jsonify(Categories=[i.serialize for i in categories])
项目:sqlakeyset    作者:djrobstep    | 项目源码 | 文件源码
def __init__(self, x):
        if isinstance(x, unicode):
            x = column(x)
        if not isinstance(x, UnaryExpression):
            x = asc(x)
        self.uo = x
        self.full_name = str(self.element)
        try:
            table_name, name = self.full_name.split('.', 1)
        except ValueError:
            table_name = None
            name = self.full_name

        self.table_name = table_name
        self.name = name
项目:trio2o    作者:openstack    | 项目源码 | 文件源码
def query_resource(context, model, filters, sorts):
    query = context.session.query(model)
    query = _filter_query(model, query, filters)
    for sort_key, sort_dir in sorts:
        sort_dir_func = sql.asc if sort_dir else sql.desc
        query = query.order_by(sort_dir_func(sort_key))
    return [obj.to_dict() for obj in query]
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def remote_etl_sql(self):
        """SQL QUERY FOR RESULTS FROM REMOTE SOURCE"""
        if not self.table.sql:
            """Use table name."""
            try:
                columns = {col.column_name: col for col in self.table.columns}

                sql = select([]).select_from(self.get_sqla_table())

                if self.sync_field and self.sync_field in columns:
                    sql = sql.where(column(self.sync_field) > self.sync_last)
                    sql = sql.order_by(asc(self.sync_field))

                return sql
            except Exception as e:
                logger.exception(str(e))
                raise
        else:
            """Use custom sql query."""
            try:

                return self.clear_sql()

            except Exception as e:
                logger.exception(str(e))
                raise
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullsfirst_op,
            wraps_column_expression=False)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def _create_nullslast(cls, column):
        """Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullslast` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullslast

            stmt = select([users_table]).\\
                        order_by(nullslast(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS LAST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullslast`, rather than as its standalone
        function version, as in::

            stmt = select([users_table]).\\
                        order_by(users_table.c.name.desc().nullslast())

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullsfirst`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullslast_op,
            wraps_column_expression=False)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def _create_desc(cls, column):
        """Produce a descending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import desc

            stmt = select([users_table]).order_by(desc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name DESC

        The :func:`.desc` function is a standalone version of the
        :meth:`.ColumnElement.desc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.desc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.desc` operation.

        .. seealso::

            :func:`.asc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.desc_op,
            wraps_column_expression=False)
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def _create_asc(cls, column):
        """Produce an ascending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import asc
            stmt = select([users_table]).order_by(asc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name ASC

        The :func:`.asc` function is a standalone version of the
        :meth:`.ColumnElement.asc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.asc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.asc` operation.

        .. seealso::

            :func:`.desc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.asc_op,
            wraps_column_expression=False)
项目:HTSOHM-dev    作者:akaija    | 项目源码 | 文件源码
def run_ids():
    cols = [materials.c.run_id,
            func.max(materials.c.generation),
            func.count(materials.c.id)]
    rows = or_(materials.c.retest_passed == None, materials.c.retest_passed == True)
    sort = materials.c.run_id
    s = select(cols, rows).group_by(sort).order_by(asc(sort))
    print('\nrun-id\t\t\t\tgenerations\tmaterial')
    result = engine.execute(s)
    for row in result:
        print('%s\t%s\t\t%s' % (row[0], row[1], row[2]))
    result.close()
项目:video_annotation    作者:danoneata    | 项目源码 | 文件源码
def export():
    btn = request.form["button_pressed"]
    if btn == '1':
        video_list = Video.query.all();
        for video in video_list:
            annotation_list = Annotation.query.filter(Annotation.video_id == video.id).order_by(sqlalchemy.asc(Annotation.start_frame)).all()
            split_list_child = [        annotation.keywords_child.split(', ')        for annotation in annotation_list    ]
            no  = 0
            classes_child = []
            for list in split_list_child:

                 temp = [WORD_TO_ID_CHILD.get(action,-1) for action in list]
                 temp2= [[ 1 if i == xs - 1 else 0   for i in range(len(WORD_TO_ID_CHILD))   ]  for xs in temp]
                 classes_child.append([sum(x) for x in zip(*temp2)])
                 no=no+1

            split_list_therapist = [        annotation.keywords_therapist.split(', ')        for annotation in annotation_list    ]
            no  = 0
            classes_therapist = []
            for list in split_list_therapist:

                 temp = [WORD_TO_ID_THERAPIST.get(action,-1) for action in list]
                 temp2 = [[ 1 if i == xs - 1 else 0   for i in range(len(WORD_TO_ID_THERAPIST))   ]  for xs in temp]
                 classes_therapist.append( [sum(x) for x in zip(*temp2)])
                 no=no+1

            #pdb.set_trace()              
            #classes_child = [ [ 1 if i == xs - 1 else 0   for i in range(len(WORD_TO_ID_CHILD))   ]  for xs in [        WORD_TO_ID_CHILD.get(annotation.keywords_child, -1)        for annotation in annotation_list    ] ]
            #classes_therapist = [ [   1 if i == xs - 1 else 0     for i in range(len(WORD_TO_ID_THERAPIST))    ]    for xs in [  WORD_TO_ID_THERAPIST.get(annotation.keywords_therapist, -1)        for annotation in annotation_list    ] ]
            #WORD_TO_ID_CHILD()
            #pdb.set_trace()
            scipy.io.savemat('/home/elisabeta/video_annotation/DataPerVideo/'+ video.name+'.mat', mdict={'start_frame': [annotation.start_frame for annotation in annotation_list], 'end_frame': [annotation.end_frame for annotation in annotation_list], 'description': [[annotation.description] for annotation in annotation_list], 'classes_child': classes_child, 'classes_therapist': classes_therapist, 'action_author': [annotation.description_type for annotation in annotation_list] })
    return 'OK'
项目:Intelligent-Public-Grievance-System    作者:devyash    | 项目源码 | 文件源码
def showIssues():
    restaurants = session.query(Issue).order_by(asc(Issue.id))
    if 'username' not in login_session:
        return render_template('publicissues.html', issues=issues)
    else:
        return render_template('issues.html', issues=issues)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.nullsfirst_op)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def _create_nullslast(cls, column):
        """Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullslast` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullslast

            stmt = select([users_table]).\\
                        order_by(nullslast(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS LAST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullslast`, rather than as its standalone
        function version, as in::

            stmt = select([users_table]).\\
                        order_by(users_table.c.name.desc().nullslast())

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullsfirst`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.nullslast_op)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def _create_desc(cls, column):
        """Produce a descending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import desc

            stmt = select([users_table]).order_by(desc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name DESC

        The :func:`.desc` function is a standalone version of the
        :meth:`.ColumnElement.desc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.desc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.desc` operation.

        .. seealso::

            :func:`.asc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.desc_op)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def _create_asc(cls, column):
        """Produce an ascending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import asc
            stmt = select([users_table]).order_by(asc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name ASC

        The :func:`.asc` function is a standalone version of the
        :meth:`.ColumnElement.asc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.asc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.asc` operation.

        .. seealso::

            :func:`.desc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.asc_op)
项目:Monocle    作者:Noctem    | 项目源码 | 文件源码
def get_top_pokemon(session, count=30, order='DESC'):
    query = session.query(Sighting.pokemon_id, func.count(Sighting.pokemon_id).label('how_many')) \
        .group_by(Sighting.pokemon_id)
    if conf.REPORT_SINCE:
        query = query.filter(Sighting.expire_timestamp > SINCE_TIME)
    order = desc if order == 'DESC' else asc
    query = query.order_by(order('how_many')).limit(count)
    return query.all()
项目:Monocle    作者:Noctem    | 项目源码 | 文件源码
def get_pokemon_ranking(session):
    query = session.query(Sighting.pokemon_id, func.count(Sighting.pokemon_id).label('how_many')) \
        .group_by(Sighting.pokemon_id) \
        .order_by(asc('how_many'))
    if conf.REPORT_SINCE:
        query = query.filter(Sighting.expire_timestamp > SINCE_TIME)
    ranked = [r[0] for r in query]
    none_seen = [x for x in range(1,252) if x not in ranked]
    return none_seen + ranked
项目:dati-ckan-docker    作者:italia    | 项目源码 | 文件源码
def group_list(context, data_dict):
    '''Return a list of the names of the site's groups.

    :param order_by: the field to sort the list by, must be ``'name'`` or
      ``'packages'`` (optional, default: ``'name'``) Deprecated use sort.
    :type order_by: string
    :param sort: sorting of the search results.  Optional.  Default:
        "name asc" string of field name and sort-order. The allowed fields are
        'name', 'package_count' and 'title'
    :type sort: string
    :param groups: a list of names of the groups to return, if given only
        groups whose names are in this list will be returned (optional)
    :type groups: list of strings
    :param all_fields: return group dictionaries instead of just names. Only
        core fields are returned - get some more using the include_* options.
        Returning a list of packages is too expensive, so the `packages`
        property for each group is deprecated, but there is a count of the
        packages in the `package_count` property.
        (optional, default: ``False``)
    :type all_fields: boolean
    :param include_extras: if all_fields, include the group extra fields
        (optional, default: ``False``)
    :type include_extras: boolean
    :param include_tags: if all_fields, include the group tags
        (optional, default: ``False``)
    :type include_tags: boolean
    :param include_groups: if all_fields, include the groups the groups are in
        (optional, default: ``False``).
    :type include_groups: boolean

    :rtype: list of strings

    '''
    _check_access('group_list', context, data_dict)
    return _group_or_org_list(context, data_dict)
项目:dati-ckan-docker    作者:italia    | 项目源码 | 文件源码
def organization_list(context, data_dict):
    '''Return a list of the names of the site's organizations.

    :param order_by: the field to sort the list by, must be ``'name'`` or
      ``'packages'`` (optional, default: ``'name'``) Deprecated use sort.
    :type order_by: string
    :param sort: sorting of the search results.  Optional.  Default:
        "name asc" string of field name and sort-order. The allowed fields are
        'name', 'package_count' and 'title'
    :type sort: string
    :param organizations: a list of names of the groups to return,
        if given only groups whose names are in this list will be
        returned (optional)
    :type organizations: list of strings
    :param all_fields: return group dictionaries instead of just names. Only
        core fields are returned - get some more using the include_* options.
        Returning a list of packages is too expensive, so the `packages`
        property for each group is deprecated, but there is a count of the
        packages in the `package_count` property.
        (optional, default: ``False``)
    :type all_fields: boolean
    :param include_extras: if all_fields, include the group extra fields
        (optional, default: ``False``)
    :type include_extras: boolean
    :param include_tags: if all_fields, include the group tags
        (optional, default: ``False``)
    :type include_tags: boolean
    :param include_groups: if all_fields, include the groups the groups are in
        (optional, default: ``False``)
    :type all_fields: boolean

    :rtype: list of strings

    '''
    _check_access('organization_list', context, data_dict)
    data_dict['groups'] = data_dict.pop('organizations', [])
    data_dict['type'] = 'organization'
    return _group_or_org_list(context, data_dict, is_org=True)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.nullsfirst_op)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def _create_nullslast(cls, column):
        """Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullslast` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullslast

            stmt = select([users_table]).\\
                        order_by(nullslast(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS LAST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullslast`, rather than as its standalone
        function version, as in::

            stmt = select([users_table]).\\
                        order_by(users_table.c.name.desc().nullslast())

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullsfirst`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.nullslast_op)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def _create_desc(cls, column):
        """Produce a descending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import desc

            stmt = select([users_table]).order_by(desc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name DESC

        The :func:`.desc` function is a standalone version of the
        :meth:`.ColumnElement.desc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.desc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.desc` operation.

        .. seealso::

            :func:`.asc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.desc_op)
项目:oa_qian    作者:sunqb    | 项目源码 | 文件源码
def _create_asc(cls, column):
        """Produce an ascending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import asc
            stmt = select([users_table]).order_by(asc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name ASC

        The :func:`.asc` function is a standalone version of the
        :meth:`.ColumnElement.asc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.asc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.asc` operation.

        .. seealso::

            :func:`.desc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_text(column), modifier=operators.asc_op)
项目:UD---sellit    作者:vondirath    | 项目源码 | 文件源码
def showStores():
    """ Store route showing and allowing creation of stores """
    stores = session.query(Store).order_by(asc(Store.name))
    if 'username' not in login_session:
        return redirect('/auth/login')
    else:
        return render_template('stores.html', stores=stores,
                               login_session=login_session)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullsfirst_op,
            wraps_column_expression=False)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def _create_nullslast(cls, column):
        """Produce the ``NULLS LAST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullslast` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullslast

            stmt = select([users_table]).\\
                        order_by(nullslast(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS LAST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullslast` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullslast`, rather than as its standalone
        function version, as in::

            stmt = select([users_table]).\\
                        order_by(users_table.c.name.desc().nullslast())

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullsfirst`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullslast_op,
            wraps_column_expression=False)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def _create_desc(cls, column):
        """Produce a descending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import desc

            stmt = select([users_table]).order_by(desc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name DESC

        The :func:`.desc` function is a standalone version of the
        :meth:`.ColumnElement.desc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.desc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.desc` operation.

        .. seealso::

            :func:`.asc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.desc_op,
            wraps_column_expression=False)
项目:chihu    作者:yelongyu    | 项目源码 | 文件源码
def _create_asc(cls, column):
        """Produce an ascending ``ORDER BY`` clause element.

        e.g.::

            from sqlalchemy import asc
            stmt = select([users_table]).order_by(asc(users_table.c.name))

        will produce SQL as::

            SELECT id, name FROM user ORDER BY name ASC

        The :func:`.asc` function is a standalone version of the
        :meth:`.ColumnElement.asc` method available on all SQL expressions,
        e.g.::


            stmt = select([users_table]).order_by(users_table.c.name.asc())

        :param column: A :class:`.ColumnElement` (e.g. scalar SQL expression)
         with which to apply the :func:`.asc` operation.

        .. seealso::

            :func:`.desc`

            :func:`.nullsfirst`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.asc_op,
            wraps_column_expression=False)
项目:ShelbySearch    作者:Agentscreech    | 项目源码 | 文件源码
def _create_nullsfirst(cls, column):
        """Produce the ``NULLS FIRST`` modifier for an ``ORDER BY`` expression.

        :func:`.nullsfirst` is intended to modify the expression produced
        by :func:`.asc` or :func:`.desc`, and indicates how NULL values
        should be handled when they are encountered during ordering::


            from sqlalchemy import desc, nullsfirst

            stmt = select([users_table]).\
                        order_by(nullsfirst(desc(users_table.c.name)))

        The SQL expression from the above would resemble::

            SELECT id, name FROM user ORDER BY name DESC NULLS FIRST

        Like :func:`.asc` and :func:`.desc`, :func:`.nullsfirst` is typically
        invoked from the column expression itself using
        :meth:`.ColumnElement.nullsfirst`, rather than as its standalone
        function version, as in::

            stmt = (select([users_table]).
                    order_by(users_table.c.name.desc().nullsfirst())
                    )

        .. seealso::

            :func:`.asc`

            :func:`.desc`

            :func:`.nullslast`

            :meth:`.Select.order_by`

        """
        return UnaryExpression(
            _literal_as_label_reference(column),
            modifier=operators.nullsfirst_op,
            wraps_column_expression=False)