コード例 #1
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var values      = (ICollection <Object>)target;
            var queue       = new LinkedList <object>();

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var item = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (item != null)
                {
                    queue.AddLast(item);
                }
            }

            return(queue);
        }
コード例 #2
0
ファイル: EnumEvalWhereScalar.cs プロジェクト: valmac/nesper
        public override Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            var result    = new LinkedList <Object>();
            var evalEvent = new ObjectArrayEventBean(new Object[1], Type);

            foreach (Object next in target)
            {
                evalEvent.Properties[0]       = next;
                eventsLambda[StreamNumLambda] = evalEvent;

                var pass = (bool?)InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.GetValueOrDefault(false))
                {
                    continue;
                }

                result.AddLast(next);
            }

            return(result);
        }
コード例 #3
0
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            double sum   = 0d;
            int    count = 0;

            var beans = target;

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var num = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (num == null)
                {
                    continue;
                }
                count++;
                sum += num.AsDouble();
            }

            if (count == 0)
            {
                return(null);
            }
            return(sum / count);
        }
コード例 #4
0
        public override ComputationResult Evaluate(IDataSource[] dataSources)
        {
            var inner = InnerExpression.Evaluate(dataSources);

            if (inner.IsValue)
            {
                return(new ComputationResult(-inner.LiteralValue));
            }
            else if (inner.IsVectorResult)
            {
                var ret = inner.Accumulator ? inner.VectorData : inner.VectorData.CreateSimilarArray <float>();
                VectorHelper.Negate(ret.GetFlatData(), inner.VectorData.GetFlatData());
                return(new ComputationResult(ret, true, inner.Direction));
            }
            else
            {
                var ret       = inner.Accumulator ? inner.OdData : inner.OdData.CreateSimilarArray <float>();
                var flatRet   = ret.GetFlatData();
                var flatInner = inner.OdData.GetFlatData();
                for (int i = 0; i < flatRet.Length; i++)
                {
                    VectorHelper.Negate(flatRet[i], flatInner[i]);
                }
                return(new ComputationResult(ret, true));
            }
        }
コード例 #5
0
ファイル: EnumEvalDistinctEvents.cs プロジェクト: ikvm/nesper
        public Object EvaluateEnumMethod(
            EventBean[] eventsLambda,
            ICollection <object> target,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            var beans = (ICollection <EventBean>)target;

            if (beans.IsEmpty() || beans.Count == 1)
            {
                return(beans);
            }

            var evaluateParams = new EvaluateParams(eventsLambda, isNewData, context);
            var distinct       = new LinkedHashMap <IComparable, EventBean>();

            foreach (var next in beans)
            {
                eventsLambda[StreamNumLambda] = next;

                var comparable = (IComparable)InnerExpression.Evaluate(evaluateParams);
                if (!distinct.ContainsKey(comparable))
                {
                    distinct.Put(comparable, next);
                }
            }

            return(distinct.Values);
        }
コード例 #6
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var result = new LinkedHashMap <object, ICollection <object> >();

            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var values      = target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;
                var key = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));

                resultEvent.Properties[0] = next;
                var entry = _secondExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));

                var value = result.Get(key);
                if (value == null)
                {
                    value = new List <object>();
                    result.Put(key, value);
                }
                value.Add(entry);
            }

            return(result);
        }
コード例 #7
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda,
                                         ICollection <object> target,
                                         bool isNewData,
                                         ExprEvaluatorContext context)
        {
            double sum                  = 0d;
            int    count                = 0;
            var    resultEvent          = new ObjectArrayEventBean(new Object[1], _resultEventType);
            ICollection <object> values = target;

            foreach (object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                object num = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (num == null)
                {
                    continue;
                }
                count++;
                sum += num.AsDouble();
            }

            if (count == 0)
            {
                return(null);
            }
            return(sum / count);
        }
コード例 #8
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var items  = new LinkedHashMap <Object, int?>();
            var values = target;

            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var item = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));

                int?existing;
                if (!items.TryGetValue(item, out existing))
                {
                    existing = 1;
                }
                else
                {
                    existing++;
                }
                items.Put(item, existing);
            }

            return(EnumEvalMostLeastFrequentEvent.GetResult(items, _isMostFrequent));
        }
コード例 #9
0
        public override Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            var result     = new LinkedList <Object>();
            var indexEvent = new ObjectArrayEventBean(new Object[1], IndexEventType);

            int count = -1;

            foreach (EventBean next in target)
            {
                count++;

                indexEvent.Properties[0]          = count;
                eventsLambda[StreamNumLambda]     = next;
                eventsLambda[StreamNumLambda + 1] = indexEvent;

                var pass = (bool?)InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.HasValue || !pass.Value)
                {
                    continue;
                }

                result.AddLast(next);
            }

            return(result);
        }
