本文整理汇总了Python中sqlalchemy.func.min方法的典型用法代码示例。如果您正苦于以下问题:Python func.min方法的具体用法?Python func.min怎么用?Python func.min使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.func
的用法示例。
在下文中一共展示了func.min方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_new_packages
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_new_packages(cls):
'''
@return: Returns list of new pkgs and date when they were created, in
format: [(id, date_ordinal), ...]
'''
def new_packages():
# Can't filter by time in select because 'min' function has to
# be 'for all time' else you get first revision in the time period.
package_revision = table('package_revision')
revision = table('revision')
s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).group_by(package_revision.c.id).order_by(func.min(revision.c.timestamp))
res = model.Session.execute(s).fetchall() # [(id, datetime), ...]
res_pickleable = []
for pkg_id, created_datetime in res:
res_pickleable.append((pkg_id, created_datetime.toordinal()))
return res_pickleable
if cache_enabled:
week_commences = cls.get_date_week_started(datetime.date.today())
key = 'all_new_packages_%s' + week_commences.strftime(DATE_FORMAT)
new_packages = our_cache.get_value(key=key,
createfunc=new_packages)
else:
new_packages = new_packages()
return new_packages
示例2: filter
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def filter(self, qs, value):
if value in EMPTY_VALUES:
return qs
y_column = getattr(self.model, value['y_column'])
if value['y_func'] == 'count':
y_func = func.count(y_column)
elif value['y_func'] == 'sum':
y_func = func.sum(y_column)
elif value['y_func'] == 'min':
y_func = func.min(y_column)
elif value['y_func'] == 'max':
y_func = func.max(y_column)
elif value['y_func'] == 'avg':
y_func = func.avg(y_column)
else:
return qs.filter(sql.false())
qs = qs.session.query(y_func).one()
return qs
示例3: test_core2
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def test_core2(dburl):
with S(dburl, echo=ECHO) as s:
sel = select([Book.score]).order_by(Book.id)
check_paging_core(sel, s)
sel = select([Book.score]) \
.order_by(Author.id - Book.id, Book.id) \
.where(Author.id == Book.author_id)
check_paging_core(sel, s)
sel = select([Book.author_id, func.count()]) \
.group_by(Book.author_id) \
.order_by(func.sum(Book.popularity))
check_paging_core(sel, s)
v = func.sum(func.coalesce(Book.a, 0)) + func.min(Book.b)
sel = select([Book.author_id, func.count(), v]) \
.group_by(Book.author_id) \
.order_by(v)
check_paging_core(sel, s)
示例4: event_summery
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def event_summery(self):
with self.session_scope() as session:
time = session.query(func.min(Event.time), func.max(Event.time)).all()
print(f'Event time duration:')
print(f'From: {time[0][0].isoformat()}')
print(f'To: {time[0][1].isoformat()}\n')
event_count = session.query(Event).count()
print(f'Total {event_count} events\n')
boundary = session.query(func.min(Event.longitude), func.max(Event.longitude),
func.min(Event.latitude), func.max(Event.latitude)).all()
print(f'Event boundary:')
print(f'West: {boundary[0][0]:>8.4f}')
print(f'East: {boundary[0][1]:>8.4f}')
print(f'South: {boundary[0][2]:>7.4f}')
print(f'North: {boundary[0][3]:>7.4f}\n')
self.pick_summery()
示例5: get_nvd_github_patch_candidates
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_nvd_github_patch_candidates():
"""Fetches concrete github.com commit links from the Nvd database.
:return:
"""
patch_regex = r"github\.com/([^/]+)/([^/]+)/commit/([^/]+)"
sub_query = (db.session.query(func.min(Reference.id)).filter(
Reference.link.op("regexp")(patch_regex)).group_by(
Reference.nvd_json_id))
github_commit_candidates = (db.session.query(
Nvd.cve_id, Reference.link, Vulnerability).select_from(
join(Nvd, Reference).outerjoin(
Vulnerability, Nvd.cve_id == Vulnerability.cve_id)).filter(
Reference.id.in_(sub_query)).with_labels())
return github_commit_candidates
示例6: _raw_statistics_time_range
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def _raw_statistics_time_range(cls, s, statistics_owner=None):
'''
The time range over which statistics exist (optionally restricted by owner),
ignoring constants at "time zero". This is the first to the last time for
any statistics - it pays no attention to gaps.
'''
from .statistic import StatisticJournal, StatisticName
q = s.query(func.min(StatisticJournal.time), func.max(StatisticJournal.time)). \
filter(StatisticJournal.time > to_time(2 * 24 * 60 * 60.0))
if statistics_owner:
q = q.join(StatisticName).filter(StatisticName.owner == statistics_owner)
start, finish = q.one() # skip entire first day because tz
if start and finish:
return start, finish
else:
raise NoStatistics('No statistics are currently defined')
示例7: get_first_requests
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_first_requests(db_session, endpoint_id, limit=None):
"""
Returns a list with all versions and when they're first used
:param db_session: session for the database
:param limit: only return the most recent versions
:param endpoint_id: id of the endpoint
:return list of tuples with versions
"""
query = (
db_session.query(
Request.version_requested, func.min(Request.time_requested).label('first_used')
)
.filter(Request.endpoint_id == endpoint_id)
.group_by(Request.version_requested)
.order_by(desc('first_used'))
)
if limit:
query = query.limit(limit)
return query.all()
示例8: test_aggregate
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def test_aggregate(self):
foo, Foo = self.tables.foo, self.classes.Foo
sess = create_session()
query = sess.query(Foo)
assert query.count() == 100
assert sess.query(func.min(foo.c.bar)).filter(
foo.c.bar < 30
).one() == (0,)
assert sess.query(func.max(foo.c.bar)).filter(
foo.c.bar < 30
).one() == (29,)
eq_(
query.filter(foo.c.bar < 30)
.with_entities(sa.func.max(foo.c.bar))
.scalar(),
29,
)
示例9: status_code
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def status_code(self) -> int:
"""
For all the transactions associated with this task, get the lowest status code
"""
return min(set(t.status_code for t in self.transactions) or [3])
示例10: status
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def status(cls):
return (
case(
STATUS_INT_TO_STRING,
value=(
select([func.min(BlockchainTransaction.status_code)])
.where(BlockchainTransaction.blockchain_task_id == cls.id)
.label('lowest_status')
),
else_='UNSTARTED'
)
)
示例11: get_deleted_packages
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_deleted_packages(cls):
'''
@return: Returns list of deleted pkgs and date when they were deleted, in
format: [(id, date_ordinal), ...]
'''
def deleted_packages():
# Can't filter by time in select because 'min' function has to
# be 'for all time' else you get first revision in the time period.
package_revision = table('package_revision')
revision = table('revision')
s = select([package_revision.c.id, func.min(revision.c.timestamp)], from_obj=[package_revision.join(revision)]).\
where(package_revision.c.state==model.State.DELETED).\
group_by(package_revision.c.id).\
order_by(func.min(revision.c.timestamp))
res = model.Session.execute(s).fetchall() # [(id, datetime), ...]
res_pickleable = []
for pkg_id, deleted_datetime in res:
res_pickleable.append((pkg_id, deleted_datetime.toordinal()))
return res_pickleable
if cache_enabled:
week_commences = cls.get_date_week_started(datetime.date.today())
key = 'all_deleted_packages_%s' + week_commences.strftime(DATE_FORMAT)
deleted_packages = our_cache.get_value(key=key,
createfunc=deleted_packages)
else:
deleted_packages = deleted_packages()
return deleted_packages
示例12: filter
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def filter(self, qs, value):
if value in EMPTY_VALUES:
return qs
x_column = getattr(self.model, value['x_column'])
y_column = getattr(self.model, value['y_column'])
if value['y_func'] == 'count':
y_func = func.count(y_column)
elif value['y_func'] == 'sum':
y_func = func.sum(y_column)
elif value['y_func'] == 'min':
y_func = func.min(y_column)
elif value['y_func'] == 'max':
y_func = func.max(y_column)
elif value['y_func'] == 'avg':
y_func = func.avg(y_column)
else:
return qs.filter(sql.false())
if value['x_lookup'] and value['x_lookup'] in ['date']:
x_lookup = getattr(func, value['x_lookup'])
x_func = x_lookup(x_column)
else:
x_func = x_column
qs = qs.session.query(x_func.label('group'), y_func.label('y_func')).group_by('group').order_by('group').all()
return qs
示例13: get_earliest
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_earliest(cls):
lowest = database.db.getSession().query(func.min(Blocks.height)).scalar()
return database.db.getSession().query(Blocks).filter(Blocks.height == lowest).first()
# Get a single record by nonce
示例14: downgrade
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def downgrade():
"""Remove share_export_locations table.
This method can lead to data loss because only first export_location
is saved in shares table.
"""
op.add_column('shares',
sa.Column('export_location', sa.String(255)))
export_locations_table = table(
'share_export_locations',
sa.Column('share_id', sa.String(length=36)),
sa.Column('path', sa.String(length=255)),
sa.Column('updated_at', sa.DateTime),
sa.Column('deleted', sa.Integer))
connection = op.get_bind()
session = sa.orm.Session(bind=connection.connect())
export_locations = session.query(
func.min(export_locations_table.c.updated_at),
export_locations_table.c.share_id,
export_locations_table.c.path).filter(
export_locations_table.c.deleted == 0).group_by(
export_locations_table.c.share_id,
export_locations_table.c.path).all()
shares = sa.Table('shares', sa.MetaData(),
autoload=True, autoload_with=connection)
for location in export_locations:
# pylint: disable=no-value-for-parameter
update = (shares.update().where(shares.c.id == location.share_id).
values(export_location=location.path))
connection.execute(update)
op.drop_table('share_export_locations')
session.close_all()
示例15: get_yearly_series
# 需要导入模块: from sqlalchemy import func [as 别名]
# 或者: from sqlalchemy.func import min [as 别名]
def get_yearly_series():
"""Returns a list of yearly generated energy for past years
:return: list of yearly generated energy for past years
"""
return (PVData.query
.with_entities(func.strftime('%Y', PVData.created_at).label('year'),
(func.max(PVData.total_energy) - func.min(PVData.total_energy)).label('yearly_output'))
.group_by(func.strftime('%Y', PVData.created_at))
.all())