This works well Boss!!
Thanks a lot and God Bless!
Regards

On Wed, Mar 20, 2019 at 3:45 AM Leonel Câmara <leonelcam...@gmail.com>
wrote:

> 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 a topic in the
> Google Groups "web2py-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/web2py/9mI7-ZkpA_0/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> web2py+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to