本文整理汇总了Python中sqlalchemy.sql.func.min函数的典型用法代码示例。如果您正苦于以下问题:Python min函数的具体用法?Python min怎么用?Python min使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了min函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
def get(self):
args = self.parse_arg()
releases = db.session.query(
func.count(Release.value).label('count'),
func.min(Release.activities).label('activities'),
func.sum(Release.value).label('total_value'),
Buyer.name.label('buyer'),
func.min(Buyer.slug).label('buyer_slug'))
releases = self.filter_request(releases, args)
releases = releases.filter(Buyer.id == Release.buyer_id)
releases = releases.group_by(Buyer.name)
releases = self.sort_request(releases, args)
release_count = releases.count()
(releases, offset, limit) = self.offset_limit(releases, args)
#Generate output structure
output = dict()
output["meta"] = {
"count": release_count,
"pagination" : {"offset" : offset, "limit": limit}
}
output["releases"] = [r._asdict() for r in releases]
return output
示例2: __get_subquery
def __get_subquery(self, *args, ord_by=None):
def add_joined_search(field_name):
joined = db(Search.index, func.min(Search.text).label('text'),
func.min(Search.table_name).label('table_name'),
index=subquery_search.subquery().c.index).filter(
Search.kind.in_(tuple(field_name))).group_by(Search.index)
return joined
subquery_search = db(Search.index.label('index'),
func.sum(Search.relevance).label('relevance'),
func.min(Search.table_name).label('table_name'),
func.min(Search.md_tm).label('md_tm'),
func.max(Search.position).label('position'),
func.max(Search.text).label('text')).filter(
or_(*self.__get_search_params(*args))).group_by('index')
if type(ord_by) in (str, list, tuple):
order = self.__get_order('text', 'text')
subquery_search = add_joined_search(ord_by)
elif type(ord_by) == int:
ord_to_str = self.__order_by_to_str[ord_by]
order = self.__get_order(ord_to_str, ord_to_str)
else:
order = self.__get_order('relevance', 'relevance')
if 'md_tm' in str(order):
subquery_search = subquery_search.order_by(order)
else:
subquery_search = subquery_search.order_by(order).order_by(
self.__get_order('md_tm', 'md_tm'))
return subquery_search
示例3: __init__
def __init__(self, engine=None, start_date='1925-12-31', end_date='',
limit=None, all_vars=None, **kwargs):
super(CCMNamesQuery, self).__init__(engine, limit)
logging.info("---- Creating a CCM-MSENAMES query session. ----")
msenames = self.tables['msenames']
ccmxpf_linktable = self.tables['ccmxpf_linktable']
id_vars = [msenames.c.permno, msenames.c.permco,
ccmxpf_linktable.c.gvkey, msenames.c.comnam]
query = sa.select(id_vars+\
[func.min(msenames.c.namedt).label('sdate'),
func.max(msenames.c.nameendt).label('edate')],
group_by = id_vars,
order_by = id_vars,
limit= self.limit).\
where(ccmxpf_linktable.c.linktype.startswith('L')).\
where(ccmxpf_linktable.c.linkprim.in_(['P','C'])).\
where(ccmxpf_linktable.c.usedflag==1).\
where((ccmxpf_linktable.c.linkdt <= msenames.c.namedt) |
(ccmxpf_linktable.c.linkdt == None)).\
where((msenames.c.nameendt <= ccmxpf_linktable.c.linkenddt) |
(ccmxpf_linktable.c.linkenddt == None)).\
where(msenames.c.permno == ccmxpf_linktable.c.lpermno).\
where(msenames.c.permco == ccmxpf_linktable.c.lpermco)
if start_date:
query = query.having(func.min(msenames.c.namedt) >= start_date)
if end_date:
query = query.having(func.max(msenames.c.nameendt) <= end_date)
logging.debug(query)
self.query = query
示例4: annotation_objects_in_frame
def annotation_objects_in_frame(self, frame):
"""
Returns annotation objects related to this video that are visible in given time.
AnnotationValues are lazily-loaded, in comparison to annotation_objects_in_frame_intervals()
SQL:
SELECT annotation_objects....., min(annotation_values.frame_from) AS min_1, max(annotation_values.frame_from) AS max_1
FROM annotation_objects
INNER JOIN annotation_values ON annotation_objects.id = annotation_values.annotation_object_id
WHERE annotation_objects.video_id = %s
GROUP BY annotation_objects.id
HAVING min(annotation_values.frame_from) <= %s AND max(annotation_values.frame_from) >= %s
ORDER BY min(annotation_values.frame_from), max(annotation_values.frame_from), annotation_objects.id
:rtype: list of (AnnotationObject, int, int)
"""
q = database.db.session.query(AnnotationObject, func.min(AnnotationValue.frame_from), func.max(AnnotationValue.frame_from))
q = q.filter_by(video_id=self.id)
q = q.join(AnnotationObject.annotation_values)
q = q.group_by(AnnotationObject.id)
q = q.having((func.min(AnnotationValue.frame_from) <= frame) & (func.max(AnnotationValue.frame_from) >= frame))
q = q.order_by(func.min(AnnotationValue.frame_from), func.max(AnnotationValue.frame_from), AnnotationObject.id)
q = q.all()
return q
示例5: listSessions
def listSessions(request):
ssnTmCnt = request.session.query(Session)\
.add_column(func.min(Pagerecording.time))\
.add_column(func.count(Pagerecording.id))\
.join(Pagerecording).group_by(Session)\
.order_by(func.min(Pagerecording.time).desc()).all()
return render_to_response('sessionlist.mako', {'ssnTmCnt':ssnTmCnt}, request=request)
示例6: backup_duration
def backup_duration(bddate):
s = select([pool.c.name, func.min(job.c.starttime), func.max(job.c.endtime)], use_labels=True).where(and_(job.c.poolid == pool.c.poolid, cast(job.c.schedtime,Date) <= datetime.fromtimestamp(float(bddate)), cast(job.c.schedtime,Date) >= datetime.fromtimestamp(float(bddate)) - timedelta(days=1))).group_by(pool.c.name, job.c.schedtime)
bd = db.execute(s).fetchall()
bd_result = {}
for bpool in bd:
bd_result.update({ bpool[0]: { 'start': bpool[1], 'end': bpool[2] } })
s = select([func.min(job.c.starttime), func.max(job.c.endtime)], use_labels=True).where(job.c.poolid == pool.c.poolid)
_min_date, _max_date = db.execute(s).fetchone()
min_date = int(mktime((strptime(str(_min_date), "%Y-%m-%d %H:%M:%S"))))
max_date = int(mktime((strptime(str(_max_date), "%Y-%m-%d %H:%M:%S"))))
return render_template('backup_duration.html', title="Backup duration time", bd_result=bd_result, bddate=int(bddate), min_date=min_date, max_date=max_date)
示例7: add_joined_search
def add_joined_search(field_name):
joined = (
db(
Search.index,
func.min(Search.text).label("text"),
func.min(Search.table_name).label("table_name"),
index=subquery_search.subquery().c.index,
)
.filter(Search.kind.in_(tuple(field_name)))
.group_by(Search.index)
)
return joined
示例8: get_order
def get_order(order_name, desc_asc, field):
order_name += "+" if desc_asc == "desc" else "-"
result = {
"text+": lambda field_name: desc(func.max(getattr(Search, field_name, Search.text))),
"text-": lambda field_name: asc(func.max(getattr(Search, field_name, Search.text))),
"md_tm+": lambda field_name: desc(func.min(getattr(Search, field_name, Search.md_tm))),
"md_tm-": lambda field_name: asc(func.min(getattr(Search, field_name, Search.md_tm))),
"relevance+": lambda field_name: desc(func.sum(getattr(Search, field_name, Search.relevance))),
"relevance-": lambda field_name: asc(func.sum(getattr(Search, field_name, Search.relevance))),
"position+": lambda field_name: desc(func.max(getattr(Search, field_name, Search.position))),
"position-": lambda field_name: asc(func.max(getattr(Search, field_name, Search.position))),
}[order_name](field)
return result
示例9: analytics_closer
def analytics_closer():
user1 = db.session.query(User).get(int(request.args.get("user1")))
user2 = db.session.query(User).get(int(request.args.get("user2")))
if request.args.get("criterion") == "artist":
field = Scrobble.artist
if request.args.get("criterion") == "track":
field = func.concat(Scrobble.artist, Scrobble.track)
start_uts = max(
db.session.query(func.min(Scrobble.uts)).filter_by(user=user1),
db.session.query(func.min(Scrobble.uts)).filter_by(user=user2)
)
def gather_shares(user):
data = {}
for (share, uts) in db.session.query(field, Scrobble.uts).filter(Scrobble.user == user, Scrobble.uts >= start_uts):
week = int(math.floor(uts / (86400 * 7)) * (86400 * 7))
if week not in data:
data[week] = set()
if share not in data[week]:
data[week].add(share)
return data
user1_shares = gather_shares(user1)
user2_shares = gather_shares(user2)
if request.args.get("criterion_type") == "integral":
def integrate_shares(shares):
prev_week = None
for week in sorted(shares.keys()):
if prev_week:
shares[week] = set.union(shares[week], shares[prev_week])
prev_week = week
return shares
user1_shares = integrate_shares(user1_shares)
user2_shares = integrate_shares(user2_shares)
data = [
[
date.fromtimestamp(week).strftime("%b %Y"),
len(user1_shares[week] - user2_shares[week]) / float(len(user1_shares[week])),
"",
", ".join(sorted(user1_shares[week] - user2_shares[week])),
-len(user2_shares[week] - user1_shares[week]) / float(len(user2_shares[week])),
"",
", ".join(sorted(user2_shares[week] - user1_shares[week])),
]
for week in sorted(set.intersection(set(user1_shares.keys()), set(user2_shares.keys())))
]
return dict(user1=user1, user2=user2, data=json.dumps(data))
示例10: annotation_objects_all
def annotation_objects_all(self):
"""
Returns all annotation objects related to this video, with object's first and last frame.
Annotation objects are sorted by the time of theirs first occurrence in the video.
:rtype: list of (AnnotationObject, int, int)
"""
q = database.db.session.query(AnnotationObject, func.min(AnnotationValue.frame_from), func.max(AnnotationValue.frame_from))
q = q.filter_by(video_id=self.id)
q = q.join(AnnotationObject.annotation_values)
q = q.group_by(AnnotationObject.id)
q = q.order_by(func.min(AnnotationValue.frame_from), func.max(AnnotationValue.frame_from), AnnotationObject.id)
return q.all()
示例11: statArtistReleaseCount
def statArtistReleaseCount(self):
artistAverageCount = self.dbSession.query(func.avg(Artist.releases))
artistMinimumCount = self.dbSession.query(func.min(Artist.releases)).scalar()
artistMaximumCount = self.dbSession.query(func.max(Artist.releases)).scalar()
artistMaximumId = ''
artistMaxName = ''
return {
'title': 'Artist Release Count',
'class': 'fa-user',
'average': {
'type': 'string',
'value': artistAverageCount,
'detail': {
'text': ''
}
},
'minimum': {
'type': 'string',
'value': artistMinimumCount,
'detail': {
'text': 'Many'
}
},
'maximum': {
'type': 'artist',
'value': artistMaximumCount,
'detail': {
'id': artistMaximumId,
'thumbnailUrl': '/images/artist/thumbnail/' + artistMaximumId,
'detailUrl': '/artist/' + artistMaximumId,
'text': artistMaxName
}
}
}
示例12: stats
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
示例13: find_day2scrobbles
def find_day2scrobbles(user, artist):
day2scrobbles = OrderedDict([(day, 0)
for day in range(int(db.session.query(func.coalesce(func.min(Scrobble.uts), 0)).\
filter(Scrobble.user == user,
Scrobble.artist == artist).\
scalar() / 86400),
int(db.session.query(func.coalesce(func.max(Scrobble.uts), 0)).\
filter(Scrobble.user == user,
Scrobble.artist == artist).\
scalar() / 86400) + 1)])
for uts, in db.session.query(Scrobble.uts).\
filter(Scrobble.user == user,
Scrobble.artist == artist):
day2scrobbles[int(uts / 86400)] += 1
for day in day2scrobbles:
if day2scrobbles[day] < 4:
day2scrobbles[day] = 0
for day in day2scrobbles:
if day2scrobbles[day] != 0:
break
del day2scrobbles[day]
for day in reversed(day2scrobbles):
if day2scrobbles[day] != 0:
break
del day2scrobbles[day]
return day2scrobbles
示例14: findMinAndMax
def findMinAndMax(name,field):
min = {"name":"Min","value":db.session.query(func.min(field)).first()[0]}
max = {"name":"Max","value":db.session.query(func.max(field)).first()[0]}
array = {"name":name,"values":[min,max]}
return array
示例15: get
def get(self, bucket_id):
b = Bucket.query.filter_by(id=bucket_id).first()
if b is None:
return {'status':'error',
'description':'Bucket ' + bucket_id + ' does not exists.'}, 204
u = User.query.filter_by(id=b.user_id).first()
if u.id != g.user.id and b.private != '0':
return {'status':'error',
'description':'Private Bucket'}, 401
result = db.session.query(Post.date).filter(Post.bucket_id==bucket_id).distinct(Post.date).all()
data = {}
if len(result) == 0:
return {'status':'error',
'description':'No rows returned'}, 204
else:
dateList = []
for i in range(len(result)):
dateList.append(result[i][0])
data['count'] = len(result)
data['minDate'] = db.session.query(func.min(Post.date).label("min_date")).filter(Post.bucket_id==bucket_id).first().min_date
data['maxDate'] = db.session.query(func.max(Post.date).label("max_date")).filter(Post.bucket_id==bucket_id).first().max_date
data['dateList'] = dateList
return {'status':'success',
'description': 'Data successfully returned.',
'data':data}, 200