As said in this previous question, I am using the Reactive library in a C# project to group incoming data according to pre-configured policies. All these data implement the following interface:
public interface IPoint
{
object Value { get; }
DateTimeOffset Timestamp { get; }
}
My goal is to implement a "hopping" buffer based on the Timestamp
s of the received data (both buffer size and hop/shift size are declared at the beginning as TimeSpan
s). Hop/shift size can be less than the buffer size, which means that some IPoint
instances can belong to more than one group.
An example: considering the following IPoint
Value: 1, Timestamp: "2021-05-25T00:00:01"
Value: 2, Timestamp: "2021-05-25T00:00:02"
Value: 3, Timestamp: "2021-05-25T00:00:03"
Value: 4, Timestamp: "2021-05-25T00:00:04"
Value: 5, Timestamp: "2021-05-25T00:00:05"
- with a buffer size of 3 seconds and a hop/shift size of 2 seconds, I am expecting them to be grouped as
[1, 2, 3], [3, 4, 5]
. - with a buffer size of 2 seconds and a hop/shift size of 3 seconds, I am expecting them to be grouped as
[1, 2], [4, 5]
I've seen that there is a Buffer(timeSpan, timeShift)
extension doing this job, but it considers a runtime-calculated timestamp instead of the ones of the passed IPoint
s.
I've tried to look for a solution, but I couldn't find anything helpful.
I am a newbie at Reactive, so any helpful comment is welcome (also for the other question). Thank you.
Edit: as in the previous question, I am using an ISubject<IPoint>
in this way:
ISubject<IPoint> subject = new Subject<IPoint>();
// ...
// when new data come from an external source
public void Add(IPoint newPoint)
{
subject.OnNext(newPoint);
}
// subscription made by another class in order to be called when "hopping" buffer is ready
public void Subscribe(Action<IEnumerable<IPoint>> callback)
{
// TODO: implement buffer + .Subscribe(callback)
}