Created
September 25, 2014 21:27
-
-
Save ikks/da4d67144018ab780a16 to your computer and use it in GitHub Desktop.
An approach to have a weekly report
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def weekly(query, weeks, initial, final): | |
u"""Returns a partitioned result grouped by 7 days. | |
query: Initial query | |
weeks: Max Number of weeks | |
initial: initial part of the week | |
final: end part of the week | |
You can use like the following: | |
previous = weekly( | |
my_query, 8, 'validated_at__gt', 'validated_at__lte', | |
) | |
""" | |
previous = [] | |
nextw = -7 * weeks | |
week = 0 | |
while week < weeks: | |
ini = now() + timedelta(nextw) | |
end = now() + timedelta(nextw + 7) | |
previous.insert(0, query.filter( | |
**{initial: ini, final: end} | |
).count()) | |
nextw += 7 | |
week += 1 | |
return previous |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment