/// <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) { 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)); }