/// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            AnalysisResultCounter resultCounter;

            if (!string.IsNullOrEmpty(rowContext.XCategoryKey))
            {
                resultCounter = valueContext.ContextForYCategoryValueXCategoryValue(rowContext.YCategoryKey, rowContext.XCategoryKey) as AnalysisResultCounter;
            }
            else
            {
                resultCounter = valueContext.ContextForYCategoryValue(rowContext.YCategoryKey) as AnalysisResultCounter;
            }

            if (resultCounter == null)
            {
                resultCounter = new AnalysisResultCounter();
                if (!string.IsNullOrEmpty(rowContext.XCategoryKey))
                {
                    valueContext.SetContextForYCategoryValueXCategoryValue(resultCounter, rowContext.YCategoryKey, rowContext.XCategoryKey);
                }
                else
                {
                    valueContext.SetContextForYCategoryValue(resultCounter, rowContext.YCategoryKey);
                }
            }

            resultCounter.AddValue(JavascriptEngine.DoubleForValue(argument));
            return(new AnalysisValueIntermediateResultDelayed(resultCounter, rowContext));
        }
        /// <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));
        }
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
        {
            var resultCounter = valueContext.ContextForYCategoryValue("all") as AnalysisResultCounter;

            if (resultCounter == null)
            {
                resultCounter = new AnalysisResultCounter();
                valueContext.SetContextForYCategoryValue(resultCounter, "all");
            }

            resultCounter.AddValue(JavascriptEngine.DoubleForValue(argument));
            return(new AnalysisValueIntermediateResultDelayed(resultCounter, rowContext));
        }
Beispiel #4
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));
        }