/// <summary>
 /// Initializes a new instance of the <see cref="AnalysisXColumn"/> class.
 /// </summary>
 /// <param name="column">Column</param>
 /// <param name="xCategoryValue">X category value</param>
 public AnalysisXColumn(AnalysisColumn column, AnalysisProcessingXCategoryValue xCategoryValue)
 {
     this.Key      = xCategoryValue.Key;
     this.Label    = xCategoryValue.Label;
     this.Category = xCategoryValue.Category;
     this.Column   = column;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AnalysisResultCell"/> class.
        /// </summary>
        /// <param name="values">Values</param>
        /// <param name="row">Row</param>
        /// <param name="column">Column</param>
        public AnalysisResultCell(List <object> values, AnalysisRow row, AnalysisColumn column)
        {
            Row    = row;
            Column = column;
            var result = 0.0;

            if (column.IsTextColumn || values?.Any() == false)
            {
                Value       = 0;
                StringValue = string.Empty;
            }

            var collection      = values?.OfType <AnalysisProcessingResultColumnValue>();
            var lstAnalysis     = collection?.ToList();
            var aggregationType = column.ResultColumn.AggregationType;

            if (lstAnalysis?.Any() == true)
            {
                result = GetAggregatedResult(aggregationType, lstAnalysis);
            }

            Value       = result;
            StringValue = column.ResultColumn.DisplayStringFromNumber(Value);
            var xCategoryValues = column.XCategoryValues;

            if (xCategoryValues?.Any() == true)
            {
                XResultCells = GetAnalysisXResultCells(lstAnalysis, aggregationType, column);
            }
        }
        /// <summary>
        /// Computes AnalysisXResultCell aggregated results
        /// </summary>
        /// <param name="lstAnalysis">
        /// List of <see cref="AnalysisProcessingResultColumnValue"/>
        /// </param>
        /// <param name="aggregationType">
        /// <see cref="AnalysisAggregationType"/> object
        /// </param>
        /// <param name="column">
        /// <see cref="AnalysisColumn"/> object.
        /// </param>
        /// <returns>
        /// List of <see cref="AnalysisXResultCell"/>
        /// </returns>
        private static List <AnalysisXResultCell> GetAnalysisXResultCells(
            List <AnalysisProcessingResultColumnValue> lstAnalysis,
            AnalysisAggregationType aggregationType,
            AnalysisColumn column)
        {
            var xResultCells    = new List <AnalysisXResultCell>();
            var xCategoryValues = column.XCategoryValues;

            foreach (var xCategoryValue in xCategoryValues)
            {
                var result = 0.0;
                if (aggregationType.Sum)
                {
                    result = lstAnalysis?.Sum(x => x.ResultForXCategoryValueKey(xCategoryValue.Key)) ?? result;
                }
                else if (aggregationType.Min)
                {
                    if (lstAnalysis?.Any() == true)
                    {
                        result = lstAnalysis.Min(x => x.ResultForXCategoryValueKey(xCategoryValue.Key));
                    }
                }
                else if (aggregationType.Max)
                {
                    result = lstAnalysis?.Max(x => x.ResultForXCategoryValueKey(xCategoryValue.Key)) ?? result;
                }
                else
                {
                    var count        = 0;
                    var currentCount = 0;
                    if (lstAnalysis?.Any() == true)
                    {
                        foreach (var colVal in lstAnalysis)
                        {
                            currentCount = colVal.CountForXCategoryValueKey(xCategoryValue.Key);
                            if (currentCount > 0)
                            {
                                result += colVal.ResultForXCategoryValueKey(xCategoryValue.Key) * currentCount;
                                count  += currentCount;
                            }
                        }
                    }

                    result = count > 0
                        ? result / count
                        : 0;
                }

                xResultCells.Add(new AnalysisXResultCell(result, column.ResultColumn.DisplayStringFromNumber(result)));
            }

            return(xResultCells);
        }
 /// <summary>
 /// Adds column
 /// </summary>
 /// <param name="column">Column</param>
 public void AddColumn(AnalysisColumn column)
 {
     if (this.columns == null)
     {
         this.columns = new List <object> {
             column
         };
     }
     else
     {
         this.columns.Add(column);
     }
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="AnalysisResultCell"/> class.
        /// </summary>
        /// <param name="value">Value.AnalysisValueFunction</param>
        /// <param name="row">Row</param>
        /// <param name="column">Column</param>
        public AnalysisResultCell(AnalysisProcessingResultColumnValue value, AnalysisRow row, AnalysisColumn column)
        {
            this.Row    = row;
            this.Column = column;
            if (this.Column.ResultColumn.ValueOptions?.IsText ?? false)
            {
                this.StringValue = value.TextResult;
                this.RawValue    = this.StringValue;
                this.Value       = 0;
                var xCategoryValues = column.XCategoryValues;
                if (xCategoryValues.Count > 0)
                {
                    var xResultCells = new List <AnalysisXResultCell>();
                    foreach (AnalysisXColumn xCategoryValue in xCategoryValues)
                    {
                        xResultCells.Add(new AnalysisXResultCell(value.TextResultForXCategoryValueKey(xCategoryValue.Key)));
                    }

                    this.XResultCells = xResultCells;
                }
            }
            else
            {
                this.Value       = value.Result;
                this.StringValue = column.ResultColumn.DisplayStringFromNumber(this.Value);
                this.RawValue    = this.Value.ToString();
                var xCategoryValues = column.XCategoryValues;
                if (xCategoryValues?.Count > 0)
                {
                    var xResultCells = new List <AnalysisXResultCell>();
                    foreach (AnalysisXColumn xCategoryValue in xCategoryValues)
                    {
                        var num = value.ResultForXCategoryValueKey(xCategoryValue.Key);
                        xResultCells.Add(new AnalysisXResultCell(num, column.ResultColumn.DisplayStringFromNumber(num)));
                    }

                    this.XResultCells = xResultCells;
                }
            }
        }