• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sqlalchemy.extract函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sqlalchemy.extract函数的典型用法代码示例。如果您正苦于以下问题:Python extract函数的具体用法?Python extract怎么用?Python extract使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_candidate

    def get_candidate(self, args, page_num, per_page, candidate_id, committee_id):
        if candidate_id is not None:
            candidates = CandidateDetail.query
            candidates = candidates.filter_by(**{'candidate_id': candidate_id})

        if committee_id is not None:
            candidates = CandidateDetail.query.join(CandidateCommitteeLink).filter(CandidateCommitteeLink.committee_id==committee_id)

        for argname in ['candidate_id', 'candidate_status', 'district', 'incumbent_challenge', 'office', 'party', 'state']:
            if args.get(argname):
                # this is not working and doesn't look like it would work for _short
                if ',' in args[argname]:
                    candidates = candidates.filter(getattr(CandidateDetail, argname).in_(args[argname].split(',')))
                else:
                    candidates = candidates.filter_by(**{argname: args[argname]})

        if args.get('year') and args['year'] != '*':
            # before expiration
            candidates = candidates.filter(or_(extract('year', CandidateDetail.expire_date) >= int(args['year']), CandidateDetail.expire_date == None))
            # after origination
            candidates = candidates.filter(extract('year', CandidateDetail.load_date) <= int(args['year']))

        count = candidates.count()

        return count, candidates.order_by(CandidateDetail.expire_date.desc()).paginate(page_num, per_page, False).items
开发者ID:LindsayYoung,项目名称:openFEC,代码行数:25,代码来源:candidates.py


示例2: get_committee

    def get_committee(self, args, page_num, per_page, committee_id, candidate_id):

        if committee_id is not None:
            committees = CommitteeDetail.query
            committees = committees.filter_by(**{'committee_id': committee_id})

        if candidate_id is not None:
            committees = CommitteeDetail.query.join(CandidateCommitteeLink).filter(CandidateCommitteeLink.candidate_id==candidate_id)

        for argname in ['designation', 'organization_type', 'committee_type']:
            if args.get(argname):
                if ',' in args[argname]:
                    committees = committees.filter(getattr(Committee, argname).in_(args[argname].split(',')))
                else:
                    committees = committees.filter(getattr(Committee, argname)==args[argname])

        # default year filtering
        if args.get('year') is None:
            earliest_year = int(sorted(default_year().split(','))[0])
            # still going or expired after the earliest year we are looking for
            committees = committees.filter(or_(extract('year', CommitteeDetail.expire_date) >= earliest_year, CommitteeDetail.expire_date == None))

        # Should this handle a list of years to make it consistent with /candidate ?
        elif args.get('year') and args['year'] != '*':
            # before expiration
            committees = committees.filter(or_(extract('year', CommitteeDetail.expire_date) >= int(args['year']), CommitteeDetail.expire_date == None))
            # after origination
            committees = committees.filter(extract('year', CommitteeDetail.original_registration_date) <= int(args['year']))

        count = committees.count()

        return count, committees.order_by(CommitteeDetail.name).paginate(page_num, per_page, False).items
开发者ID:LindsayYoung,项目名称:openFEC,代码行数:32,代码来源:committees.py


示例3: agg_week

def agg_week(crime, year):
    week_days = {
        0: 'Sun',
        1: 'Mon',
        2: 'Tue',
        3: 'Wed',
        4: 'Thu',
        5: 'Fri',
        6: 'Sat'
    }

    data = Crimes.query.with_entities(
        extract('dow', Crimes.datetime).label('day'),
        func.count(Crimes.cat)
        ).filter(Crimes.cat == crime
        ).filter(extract('year', Crimes.datetime) == year
        ).group_by('day'
        ).order_by('day'
        ).all()

    return jsonify({
        'crime': crime,
        'aggregates': [ {'day': week_days[day], 'occurrences': occurences}
            for day, occurences in data ]
    })
开发者ID:kirwi,项目名称:sfcrime,代码行数:25,代码来源:app.py


