Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect function location #42

Open
llirrikk opened this issue Mar 5, 2023 · 0 comments
Open

Incorrect function location #42

llirrikk opened this issue Mar 5, 2023 · 0 comments

Comments

@llirrikk
Copy link

llirrikk commented Mar 5, 2023

According to the official documentation, the functions should be after the keyword "SELECT".

I wrote:

ranges = (datetime.now() - timedelta(days=3), datetime.now())
res = Metric.timescale\
    .filter(pool=pool, time__range=ranges)\
    .values('time', 'value')

And I've got this SQL:

SELECT "graphs_volume24hoursmetric"."time", "graphs_volume24hoursmetric"."value"
FROM "graphs_volume24hoursmetric"
WHERE ("graphs_volume24hoursmetric"."pool_id" = c6e6b7bd-1f0e-4766-89ed-56bc592742ed AND "graphs_volume24hoursmetric"."time" BETWEEN 2023-03-02 10:58:03.333117+00:00 AND 2023-03-05 10:58:03.333130+00:00)

This query outputs all the points that were created after 3 days.


Then I've used time_bucket_gapfill according to the documentation in the README.
Wrote:

ranges = (datetime.now() - timedelta(days=3), datetime.now())
res = Volume24HoursMetric.timescale\
    .filter(pool=pool, time__range=ranges)\
    .time_bucket_gapfill('time', '1 day', ranges[0], ranges[1])\
    .annotate(value=Avg('value'))\
    .values('time', 'value'

Got:

SELECT "graphs_volume24hoursmetric"."time", AVG("graphs_volume24hoursmetric"."value") AS "value"
FROM "graphs_volume24hoursmetric" WHERE ("graphs_volume24hoursmetric"."pool_id" = c6e6b7bd-1f0e-4766-89ed-56bc592742ed AND "graphs_volume24hoursmetric"."time" BETWEEN 2023-03-02 11:07:24.915758+00:00 AND 2023-03-05 11:07:24.915784+00:00) 
GROUP BY time_bucket_gapfill(INTERVAL 1 day, "graphs_volume24hoursmetric"."time", 2023-03-02 11:07:24.915758+00:00, 2023-03-05 11:07:24.915784+00:00), "graphs_volume24hoursmetric"."time"

Hoping to get 3 points, I get some bullshit out of 40 points.
According to the official documentation, you need to use the function after the 'SELECT" keyword, and not after "GROUP BY". In my case, aggregation should occur in the interval of 1 day, not 40.

Time buckets are usually used together with GROUP BY to aggregate data. But you can also run time_bucket on a single time value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant