Пример #1
0
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            JavascriptEngine engine       = JavascriptEngine.Current;
            double           maximumValue = 0;
            bool             first        = true;
            var arr = JavascriptEngine.ArrayForValue(argument);

            if (arr == null)
            {
                return(new AnalysisValueIntermediateResult(0));
            }

            foreach (JsValue v in arr)
            {
                double curVal = JavascriptEngine.DoubleForObject(v);
                if (first)
                {
                    maximumValue = curVal;
                    first        = false;
                }
                else if (curVal > maximumValue)
                {
                    maximumValue = curVal;
                }
            }

            return(new AnalysisValueIntermediateResult(maximumValue));
        }
Пример #2
0
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            JavascriptEngine engine = JavascriptEngine.Current;
            var arr = JavascriptEngine.ArrayForValue(argument);

            if (arr == null || arr.Count < 3)
            {
                return(new AnalysisValueIntermediateResult(0));
            }

            double curVal = JavascriptEngine.DoubleForObject(arr[0]);
            double minVal = JavascriptEngine.DoubleForObject(arr[1]);
            double maxVal = JavascriptEngine.DoubleForObject(arr[2]);

            if (minVal <= curVal && curVal <= maxVal)
            {
                if (arr.Count > 3)
                {
                    return(new AnalysisValueIntermediateResult(JavascriptEngine.DoubleForObject(arr[3])));
                }
                else
                {
                    return(new AnalysisValueIntermediateResult(1));
                }
            }
            else if (arr.Count > 4)
            {
                return(new AnalysisValueIntermediateResult(JavascriptEngine.DoubleForObject(arr[4])));
            }
            else
            {
                return(new AnalysisValueIntermediateResult(0));
            }
        }
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            double           argumentValue;
            double           weight        = 0;
            bool             defaultWeight = true;
            JavascriptEngine engine        = JavascriptEngine.Current;

            if (JavascriptEngine.IsObject(argument))
            {
                var arr = JavascriptEngine.ArrayForValue(argument);
                if (arr.Count > 0)
                {
                    object argobj = arr[0];
                    argumentValue = argobj.ToDouble();
                }
                else
                {
                    argumentValue = 0;
                }

                if (arr.Count > 1)
                {
                    object argobj = arr[1];
                    weight        = argobj.ToDouble();
                    defaultWeight = false;
                }
            }
            else
            {
                argumentValue = JavascriptEngine.DoubleForValue(argument);
            }

            if (defaultWeight)
            {
                if (rowContext.ProcessingContext.Analysis.WeightField != null)
                {
                    string weightStringValue = rowContext.Row.RawValueAtIndex(rowContext.ProcessingContext.Analysis.WeightField.QueryResultFieldIndex);
                    if (weightStringValue?.Length > 0)
                    {
                        weight = weightStringValue.ToDouble();
                    }
                    else
                    {
                        weight = 1;
                    }
                }
                else
                {
                    weight = 1;
                }
            }

            return(new AnalysisValueIntermediateResult(argumentValue * weight));
        }
Пример #4
0
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            double           val;
            string           key;
            object           valueObject;
            JavascriptEngine engine = JavascriptEngine.Current;
            var arr = JavascriptEngine.ArrayForValue(argument);

            if (arr == null)
            {
                val = JavascriptEngine.DoubleForObject(argument);
                key = null;
            }
            else
            {
                if (arr.Count > 1)
                {
                    valueObject = arr[1];
                    if (valueObject is string)
                    {
                        key = (string)valueObject;
                    }
                    else
                    {
                        key = $"{valueObject}";
                    }

                    valueObject = arr[0];
                }
                else if (arr.Count == 1)
                {
                    valueObject = arr[0];
                    key         = "const";
                }
                else
                {
                    return(new AnalysisValueIntermediateResult(0));
                }

                if (valueObject is int || valueObject is string)
                {
                    val = valueObject.ToDouble();
                }
                else
                {
                    val = 0;
                }
            }

            var resultCounter = valueContext.ContextForYCategoryValue(rowContext.YCategoryKey) as AnalysisResultCounter;

            if (resultCounter == null)
            {
                resultCounter = new AnalysisResultCounter();
                valueContext.SetContextForYCategoryValue(resultCounter, rowContext.YCategoryKey);
            }

            if (key == null)
            {
                resultCounter.AddValue(val);
            }
            else
            {
                var num = resultCounter.ObjectForKey(key);
                if (num == null)
                {
                    resultCounter.AddValue(val);
                    resultCounter.SetObjectForKey(1, key);
                }
                else
                {
                    resultCounter.SetObjectForKey(num.ToInt() + 1, key);
                }
            }

            return(new AnalysisValueIntermediateResultDelayed(resultCounter, rowContext));
        }
Пример #5
0
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            double           argumentValue        = 0;
            int              currencyCode         = 0;
            bool             defaultCurrencyField = true;
            JavascriptEngine engine = JavascriptEngine.Current;

            if (JavascriptEngine.IsObject(argument))
            {
                var arr = JavascriptEngine.ArrayForValue(argument);
                if (arr.Count > 0)
                {
                    object argobj = arr[0];
                    argumentValue = argobj.ToDouble();
                }
                else
                {
                    argumentValue = 0;
                }

                if (arr.Count > 1)
                {
                    object argobj = arr[1];
                    currencyCode         = argobj.ToInt();
                    defaultCurrencyField = false;
                }
            }
            else
            {
                argumentValue = JavascriptEngine.DoubleForValue(argument);
            }

            if (defaultCurrencyField)
            {
                if (rowContext.ProcessingContext.Analysis.CurrencyField != null)
                {
                    var currencyStringValue = rowContext.Row.RawValueAtIndex(rowContext.ProcessingContext.Analysis.CurrencyField.QueryResultFieldIndex);
                    if (currencyStringValue?.Length > 0)
                    {
                        currencyCode = currencyStringValue.ToInt();
                    }
                    else
                    {
                        currencyCode = 0;
                    }
                }
                else
                {
                    currencyCode = 0;
                }
            }

            int targetCode = rowContext.ProcessingContext.Analysis.CurrentSettings.CurrencyCode;

            if (currencyCode == 0 || targetCode == 0 || currencyCode == targetCode)
            {
                return(new AnalysisValueIntermediateResult(argumentValue));
            }

            var exchangeRate = rowContext.ProcessingContext.Analysis.CurrencyConversion.ExchangeRateFromCodeToCode(currencyCode, targetCode);

            if (exchangeRate != 0)
            {
                argumentValue /= exchangeRate;
            }

            return(new AnalysisValueIntermediateResult(argumentValue));
        }