You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stream.periodic(n) returns a stream of every nth element of the original stream. I can't think of a way to do this with existing primitives. This could be useful in a number of contexts but I'm primarily thinking that it will be useful with triggers (#997).
Imagine you want to keep a log of the frequency of table inserts but don't need to log every insert. With triggers and periodic you can do this easily with the following script:
importrethinkdbasrfromdatetimeimportdatetimelog=open('/tmp/insert_log.txt', 'w+')
c=r.connect(host, port)
foreventinr.table('foo').on_insert().periodic(100).run(c):
log.write("[%s] 100 inserts on 'foo'\n"%datetime.utcnow())
@hardkrash: Consider the possibility of having a data set with points at times ..., t_i, t_{i+1}, t_{i+2}, ... where t_{i+1} - t_i != t_{i+2} - t_{i+1}.
Do you find that this is common (in your experience, I guess)? Based on my vague memory of another post you've made, I guess maybe not, (edit: never mind, now I read another post, and maybe so) but:
If so, and you wanted interpolation to fill in data, how would you want it to happen: exactly X samples between each original data point? Enough points between each original data point such that the difference between successive times is bounded above? That, with the stipulation that the query errors if the distance between two successive time points is above some stipulated value (as a safety valve if one of the datums has a garbage time value)? (Also, would you want some kind of downsample operation that takes a sample every u seconds, say, the first sample after t_0 + k*u for k = 0,1,2,...?)
Most of data logging is done at fixed sampling rates, but often there are better ways depending on signal type.
Storing data is where you pull out the tricks to save space and bring out details.
Getting data out of the database is different then how the data is stored and manipulated internally during queries.
Interpolation should be optional and configurable.
Interpolation should make queries more effective.
Advanced stuff should be left to the client.
/TLDR
I think your asking me about varying sample rates. Where some data may be collected with varying time between samples.
There are some techniques where this method works great. Imagine a slowly varying signal you could in the data collection phase monitor it once a second. It might not move more that one value quanta per few seconds/minutes/hours. You are better off recording that it took t amount of time to move to a new value.
There are other techniques that solve a different problem, sporadic events. Save a low data rate signal for most of the time from a high speed data converter. Then when an interesting event comes around save it in full resolution for the duration of the interesting event. you have the background trend, but also that interesting tidbit of time when there was a spike.
A desirable time series interpolation performed in a query would be like the following scenario.
I'm collecting the temperature of my pool every hour on the hour, but I want to know what temperature it was at when I was swimming. So my application queries for when I was swimming over the past month. We have data samples that are before and after a swim time. So, what was the temperature for my swim. A linear interpolation would say average the before and after data point. Then that linear interpolated data point is joined with the swim event data Then it returns what it expects the swimming pool temperature to be and date time of when I was swimming over the last month.
Other interpolations exist to make a better guess. A curve fit of a few data points before and after would be another option.
There are various ways to cope with the swimming pool temperature time series data log, both in a lossy and non lossy methods.
Lets look at this from how we could make it better. First remove the once an hour sampling rate, I bet that it is not recording interesting data. Let's make some rules for storage. Run length encoding can help but recording the time and new value after some delta change in temperature. My thermometer has a resolution of 0.5°C and a accuracy of 2°C.
Store it with a value resolution of 1°C we might be able to get away with a 2°C resolution later. (old data could be downgraded.) Then record the time when the value would change to a new value. Be sure to keep a hysteresis in play to prevent storing many irrelevant perturbations around the change point. then look at the effective resolution of time. It might be that having 1 second resolution vs 1 minute resolution is no true concern. i.e. The pool can't raise a single degree in less than that one minute.
(Also, would you want some kind of downsample operation that takes a sample every u seconds, say, the first sample after t_0 + k*u for k = 0,1,2,...?)
That kinda interesting resample to a seconds (time). I could see a use for some folks. Take the once a second temperature of my house and give the temperature every hour.
With time series try NOT to think of time in only integer seconds, it can lead to some odd decisions and missed opportunities. Try to think of them as either a frequency (10 samples per second) or as an integer multiple of a time interval.
Think of time series as one of two general classes.
Samples at a fixed sampling rate.
Samples recorded with a specific time.
Missing values are an interesting issue, error out or interpolate. Not sure, it depends on the scenario.
Activity
coffeemug commentedon Jul 11, 2013
Intriguing. Moving to backlog since we're past debating timebox for this release, but we'll come back to this.
jdoliner commentedon Jul 11, 2013
Psh, just use mapreduce:
chere stands for counter,vfor value andrfor result.jdoliner commentedon Jul 11, 2013
(This does every fourth element.)
wmrowan commentedon Jul 11, 2013
Oh I somehow didn't think of that myself. I didn't realize this could be done with existing primitives. I withdraw my proposal then.
jdoliner commentedon Jul 11, 2013
I still think this is a totally legit idea, that mapreduce is none too user friendly and it's sinfully inefficient.
coffeemug commentedon Jul 11, 2013
Reopening because
.periodic(100)is just slightly more user friendly than... that.mlucy commentedon Jul 11, 2013
Also, if we implemented
periodiccorrectly you could call it on a large stream without loading the whole thing into memory.hardkrash commentedon Jul 11, 2014
My signals and systems brain hurts with the term periodic. I think of it as a generator of data like a periodic signal e.g. sin(x).
The python folks call it a step, it could also could be called a stride.
This is related to #2664 as these could be considered time series.
As a you would have these functions.
Arguably you could also add the opposites.
srh commentedon Jul 11, 2014
@hardkrash: Consider the possibility of having a data set with points at times ..., t_i, t_{i+1}, t_{i+2}, ... where t_{i+1} - t_i != t_{i+2} - t_{i+1}.
Do you find that this is common (in your experience, I guess)? Based on my vague memory of another post you've made, I guess maybe not, (edit: never mind, now I read another post, and maybe so) but:
If so, and you wanted interpolation to fill in data, how would you want it to happen: exactly X samples between each original data point? Enough points between each original data point such that the difference between successive times is bounded above? That, with the stipulation that the query errors if the distance between two successive time points is above some stipulated value (as a safety valve if one of the datums has a garbage time value)? (Also, would you want some kind of downsample operation that takes a sample every u seconds, say, the first sample after t_0 + k*u for k = 0,1,2,...?)
hardkrash commentedon Jul 12, 2014
TLDR
/TLDR
I think your asking me about varying sample rates. Where some data may be collected with varying time between samples.
There are some techniques where this method works great. Imagine a slowly varying signal you could in the data collection phase monitor it once a second. It might not move more that one value quanta per few seconds/minutes/hours. You are better off recording that it took t amount of time to move to a new value.
There are other techniques that solve a different problem, sporadic events. Save a low data rate signal for most of the time from a high speed data converter. Then when an interesting event comes around save it in full resolution for the duration of the interesting event. you have the background trend, but also that interesting tidbit of time when there was a spike.
A desirable time series interpolation performed in a query would be like the following scenario.
I'm collecting the temperature of my pool every hour on the hour, but I want to know what temperature it was at when I was swimming. So my application queries for when I was swimming over the past month. We have data samples that are before and after a swim time. So, what was the temperature for my swim. A linear interpolation would say average the before and after data point. Then that linear interpolated data point is joined with the swim event data Then it returns what it expects the swimming pool temperature to be and date time of when I was swimming over the last month.
Other interpolations exist to make a better guess. A curve fit of a few data points before and after would be another option.
There are various ways to cope with the swimming pool temperature time series data log, both in a lossy and non lossy methods.
Lets look at this from how we could make it better. First remove the once an hour sampling rate, I bet that it is not recording interesting data. Let's make some rules for storage. Run length encoding can help but recording the time and new value after some delta change in temperature. My thermometer has a resolution of 0.5°C and a accuracy of 2°C.
Store it with a value resolution of 1°C we might be able to get away with a 2°C resolution later. (old data could be downgraded.) Then record the time when the value would change to a new value. Be sure to keep a hysteresis in play to prevent storing many irrelevant perturbations around the change point. then look at the effective resolution of time. It might be that having 1 second resolution vs 1 minute resolution is no true concern. i.e. The pool can't raise a single degree in less than that one minute.
hardkrash commentedon Jul 12, 2014
That kinda interesting resample to a seconds (time). I could see a use for some folks. Take the once a second temperature of my house and give the temperature every hour.
With time series try NOT to think of time in only integer seconds, it can lead to some odd decisions and missed opportunities. Try to think of them as either a frequency (10 samples per second) or as an integer multiple of a time interval.
Think of time series as one of two general classes.
Missing values are an interesting issue, error out or interpolate. Not sure, it depends on the scenario.
thelinuxlich commentedon Oct 1, 2014
+1