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

group_by with custom duration ignores lastest items #268

Closed
NicosKaralis opened this issue Feb 7, 2023 · 1 comment
Closed

group_by with custom duration ignores lastest items #268

NicosKaralis opened this issue Feb 7, 2023 · 1 comment

Comments

@NicosKaralis
Copy link

I'm building a chart with sensor data, aggregated by 15 minutes. it works fine for older records. Today I was looking for the most recent data and I couldn't see the latest group of items.

The data is queried with the following:

# Get the latest data, from 1 hour ago until now
period = 1.hours.ago..Time.now
values = Data.group_by_minute(:created_at, n: 15, range: period, format: '%H:%M').average(:value)

# The time is now 7:58, this is the result
'06:45': 23021.19
'07:00': 23026.92
'07:15': 23046.51
'07:30': 23032.58
'07:45': 23008.76

Since 7:45 is the latest group returned I thought it because the period is not large enough to create the next group so I tried to add 25 minutes more to the groups but it didn't help

# Get the latest data, from 1 hour ago until now
period = 1.hours.ago..(Time.now + 25.minutes)
values = Data.group_by_minute(:created_at, n: 15, range: period, format: '%H:%M').average(:value)

# The time is now 7:58, this is the result
'06:45': 23021.19
'07:00': 23026.92
'07:15': 23046.51
'07:30': 23032.58
'07:45': 23008.76
'08:00': 
'08:15': 

There are objects created between 7:45 and 8:00 but the values never load that.

Is this the intended behavior? Am I missing something?

@ankane
Copy link
Owner

ankane commented Feb 7, 2023

Hey @NicosKaralis, times in the range [7:45, 8:00) are placed in the 7:45 bucket.

@ankane ankane closed this as completed Feb 7, 2023
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

2 participants