示例4: send_profile_visitor_email

def send_profile_visitor_email(**kwargs):
    template = email_template_env.get_template('profile_visitors.html')
    senders = AccountUser.query.filter(
        extract('dow', AccountUser.date_added) == extract('dow', func.now()),
        extract('hour', AccountUser.date_added) == extract('hour', func.now()),
    ).join(
        AccountUserVisit,
        (AccountUserVisit.profile_user_id == AccountUser.id) &
        (AccountUserVisit.notified == False)
    )

    for sender in senders:
        visitors = AccountUserVisit.get_all_visits_in_last_7_days(sender, 5)

        visitors = [AccountUserVisit.visit_item(*v) for v in visitors.all()]
        if visitors:
            body = template.render(
                sender=sender,
                visitors=visitors,
                **kwargs
            )
            send_email(sender.username, body)

            try:
                db.session.query(AccountUserVisit).filter_by(profile_user_id=sender.id).update({"notified": True})
                db.session.commit()
            except:
                db.session.rollback()
                raise
开发者ID:philpill,项目名称:romeo,代码行数:29,代码来源:commands.py


示例5: detail

def detail(year, month, day, slug):
    year = int(year)
    month = int(month)
    day = int(day)
    with session_context() as session:
        post = session.query(Post).options(
            subqueryload(Post.tags)).filter(Post.slug == slug).filter(
                extract('year', Post.create_at) == year,
                extract('month', Post.create_at) == month,
                extract('day', Post.create_at) == day)
        try:
            if post.count() < 1:
                redirect('/blog')
        except:
            print "error occurred"
            redirect('/blog')
        post = post.first()
        post.view_count += 1
        # get related posts
        # dont forget to filter self
        tag_ids = [_t.id for _t in post.tags]
        related_posts = session.query(Post).filter(
            Post.tags.any(Tag.id.in_(tag_ids))
        ).filter(
            Post.id != post.id
        ).order_by(Post.view_count.desc())

        session.commit()
    return {'post': post, 'title': post.title, 'related_posts': related_posts}
开发者ID:songuo,项目名称:sblog,代码行数:29,代码来源:views.py


示例6: getPostByMonth

 def getPostByMonth(self, year, month):
     posts = web.ctx.orm.query(Post).\
             filter(and_(Post.content_type=='post', Post.status=='publish')).\
             filter(extract('year', Post.created)==int(year)).\
             filter(extract('month', Post.created)==int(month)).\
             order_by('posts.created DESC')
     return posts
开发者ID:huoyuanzh,项目名称:aplog,代码行数:7,代码来源:controllers.py


示例7: get_booked

    def get_booked(self, date: datetime, is_after: bool, is_now: bool = False):
        order_func = None
        compare_op = None
        if is_after:
            compare_op = operator.ge
            if not is_now:
                date += timedelta(days=1)
            order_func = stub_func
        else:
            compare_op = operator.lt
            order_func = desc

        date = date.replace(hour=0, minute=0, second=0, microsecond=0)
        start_date = dataentities.BookedRange.start_date
        next_date = session.query(dataentities.BookedRange) \
            .filter(dataentities.BookedRange.start_date > datetime.now()) \
            .filter(compare_op(dataentities.BookedRange.start_date, date)) \
            .order_by(order_func(dataentities.BookedRange.start_date)) \
            .limit(1).first()

        if not next_date:
            return None

        return session.query(dataentities.BookedRange) \
            .filter(extract('day', start_date) == next_date.start_date.day) \
            .filter(extract('month', start_date) == next_date.start_date.month) \
            .filter(extract('year', start_date) == next_date.start_date.year) \
            .order_by(dataentities.BookedRange.start_date).all()
开发者ID:rundoom,项目名称:BookingBot,代码行数:28,代码来源:datacore.py


示例8: get_model_changes