コード例 #10
0
        public Object EvaluateEnumMethod(
            EventBean[] eventsLambda,
            ICollection <object> target,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            if (target == null || target.Count < 2)
            {
                return(target);
            }

            var evaluateParams = new EvaluateParams(eventsLambda, isNewData, context);
            var set            = new LinkedHashMap <IComparable, Object>();
            var resultEvent    = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var values         = target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var comparable = (IComparable)InnerExpression.Evaluate(evaluateParams);
                if (!set.ContainsKey(comparable))
                {
                    set.Put(comparable, next);
                }
            }
            return(set.Values);
        }
コード例 #11
0
        public override Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            var evalEvent  = new ObjectArrayEventBean(new Object[1], EvalEventType);
            var indexEvent = new ObjectArrayEventBean(new Object[1], IndexEventType);

            if (target.Count == 1)
            {
                Object item = target.First();

                evalEvent.Properties[0]       = item;
                eventsLambda[StreamNumLambda] = evalEvent;

                indexEvent.Properties[0]          = 0;
                eventsLambda[StreamNumLambda + 1] = indexEvent;

                var pass = (bool?)InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.GetValueOrDefault(false))
                {
                    return(Collections.GetEmptyList <object>());
                }
                return(Collections.SingletonList(item));
            }

            var size  = target.Count;
            var all   = new Object[size];
            var count = 0;

            foreach (Object item in target)
            {
                all[count++] = item;
            }

            var result = new LinkedList <Object>();
            int index  = 0;

            for (int i = all.Length - 1; i >= 0; i--)
            {
                evalEvent.Properties[0]       = all[i];
                eventsLambda[StreamNumLambda] = evalEvent;

                indexEvent.Properties[0]          = index++;
                eventsLambda[StreamNumLambda + 1] = indexEvent;

                var pass = (bool?)InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.GetValueOrDefault(false))
                {
                    break;
                }
                result.AddFirst(all[i]);
            }

            return(result);
        }
コード例 #12
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var method = _sumMethodFactory.SumAggregator;

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;
                var value = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                method.Enter(value);
            }

            return(method.Value);
        }
コード例 #13
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var map = new Dictionary <object, object>().WithNullSupport();

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var key   = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                var value = _secondExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                map.Put(key, value);
            }

            return(map);
        }
コード例 #14
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var method      = _sumMethodFactory.SumAggregator;
            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var values      = (ICollection <Object>)target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var value = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                method.Enter(value);
            }

            return(method.Value);
        }
コード例 #15
0
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                Object pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.AsBoolean())
                {
                    continue;
                }

                return(next);
            }

            return(null);
        }
コード例 #16
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            IComparable          minKey      = null;
            Object               result      = null;
            ObjectArrayEventBean resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            ICollection <Object> values      = (ICollection <Object>)target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                Object comparable = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (comparable == null)
                {
                    continue;
                }

                if (minKey == null)
                {
                    minKey = (IComparable)comparable;
                    result = next;
                }
                else
                {
                    if (_max)
                    {
                        if (minKey.CompareTo(comparable) < 0)
                        {
                            minKey = (IComparable)comparable;
                            result = next;
                        }
                    }
                    else
                    {
                        if (minKey.CompareTo(comparable) > 0)
                        {
                            minKey = (IComparable)comparable;
                            result = next;
                        }
                    }
                }
            }

            return(result);  // unpack of EventBean to underlying performed at another stage
        }
コード例 #17
0
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var agg = new AggregatorAvgDecimal(_optionalMathContext);

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var num = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (num == null)
                {
                    continue;
                }
                agg.Enter(num);
            }

            return(agg.Value);
        }
コード例 #18
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var map         = new Dictionary <object, object>();
            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var values      = (ICollection <Object>)target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var key   = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                var value = _secondExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                map.Put(key, value);
            }

            return(map);
        }
コード例 #19
0
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            int count = 0;

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var pass = (bool?)InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.GetValueOrDefault(false))
                {
                    continue;
                }
                count++;
            }

            return(count);
        }
コード例 #20
0
ファイル: EnumEvalMinMaxByEvents.cs プロジェクト: ikvm/nesper
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            IComparable minKey = null;
            EventBean   result = null;

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                Object comparable = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (comparable == null)
                {
                    continue;
                }

                if (minKey == null)
                {
                    minKey = (IComparable)comparable;
                    result = next;
                }
                else
                {
                    if (_max)
                    {
                        if (minKey.CompareTo(comparable) < 0)
                        {
                            minKey = (IComparable)comparable;
                            result = next;
                        }
                    }
                    else
                    {
                        if (minKey.CompareTo(comparable) > 0)
                        {
                            minKey = (IComparable)comparable;
                            result = next;
                        }
                    }
                }
            }

            return(result);  // unpack of EventBean to underlying performed at another stage
        }
