I am currently using the Truc
function of Django to aggregate some data within the day and hour.
I would like to do the same but over 15 minutes, instead of an hour or just a minute but I can't figure it out.
Here is an example of my current query:
data_trunc = data_qs.annotate(
start_day=Trunc('date_created', 'minute', output_field=DateTimeField()))
.values('start_day', 'content', 'device')
The problem lies with the 'minutes'
argument that can be passed to Trunc
. As far as I get it, there is no choice inbetween 'hour'
and 'minutes'
.
How can I group my data over 15 minutes and have a larger time span for the data grouping ?
I know that I could do this by hand afterward but I'd really like to have the database do this for me since there is a large dataset to compute and this way is the most efficient one I have yet.
If this is the only way though I am opened to suggestions to the most efficient ways to get around this.
Thanks for your help
Edit
I should have specified I did not wish to use raw SQL to do this and stick with Django ORM or native Python.