def get_model_changes(
    entity_type, year=None, month=None, day=None, hour=None, since=None
):
    # type: (Text, int, int, int, int, datetime) -> Query
    """Get models modified at the given date with the Audit service.

    :param entity_type: string like "extranet_medicen.apps.crm.models.Compte".
      Beware the typo, there won't be a warning message.
    :param since: datetime
    :param year: int
    :param month: int
    :param day: int
    :param hour: int

    :returns: a query object
    """
    query = AuditEntry.query

    if since:
        query = query.filter(AuditEntry.happened_at >= since)

    if year:
        query = query.filter(extract("year", AuditEntry.happened_at) == year)
    if month:
        query = query.filter(extract("month", AuditEntry.happened_at) == month)
    if day:
        query = query.filter(extract("day", AuditEntry.happened_at) == day)
    if hour:
        query = query.filter(extract("hour", AuditEntry.happened_at) == hour)

    query = query.filter(AuditEntry.entity_type.like(entity_type)).order_by(
        AuditEntry.happened_at
    )

    return query
开发者ID:abilian,项目名称:abilian-core,代码行数:35,代码来源:service.py


示例9: write_states_dataset

def write_states_dataset(fobj, source, slug,
                         start_year=None, end_year=None,
                         adjusted=True, delta=False):
    """
    Writes a geographic csv of the series to the open file-like object passed
    in as `fobj`. Each row is an individual state, and each column is the
    period for the series. You may also specify seasonally adjusted with the
    `adjusted` boolean.

    The source can be either "LAUS" or "CESSM". The slug should be the URL-safe
    slug that groups similar datasets by state/category.

    This will write in place to the fobj that is passed to it.
    """

    fields = ["fips", "State"]

    start_year = start_year or int(elmr.app.config['STARTYEAR'])
    end_year   = end_year or int(elmr.app.config['ENDYEAR'])

    ## TODO: Somehow get this from the database, not hardcoded logic.
    for year in xrange(start_year, end_year + 1):
        for month in xrange(1, 13):
            if year == 2015 and month > 3:
                break
            fields.append(date(year, month, 1).strftime("%b %Y"))

    # Create the CSV writer
    writer = csv.DictWriter(fobj, fieldnames=fields)
    writer.writeheader()

    # Create the database query - note, there is no checking
    for state in USAState.query.order_by('name'):
        ss = state.series.filter_by(adjusted=adjusted, source=source, slug=slug)

        ss = ss.first()  # TODO: Check to make sure this returns a single result
        if ss is None:
            ss = state.series.filter_by(source=source, slug=slug).first()

        series = ss.series.delta if delta else ss.series

        if ss is None:
            continue
        # TODO: above was just a temporary fix

        row = {
            "fips": state.fips,
            "State": state.name,
        }

        field   = SeriesRecord.period
        records = series.records

        records = records.filter(extract('year', field) >= start_year)
        records = records.filter(extract('year', field) <= end_year)
        for record in records:
            row[record.period.strftime("%b %Y")] = record.value

        writer.writerow(row)
开发者ID:eleventhend,项目名称:jobs-report,代码行数:59,代码来源:fips.py


示例10: archive

def archive():
    archive = (db_session.query(extract("year", Post.pub_date).label("year"),
                                extract("month", Post.pub_date).label("month"))
                         .group_by("year", "month")
                         .order_by("-year", "-month"))

    return render_template(env.get_template("archive.html"),
                           archive=archive)
开发者ID:thoslin,项目名称:mfalookbook,代码行数:8,代码来源:app.py


示例11: get_birthday

 def get_birthday(cls):
     today = date.today()
     tomorrow = today + timedelta(days=1)
     return cls.query.filter(
         or_(
             and_(extract('month', User.birth_date) == today.month, extract('day', User.birth_date) == today.day),
             and_(extract('month', User.birth_date) == tomorrow.month, extract('day', User.birth_date) == tomorrow.day)
         ), or_(User.status != User.STATUS_DELETED, User.status==None)).order_by(User.birth_date.desc(), User.full_name).all()
开发者ID:alexbelich,项目名称:PromTal,代码行数:8,代码来源:user.py


示例12: view_post

