Exemplo n.º 1
0
        public IDisposable Subscribe(IObserver <double> obsvr)
        {
            var ret = new CompositeDisposable();

            if (_offset != null)
            {
                ret.Add(_offset.Subscribe(ofst => {
                    for (int itr = 0; itr < _count; ++itr)
                    {
                        long idx           = (_ring.head + itr) % _period;
                        _ring.buffer[idx] += ofst;
                    }
                    _total += ofst * _count;
                }));
            }
            ret.Add(_source.Subscribe(val => {
                // calculate  ( Insert QTY times)
                for (int itr = 0; itr < val.QTY; itr++)
                {
                    OnVal(val.PX, _ring.Enqueue(val.PX));
                }
                // count matches window size  publish
                if (_count == _period)
                {
                    obsvr.OnNext(_total / _period);
                }
            }, obsvr.OnError, obsvr.OnCompleted));
            return(ret);
        }
Exemplo n.º 2
0
        public IDisposable Subscribe(IObserver <double> obsvr)
        {
            var ret = new CompositeDisposable();

            // offset calculations are associated with future product rolls.
            if (_offset != null)
            {
                ret.Add(_offset.Subscribe(ofst => {
                    for (int itr = 0; itr < _count; ++itr)
                    {
                        long idx           = (_ring.head + itr) % _period;
                        _ring.buffer[idx] += ofst;
                    }
                    _total += ofst * _count;
                }));
            }
            // data subscription
            ret.Add(_source.Subscribe(val => {
                OnVal(val, _ring.Enqueue(val), obsvr);                  //    calculate
                if (_count == _period)
                {
                    obsvr.OnNext(_total);                              //     publish
                }
            }, obsvr.OnError, obsvr.OnCompleted));
            return(ret);
        }
Exemplo n.º 3
0
        internal static IObservable <Tuple <TSource, TSource> > RollingWindowX <TSource>(this IObservable <TSource> source, uint period)
        {
            RingWnd <TSource> ring = new RingWnd <TSource>(period);

            return(Observable.Create <Tuple <TSource, TSource> >(obs => {
                return source.Subscribe(newVal => {
                    obs.OnNext(new Tuple <TSource, TSource>(newVal, ring.Enqueue(newVal)));
                }, obs.OnError, obs.OnCompleted);
            }));
        }
Exemplo n.º 4
0
 void OnNext(double newVal, IObserver <DATA_POS <double> > obsvr)
 {
     OnNext(newVal, _ring.Enqueue(newVal));
     //send outgoing
     if (_count >= (_period - 1))
     {
         obsvr.OnNext(lnkQue.First.Value);
     }
     else
     {
         _count++;
     }
 }
Exemplo n.º 5
0
        public IDisposable Subscribe(IObserver <double> obsvr)
        {
            var ret = new CompositeDisposable();

            if (_offset != null)
            {
                ret.Add(_offset.Subscribe(ofst => {
                    Debug.Assert(false, "Needs to Implement");
                    //empty for now
                }));
            }
            ret.Add(_source.Subscribe(val => OnVal(val, _ring.Enqueue(val), obsvr), obsvr.OnError, obsvr.OnCompleted));
            return(ret);
        }
Exemplo n.º 6
0
        public IDisposable Subscribe(IObserver <double> obsvr)
        {
            var ret = new CompositeDisposable();

            // offset calculations
            if (_offset != null)
            {
                ret.Add(_offset.Subscribe(ofst => {
                    //step 1
                    _weighted += ofst * m_weight;
                    // step 2
                    for (int itr = 0; itr < _count; ++itr)
                    {
                        long idx           = (_ring.head + itr) % _period;
                        _ring.buffer[idx] += ofst;
                    }
                    _total += ofst * _count;
                }));
            }
            ret.Add(_source.Subscribe(val => OnVal(val, _ring.Enqueue(val), obsvr), obsvr.OnError, obsvr.OnCompleted));
            return(ret);
        }