Exemple #1
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));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisValueIntermediateResultWithFormula"/> class.
 /// </summary>
 /// <param name="functionFormula">Function formula</param>
 /// <param name="arguments">Arguments</param>
 /// <param name="rowContext">Row context</param>
 /// <param name="valueContext">Value context</param>
 public AnalysisValueIntermediateResultWithFormula(AnalysisFunctionFormula functionFormula, List <object> arguments, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
     : base(functionFormula.FormulaFunction)
 {
     this.Arguments    = arguments;
     this.Formula      = functionFormula;
     this.RowContext   = rowContext;
     this.ValueContext = valueContext;
     this.Complete     = false;
 }
        /// <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);
                }
            }

            string strValue = JavascriptEngine.StringForValue(argument);

            if (!string.IsNullOrEmpty(strValue) && resultCounter.ObjectForKey(strValue) == null)
            {
                resultCounter.SetObjectForKey(strValue, strValue);
                resultCounter.AddValue(1);
            }

            return(new AnalysisValueIntermediateResultDelayed(resultCounter, rowContext));
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisValueIntermediateResultWithFunction"/> class.
 /// </summary>
 /// <param name="function">Function</param>
 /// <param name="argument">Argument</param>
 /// <param name="rowContext">Row context</param>
 /// <param name="valueContext">Value context</param>
 public AnalysisValueIntermediateResultWithFunction(AnalysisFunctionFunc function, AnalysisValueIntermediateResult argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
     : base(null, new System.Collections.Generic.List <object> {
     argument
 }, rowContext, valueContext)
 {
     this.Func = function;
 }
Exemple #5
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));
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisValueIntermediateResultWithRowContext"/> class.
 /// </summary>
 /// <param name="result">Result</param>
 /// <param name="rowContext">Row context</param>
 public AnalysisValueIntermediateResultWithRowContext(double result, AnalysisProcessingQueryResultRowExecutionContext rowContext)
     : base(result)
 {
     this.RowContext = rowContext;
 }
        /// <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));
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnalysisValueIntermediateResultDelayed"/> class.
 /// </summary>
 /// <param name="resultDelegate">Result delegate</param>
 /// <param name="rowContext">Row context</param>
 public AnalysisValueIntermediateResultDelayed(IAnalysisFunctionResultDelegate resultDelegate, AnalysisProcessingQueryResultRowExecutionContext rowContext)
     : base(resultDelegate.Result)
 {
     this.resultDelegate = resultDelegate;
     this.RowContext     = 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));
        }
Exemple #10
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));
            }
        }
Exemple #11
0
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultForQueryRowVariableContext(AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueExecutionContext)
        {
            bool complete          = true;
            var  objectResultArray = new List <object>();
            int  i = 0;

            foreach (AnalysisValueFunction func in this.Arguments)
            {
                AnalysisValueIntermediateResult res = func.ResultForQueryRowVariableContext(rowContext, valueExecutionContext.ChildExecutionContextAtIndex(i++));
                if (!res.Complete)
                {
                    complete = false;
                }

                if (res == null)
                {
                    objectResultArray.Add(new AnalysisValueIntermediateResult(0));
                }
                else
                {
                    objectResultArray.Add(res);
                }
            }

            if (!complete)
            {
                return(new AnalysisValueIntermediateResultWithFormula(this, objectResultArray, rowContext, valueExecutionContext));
            }

            return(this.ObjectResultForArguments(objectResultArray));
        }
 /// <summary>
 /// Result with argument row context value context
 /// </summary>
 /// <param name="argument">Argument</param>
 /// <param name="rowContext">Row context</param>
 /// <param name="valueContext">Value.AnalysisValueFunction context</param>
 /// <returns>Analysis value intermediate result</returns>
 public virtual AnalysisValueIntermediateResult ResultWithArgumentRowContextValueContext(JsValue argument, AnalysisProcessingQueryResultRowExecutionContext rowContext, AnalysisProcessingValueExecutionContext valueContext)
 {
     return(new AnalysisValueIntermediateResult(0));
 }
Exemple #13
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));
        }
 /// <summary>
 /// Result for query row variable context
 /// </summary>
 /// <param name="row">Row</param>
 /// <param name="valueExecutionContext">Value execution context</param>
 /// <returns>Result for query row</returns>
 public virtual AnalysisValueIntermediateResult ResultForQueryRowVariableContext(AnalysisProcessingQueryResultRowExecutionContext row, AnalysisProcessingValueExecutionContext valueExecutionContext) => this.ObjectResultForResultRow(row.Row);
        /// <inheritdoc/>
        public override AnalysisValueIntermediateResult ResultForQueryRowVariableContext(AnalysisProcessingQueryResultRowExecutionContext row, AnalysisProcessingValueExecutionContext valueExecutionContext)
        {
            AnalysisProcessingValueExecutionContext childExecutionContext = valueExecutionContext.ChildExecutionContextAtIndex(0);
            AnalysisValueIntermediateResult         result = this.ArgumentFunction.ResultForQueryRowVariableContext(row, childExecutionContext);

            if (result.Complete)
            {
                return(this.AnalysisFunction.ResultWithArgumentRowContextValueContext(result.JavascriptResult, row, valueExecutionContext));
            }
            else
            {
                return(new AnalysisValueIntermediateResultWithFunction(this, result, row, valueExecutionContext));
            }
        }
 /// <summary>
 /// Result for argument row variable context
 /// </summary>
 /// <param name="result">Result row</param>
 /// <param name="row">Row</param>
 /// <param name="valueExecutionContext">Value.AnalysisValueFunction execution context</param>
 /// <returns>Returns analysis value intermediate result</returns>
 public AnalysisValueIntermediateResult ResultForArgumentRowVariableContext(AnalysisValueIntermediateResult result, AnalysisProcessingQueryResultRowExecutionContext row, AnalysisProcessingValueExecutionContext valueExecutionContext)
 {
     return(this.AnalysisFunction.ResultWithArgumentRowContextValueContext(result.JavascriptResult, row, valueExecutionContext));
 }