def view_post(year, month, day, slug):
    post = Post.query.filter(
        (extract('year', Post.pub_date) == year) &
        (extract('month', Post.pub_date) == month) &
        (extract('day', Post.pub_date) == day) &
        (Post.status == PostStatus.published) &
        (Post.slug == slug)).first_or_404()
    return render_template('blog/post_view.html', post=post)
开发者ID:ryankask,项目名称:esther,代码行数:8,代码来源:blog.py


示例13: birthdays

def birthdays():
    today = datetime.datetime.now()
    session = DBSession()

    bday_members = session.query(Person).filter(
        extract('day', Person.dob) == today.day).filter(
        extract('month', Person.dob) == today.month).all()
    session.close()
    return bday_members
开发者ID:asifpy,项目名称:birthday_reminder,代码行数:9,代码来源:helpers.py


示例14: index

def index():
    filter_query = []
    hoje = date.today()
    session['tela'] = "relatorio"

    form = PesForm()

    categoria = []
    categoria.append(('0','Todos'))
    for h in Categoria.query.filter(Categoria.empresa_id == session['empresa']).all():
        categoria.append((h.id,str(h.id) + " " + h.titulo))

    form.categoria_id.choices = categoria

    conta =  []
    conta.append(('0', 'Todos'))
    for h in Conta.query.filter(Conta.empresa_id == session['empresa']).all():
        conta.append((h.id,h.tipo + '-' + h.conta))

    form.conta_id.choices = conta
   
        
    if request.method == "POST":
        if form.categoria_id.data != "0":
            filter_query.append(Movimentacao.categoria_id == form.categoria_id.data)
        
        if form.conta_id.data != "0":
            filter_query.append(Movimentacao.conta_id == form.conta_id.data)    

        if form.data.data:
            (data_inicio,data_fim) = form.data.data.replace(" ","").split("-")

            data_inicio  = datetime.strptime(data_inicio, '%m/%d/%Y') + timedelta(days=-1)
            data_fim     = datetime.strptime(data_fim, '%m/%d/%Y')

            filter_query.append(Movimentacao.data_v >= data_inicio)
            filter_query.append(Movimentacao.data_v <= data_fim   ) 

        else:
            filter_query.append(extract('month', Movimentacao.data_v) == hoje.month)
            filter_query.append(extract('year' , Movimentacao.data_v) == hoje.year )        


        todos = Movimentacao.query.filter(
                Movimentacao.empresa_id == session['empresa'],
                *filter_query,
                ).order_by('data_v').all() 
    
    else:
        todos = Movimentacao.query.filter(
                Movimentacao.empresa_id == session['empresa'],
                extract('month', Movimentacao.data_v) == hoje.month,
                extract('year', Movimentacao.data_v) == hoje.year).order_by('data_v').all() 

    credito = sum([item.valor  for item in todos if item.categoria.status == 0])
    debito = sum([item.valor  for item in todos if item.categoria.status == 1])
    return render_template('relatorio/index.html',title='Relatório de Contas',form=form, todos=todos,credito=credito,debito=debito)
开发者ID:clodonil,项目名称:decoro,代码行数:57,代码来源:controllers.py


示例15: get_busy_on_date

    def get_busy_on_date(self, day, month, year):
        start_date = dataentities.BookedRange.start_date
        on_day = session.query(dataentities.BookedRange) \
            .filter(extract('day', start_date) == day) \
            .filter(extract('month', start_date) == month) \
            .filter(extract('year', start_date) == year) \
            .all()

        return list(map(lambda x: [x.start_date.hour, x.end_date.hour], on_day))
开发者ID:rundoom,项目名称:BookingBot,代码行数:9,代码来源:datacore.py


示例16: group_join_leave_events

    def group_join_leave_events(self, group_id):
        aet = self.auditEventTable
