Notice that, it seems you are using [-1] because want to get the last
record where the user was awake/light sleep/sleep, however you don't use an
order by, so depending on the strategy the database decides to use, there's
no guarantee that it will be the last. This is also inefficient because you
only want the last record and you're getting all the records and they could
be hundreds in the future.
Couldn't you just do:
last_sleep = db(db.sleep.id > 0).select(orderby=~db.sleep.id,
limitby=(0,1)).first()
gauge.add('Awake', [{'value':last_sleep.awake if last_sleep else 0,
'max_value': 24}])
gauge.add('Light Sleep', [{'value':last_sleep.light_sleep if last_sleep
else 0, 'max_value': 24}])
gauge.add('Deep Sleep', [{'value':last_sleep.deep_sleep if last_sleep
else 0, 'max_value': 24}])
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.