How can get max & min of a field in a rows object

899 views
Skip to first unread message

Lorin Rivers

unread,
Nov 16, 2010, 3:29:37 PM11/16/10
to web...@googlegroups.com
I've got data with many, many rows, one record for each device that's being sampled every 6 seconds. I'm trying to roll up some of this data by getting the max, min, and average in a time span (for example, a minute).

Is there a way to do that with the rows object? Or do I have to craft queries for each time span to get the max, min, and count?

I tried using find on rows but couldn't get max to work with that.

--
Lorin Rivers
Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
<mailto:lri...@mosasaur.com>
512/203.3198 (m)


mdipierro

unread,
Nov 16, 2010, 3:33:56 PM11/16/10
to web2py-users
fmax=db.table.field.max(),
fmin=db.table.field.min()
fcount=db.table.field.count()
fsum=db.table.field.sum())
rows = db(query).select(fmax,fmin,fcount,fsum)
vmax=rows[0][fmax]
vmin=rows[0][fmin]
vavg=rows[0][fsum]/(rows[0][fcount] or 1)

does not work on GAE
> <mailto:lriv...@mosasaur.com>
> 512/203.3198 (m)
Reply all
Reply to author
Forward
0 new messages