#        SELECT EXTRACT(year FROM event_date) AS year,
#          EXTRACT(month FROM event_date) AS month,
#          subsystem, event_date, instance_user_id, user_id
#        FROM audit_event
#        WHERE
#          ((subsystem = 'gs.group.member.join' AND event_code = '1')
#           OR
#           (subsystem = 'gs.group.member.leave' AND event_code = '1'))
#          AND group_id = 'example_group';
        s = sa.select([
            sa.extract('year', aet.c.event_date).label('year'),
            sa.extract('month', aet.c.event_date).label('month'),
            aet.c.subsystem,
            aet.c.event_date,
            aet.c.instance_user_id,
            aet.c.user_id
        ])
        joinClauses = ((aet.c.subsystem == JOIN_SUBSYSTEM)
                       & (aet.c.event_code == JOIN))
        leaveClauses = ((aet.c.subsystem == LEAVE_SUBSYSTEM)
                        & (aet.c.event_code == LEAVE))
        s.append_whereclause(joinClauses | leaveClauses)
        s.append_whereclause(aet.c.group_id == group_id)

        session = getSession()
        r = session.execute(s)
        rows = []
        if r.rowcount:
            rows = [{
                'year': int(row['year']),
                'month': int(row['month']),
                'date': row['event_date'],
                'subsystem': row['subsystem'],
                'user_id': row['instance_user_id'],
                'admin_id': row['user_id']
            } for row in r]
        years = {}
        for row in rows:
            if row['year'] not in years:
                years[row['year']] = {}
        for row in rows:
            if row['month'] not in years[row['year']]:
                years[row['year']][row['month']] = {
                    JOIN_SUBSYSTEM: [],
                    LEAVE_SUBSYSTEM: []
                }
        for row in rows:
            years[row['year']][row['month']][row['subsystem']].append({
                'date': row['date'],
                'user_id': row['user_id'],
                'admin_id': row['admin_id']
            })
        retval = years
        assert type(retval) == dict
        return retval
开发者ID:groupserver,项目名称:gs.group.member.log,代码行数:57,代码来源:queries.py


示例17: csr_table

def csr_table(filter_val):

    _csr_type = sort_tuple(csr_types)
    _status = sort_tuple(csr_status)

    # Joins CSR and VENDORS


    if filter_val is not None:

        results = results = Csr.query.join(Vendor).filter(Csr.status==1)

        _v = filter_val.split("-")
        if _v[0] == 'date':
            results = results.filter(extract('year', Csr.report_date) == int(_v[1]))
            results = results.filter(extract('month', Csr.report_date) == int(_v[2]))
        elif _v[0] == 'vendor':
            results = results.filter(Vendor.short_hand==_v[1])
        elif _v[0] == 'duration':
            date_max = dt.now() - timedelta(int(_v[1]))
            date_min = dt.now() - timedelta(int(_v[2]))
            results = results.filter(Csr.report_date.between(date_min, date_max))

    else:
        results = Csr.query.join(Vendor)
    # Specify Column Data
    results = results.values(Vendor.name,
                       Csr.id,
                       Csr.csr_ref,
                       Csr.contract_no,
                       Csr.description,
                       Csr.csr_type,
                       Csr.status,
                       Csr.incident_date,
                       Csr.report_date,
                       Csr.close_date,
                       Csr.remarks,
                       )

    resultlist = []
    for v_name, csr_id, ref, contract_no, description, csr_type,\
            status, incident, report, close, remarks in results:

        resultlist.append({ 'vendor_name': v_name,
                            'id': csr_id,
                            'csr_reference' : ref,
                            'contract_no': contract_no,
                            'description': description,
                            'csr_type': _csr_type[csr_type-1],
                            'status': _status[status-1],
                            'incident_date': get_date(incident),
                            'report_date': get_date(report),
                            'close_date': get_date(close),
                            'remarks': remarks,
                           })
    return resultlist
开发者ID:mpdevilleres,项目名称:edm,代码行数:56,代码来源:tables.py


示例18: archive

def archive(year, month):
    entries = Posts.query.filter(
        (extract('month', Posts.created) == month) &
        (extract('year', Posts.created) == year)
    ).all()
    if not entries:
        abort(404)
    for entry in entries:
        entry.content = markdown(entry.content)
    return render_template('archive.html', entries=entries)
