agoragames / kairos

Python module for time series data in Redis and Mongo
BSD 3-Clause "New" or "Revised" License
207 stars 38 forks source link

Getting most recent value? #57

Closed mcowger closed 1 year ago

mcowger commented 9 years ago

Sometimes I have a need to get the most recent value of a given name/interval pair, but I dont know what the timestamp of that is.

Obviously t.get(name,interval) doesn't really work, because it uses time.time() as the timestamp, and the chances of that matching are unlikely...usually it just comes back with an empty set.

Is there a pattern for 'give me the most recent non-empty value for this metric/interval'?

mcowger commented 9 years ago

I believe I may have solved my own issue:

most_recent_timestamp = t.properties(name)[interval]['last']
timestamp, value = t.get(name,interval,timestamp=most_recent_timestamp,condense=True).popitem(last=True)

Seems to do what I'm looking for....

awestendorf commented 9 years ago

Yeah that's the right way to go about that. I'll make some helpers to get the first and last value, I can see that being very useful

awestendorf commented 9 years ago

As it turns out, I started the branch first-last awhile ago with just this use case in mind. I'll try to get that rolled out soon.

mcowger commented 9 years ago

I think if you extend it to last "n" or first "n" it would be really valuable.

On Jan 16, 2015, at 2:02 PM, Aaron Westendorf notifications@github.com wrote:

As it turns out, I started the branch first-last awhile ago with just this use case in mind. I'll try to get that rolled out soon.

— Reply to this email directly or view it on GitHub.