コード例 #21
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            IComparable minKey = null;

            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);
            var coll        = (ICollection <Object>)target;

            foreach (Object next in coll)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                Object comparable = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (comparable == null)
                {
                    continue;
                }

                if (minKey == null)
                {
                    minKey = (IComparable)comparable;
                }
                else
                {
                    if (_max)
                    {
                        if (minKey.CompareTo(comparable) < 0)
                        {
                            minKey = (IComparable)comparable;
                        }
                    }
                    else
                    {
                        if (minKey.CompareTo(comparable) > 0)
                        {
                            minKey = (IComparable)comparable;
                        }
                    }
                }
            }

            return(minKey);
        }
コード例 #22
0
ファイル: EnumEvalAnyOfEvents.cs プロジェクト: ikvm/nesper
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(false);
            }

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                Object pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (pass.AsBoolean())
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #23
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var result = new LinkedHashMap <Object, ICollection <object> >();

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var key   = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                var value = result.Get(key);
                if (value == null)
                {
                    value = new List <object>();
                    result.Put(key, value);
                }
                value.Add(next.Underlying);
            }

            return(result);
        }
コード例 #24
0
        public override object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var evalEvent = new ObjectArrayEventBean(new Object[1], Type);

            foreach (var next in target)
            {
                evalEvent.Properties[0]       = next;
                eventsLambda[StreamNumLambda] = evalEvent;

                Object pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.AsBoolean())
                {
                    continue;
                }

                return(next);
            }

            return(null);
        }
コード例 #25
0
ファイル: EnumEvalMinMaxEvents.cs プロジェクト: ikvm/nesper
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            IComparable minKey = null;

            var beans = target;

            foreach (EventBean next in beans)
            {
                eventsLambda[StreamNumLambda] = next;

                Object comparable = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (comparable == null)
                {
                    continue;
                }

                if (minKey == null)
                {
                    minKey = (IComparable)comparable;
                }
                else
                {
                    if (_max)
                    {
                        if (minKey.CompareTo(comparable) < 0)
                        {
                            minKey = (IComparable)comparable;
                        }
                    }
                    else
                    {
                        if (minKey.CompareTo(comparable) > 0)
                        {
                            minKey = (IComparable)comparable;
                        }
                    }
                }
            }

            return(minKey);
        }
コード例 #26
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            var queue = new LinkedList <object>();

            foreach (EventBean next in target)
            {
                eventsLambda[StreamNumLambda] = next;

                var item = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (item != null)
                {
                    queue.AddLast(item);
                }
            }

            return(queue);
        }
コード例 #27
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var agg         = new AggregatorAvgDecimal(_optionalMathContext);
            var resultEvent = new ObjectArrayEventBean(new Object[1], _resultEventType);

            var values = target;

            foreach (Object next in values)
            {
                resultEvent.Properties[0]     = next;
                eventsLambda[StreamNumLambda] = resultEvent;

                var num = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (num == null)
                {
                    continue;
                }
                agg.Enter(num);
            }

            return(agg.Value);
        }
コード例 #28
0
        public Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            var initializationValue = Initialization.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));

            if (target.IsEmpty())
            {
                return(initializationValue);
            }

            var resultEvent = new ObjectArrayEventBean(new Object[1], ResultEventType);

            foreach (EventBean next in target)
            {
                resultEvent.Properties[0]         = initializationValue;
                eventsLambda[StreamNumLambda + 1] = next;
                eventsLambda[StreamNumLambda]     = resultEvent;

                initializationValue = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
            }

            return(initializationValue);
        }
コード例 #29
0
        public object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(target);
            }

            if (target.Count == 1)
            {
                EventBean item = target.OfType <EventBean>().FirstOrDefault();
                eventsLambda[StreamNumLambda] = item;

                Object pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.AsBoolean())
                {
                    return(new EventBean[0]);
                }
                return(new[] { item });
            }

            var all    = target.OfType <EventBean>().ToArray();
            var result = new LinkedList <EventBean>();

            for (int i = all.Length - 1; i >= 0; i--)
            {
                eventsLambda[StreamNumLambda] = all[i];

                Object pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context));
                if (!pass.AsBoolean())
                {
                    break;
                }

                result.AddFirst(all[i]);
            }

            return(result);
        }
コード例 #30
0
ファイル: EnumEvalAnyOfScalar.cs プロジェクト: ikvm/nesper
        public override Object EvaluateEnumMethod(EventBean[] eventsLambda, ICollection <object> target, bool isNewData, ExprEvaluatorContext context)
        {
            if (target.IsEmpty())
            {
                return(false);
            }

            var evalEvent = new ObjectArrayEventBean(new Object[1], Type);

            foreach (Object next in target)
            {
                evalEvent.Properties[0]       = next;
                eventsLambda[StreamNumLambda] = evalEvent;

                var pass = InnerExpression.Evaluate(new EvaluateParams(eventsLambda, isNewData, context)).AsBoolean();
                if (pass)
                {
                    return(true);
                }
            }

            return(false);
        }