开发者ID:jameshawkins,项目名称:blog,代码行数:10,代码来源:app.py


示例19: review_kpi

def review_kpi(filename=None):
    """
    Review Details of the KPI per section by month and year
    """

    section_id = current_user.get_id()
    section = User.query.filter(User.id == section_id).first_or_404()
    specs = SpecSectionKpi.query.filter(SpecSectionKpi.filename == filename).first()
    if specs is None:
        return render_template(
            "section_kpi_mgt/coming-soon.html", msg="Specification for {} doesn't exist yet".format(filename)
        )

    spec = specs.doc[section.full_name]
    classes_description = spec["_classes_description"]
    targets = spec["_target"]
    data = {}

    record = SectionRawScore.query.filter(
        and_(
            SectionRawScore.section_id == section_id,
            extract("month", SectionRawScore.score_date) == filename.split("-")[1],
            extract("year", SectionRawScore.score_date) == filename.split("-")[0],
        )
    ).all()

    if record is None:
        return render_template("section_kpi_mgt/coming-soon.html")

    df = query_to_df(record)
    df = df.set_index("score_class")

    temp_list = []
    for i in ["a11", "a12", "a13", "a2", "a3"]:
        temp_list.append(
            {"class": classes_description[i], "target": targets[i], "actual": float(df.loc[i, "raw_score"])}
        )
    data["capex"] = temp_list

    temp_list = []
    for i in ["b1", "b2"]:
        temp_list.append(
            {"class": classes_description[i], "target": targets[i], "actual": float(df.loc[i, "raw_score"])}
        )
    data["opex"] = temp_list

    temp_list = []
    for i in ["c1", "c2"]:
        temp_list.append(
            {"class": classes_description[i], "target": targets[i], "actual": float(df.loc[i, "raw_score"])}
        )
    data["initiatives"] = temp_list

    _template = "section_kpi_mgt/detailed-dashboard.html"
    return render_template(_template, data=data)
开发者ID:mpdevilleres,项目名称:bprc,代码行数:55,代码来源:views.py


示例20: update_kpi_dashboard

def update_kpi_dashboard(section_id=None, date=None):
    mn = date.month
    yr = date.year
    if section_id is None:
        return (False, 'Section ID must not be None')

    record = SectionWeightedScore.query.\
        filter(and_(SectionWeightedScore.section_id==section_id,
                    extract('month', SectionWeightedScore.weighted_score_date) == mn,
                    extract('year', SectionWeightedScore.weighted_score_date) == yr
                    )).\
        first()

    if record is not None:
        return (False, "Can't Update, Updated Record Already Exist")

    else:
        section = 'BP&TE'
        scores = SectionRawScore.query.\
        filter(and_(SectionRawScore.section_id==section_id,
                    extract('month', SectionRawScore.score_date) == mn,
                    extract('year', SectionRawScore.score_date) == yr
                    )).\
        all()
        df_score = query_to_df(scores)
        df_score = df_score[['score_class', 'raw_score']]
        score_dict = df_score.set_index('score_class').to_dict()

        score_from_raw = cal_raw_scores(raw_scores=score_dict['raw_score'],
                                        targets=targets[section],
                                        classes=classes
                                        )
        score_eqvs = get_score_equivalent(score_from_raw, criteria)

        weighted_each_class = get_weighted_each_class(score_eqvs,
                                                      weightage_class[section],
                                                      classes)
        weighted_each_category = get_weighted_each_category(weighted_each_class,
                                                            weightage_category[section],
                                                            categories)

        for k, v in weighted_each_category.items():

            record = SectionWeightedScore(
                section_id=section_id,
                weighted_score_date=scores[0].score_date,
                weighted_score=v,
                category=k
            )
            db.session.add(record)
        db.session.commit()

        return (True, 'Success')
开发者ID:mpdevilleres,项目名称:bprc,代码行数:53,代码来源:kpi_criteria.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sqlalchemy.false函数代码示例发布时间:2022-05-27
下一篇:
Python sqlalchemy.exists函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap