On Tuesday, March 19, 2019 at 5:45:42 PM UTC-7, Leonel Câmara wrote:
>
> Notice that, it seems you are using [-1] because
>
I thought he was doing that to test our ability to count brackets, braces,
and parens. (GG's default font, as used on my screen, makes them very
close in appearance; using the code wrapper helps by monospacing.)
> 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}])
>
and there you see an example of what I have a hard time doing right ...
conditionals in comprehensions.
/dps
--
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.