/// <summary>
        /// Generates the the attribute.
        /// </summary>
        /// <param name="domainType">Type of the domain.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="countOfCategories">The count of categories.</param>
        /// <param name="columnInfo">The column info.</param>
        /// <param name="boxIdentity">The box identity.</param>
        /// <returns>Generated attribute.</returns>
        public static GeneratedAttribute Generate(
			AttributeDomainEnum domainType,
			double from,
			double to,
			long countOfCategories,
			Ferda.Modules.Boxes.DataMiningCommon.Column.ColumnInfo columnInfo,
			string boxIdentity)
        {
            Ferda.Modules.Helpers.Data.Column.ValueType simpleColumnType = Ferda.Modules.Helpers.Data.Column.GetColumnValueTypeByValueSubType(columnInfo.columnSubType);
            if (simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Integral
                && simpleColumnType != Ferda.Modules.Helpers.Data.Column.ValueType.Floating)
                throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);

            //dataArray.Add(new Data(currentValue, currentCount));
            ArrayList dataArray = new ArrayList();
            DataTable frequencies = null;
            float startValue = Convert.ToSingle(columnInfo.statistics.ValueMin);
            float endValue = Convert.ToSingle(columnInfo.statistics.ValueMax);
            switch (domainType)
            {
                case AttributeDomainEnum.WholeDomain:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        boxIdentity);
                    from = to = 0;
                    break;
                case AttributeDomainEnum.SubDomainValueBounds:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        columnInfo.columnSelectExpression + ">=" + from + " AND " + columnInfo.columnSelectExpression + "<=" + to,
                        boxIdentity);
                    startValue = (float)from;
                    endValue = (float)to;
                    from = to = 0;
                    break;
                case AttributeDomainEnum.SubDomainNumberOfValuesBounds:
                    frequencies = Ferda.Modules.Helpers.Data.Column.GetDistinctsAndFrequencies(
                        columnInfo.dataMatrix.database.odbcConnectionString,
                        columnInfo.dataMatrix.dataMatrixName,
                        columnInfo.columnSelectExpression,
                        boxIdentity);
                    break;
                default:
                    throw Ferda.Modules.Exceptions.SwitchCaseNotImplementedError(domainType);
            }

            if (from < 0)
            {
                throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "From" }, restrictionTypeEnum.Minimum);
            }
            if (to < 0)
            {
                throw Ferda.Modules.Exceptions.BadValueError(null, boxIdentity, null, new string[] { "To" }, restrictionTypeEnum.Minimum);
            }
            int fromUi = (int)from;
            int toUi = (int)to;
            int frequenciesCount = frequencies.Rows.Count;
            if (frequenciesCount <= from + to)
                return new GeneratedAttribute();
            object item;

            switch (simpleColumnType)
            {
                case Ferda.Modules.Helpers.Data.Column.ValueType.Floating:
                    for (int i = fromUi; i < (frequenciesCount - toUi); i++)
                    {
                        item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts];
                        if (item == System.DBNull.Value)
                            continue;
                        dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToSingle(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency])));
                    }
                    break;
                case Ferda.Modules.Helpers.Data.Column.ValueType.Integral:
                    for (int i = fromUi; i < (frequenciesCount - toUi); i++)
                    {
                        item = frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectDistincts];
                        if (item == System.DBNull.Value)
                            continue;
                        dataArray.Add(new EquifrequencyIntervalGenerator.Data(Convert.ToInt64(item), Convert.ToInt32(frequencies.Rows[i][Ferda.Modules.Helpers.Data.Column.SelectFrequency])));
                    }
                    break;
                default:
                    throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);
            }
            object[] splitPoints = null;
            try
            {
                splitPoints = EquifrequencyIntervalGenerator.GenerateIntervals((int)countOfCategories, dataArray);
            }
            catch (ArgumentOutOfRangeException ex)
            {
                if (ex.ParamName == "intervals")
                {
                    throw Ferda.Modules.Exceptions.BadValueError(ex, boxIdentity, null, new string[] { "CountOfCategories" }, restrictionTypeEnum.Other);
                }
                else
                    throw ex;
            }
            if (splitPoints == null)
                return new GeneratedAttribute();

            CategoriesStruct categoriesStruct = new CategoriesStruct();

            string categoryName;
            List<SelectString> categoriesNames = new List<SelectString>();
            SelectString categoriesNamesItem;
            bool computeCategoriesNames = (splitPoints.Length + 1 < Ferda.Modules.Boxes.DataMiningCommon.Attributes.AbstractAttributeConstants.MaxLengthOfCategoriesNamesSelectStringArray);
            switch (simpleColumnType)
            {
                case Ferda.Modules.Helpers.Data.Column.ValueType.Floating:
                    categoriesStruct.floatIntervals = new FloatIntervalCategorySeq();
                    float beginValueFl = startValue;
                    float nextValueFl;
                    FloatIntervalStruct intervalFlTemplate = new FloatIntervalStruct();
                    intervalFlTemplate.leftBoundType = BoundaryEnum.Sharp;
                    intervalFlTemplate.rightBoundType = BoundaryEnum.Round;
                    FloatIntervalStruct intervalFl;
                    for (int i = 0; i < splitPoints.Length + 1; i++)
                    {
                        if (i == splitPoints.Length)
                        {
                            nextValueFl = endValue;
                            intervalFlTemplate.rightBoundType = BoundaryEnum.Sharp;
                        }
                        else
                            nextValueFl = (float)splitPoints[i];
                        intervalFl = intervalFlTemplate;
                        intervalFl.leftBound = beginValueFl;
                        intervalFl.rightBound = nextValueFl;
                        categoryName = Constants.LeftClosedInterval + beginValueFl.ToString() + Constants.SeparatorInterval + nextValueFl.ToString();
                        categoryName += (intervalFl.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval;

                        if (computeCategoriesNames)
                        {
                            categoriesNamesItem = new SelectString();
                            categoriesNamesItem.name = categoryName;
                            categoriesNamesItem.label = categoryName;
                            categoriesNames.Add(categoriesNamesItem);
                        }

                        categoriesStruct.floatIntervals.Add(
                            categoryName,
                            new FloatIntervalStruct[] { intervalFl });
                        beginValueFl = nextValueFl;
                    }

                    return new GeneratedAttribute(
                        categoriesStruct,
                        null,
                        categoriesStruct.floatIntervals.Count,
                        categoriesNames.ToArray());
                case Ferda.Modules.Helpers.Data.Column.ValueType.Integral:
                    categoriesStruct.longIntervals = new LongIntervalCategorySeq();
                    long beginValueLn = (long)startValue;
                    long nextValueLn;
                    LongIntervalStruct intervalLnTemplate = new LongIntervalStruct();
                    intervalLnTemplate.leftBoundType = BoundaryEnum.Sharp;
                    intervalLnTemplate.rightBoundType = BoundaryEnum.Round;
                    LongIntervalStruct intervalLn;
                    for (int i = 0; i < splitPoints.Length + 1; i++)
                    {
                        if (i == splitPoints.Length)
                        {
                            nextValueLn = (long)endValue;
                            intervalLnTemplate.rightBoundType = BoundaryEnum.Sharp;
                        }
                        else
                            nextValueLn = (long)splitPoints[i];
                        intervalLn = intervalLnTemplate;
                        intervalLn.leftBound = beginValueLn;
                        intervalLn.rightBound = nextValueLn;
                        categoryName = Constants.LeftClosedInterval + beginValueLn.ToString() + Constants.SeparatorInterval + nextValueLn.ToString();
                        categoryName += (intervalLn.rightBoundType == BoundaryEnum.Sharp)? Constants.RightClosedInterval : Constants.RightOpenedInterval;

                        if (computeCategoriesNames)
                        {
                            categoriesNamesItem = new SelectString();
                            categoriesNamesItem.name = categoryName;
                            categoriesNamesItem.label = categoryName;
                            categoriesNames.Add(categoriesNamesItem);
                        }

                        categoriesStruct.longIntervals.Add(
                            categoryName,
                            new LongIntervalStruct[] { intervalLn });
                        beginValueLn = nextValueLn;
                    }

                    return new GeneratedAttribute(
                        categoriesStruct,
                        null,
                        categoriesStruct.longIntervals.Count,
                        categoriesNames.ToArray());
                default:
                    throw Ferda.Modules.Exceptions.BadParamsError(null, boxIdentity, simpleColumnType.ToString(), restrictionTypeEnum.DbColumnDataType);
            }
        }
        private void insertValueInterval(int categoryID, FloatIntervalStruct intervalStruct)
        {
            int leftCategoryValueID;
            int rightCategoryValueID;
            BoundaryEnum leftBracketType;
            BoundaryEnum rightBracketType;

            if (intervalStruct.leftBoundType == BoundaryEnum.Infinity)
            {
                leftCategoryValueID = SetValue(InfinityTypeEnum.MinusInfinity);
                leftBracketType = BoundaryEnum.Round;
            }
            else
            {
                leftCategoryValueID = SetValue(intervalStruct.leftBound);
                leftBracketType = intervalStruct.leftBoundType;
            }
            if (intervalStruct.rightBoundType == BoundaryEnum.Infinity)
            {
                rightCategoryValueID = SetValue(intervalStruct.leftBound);
                rightBracketType = BoundaryEnum.Round;
            }
            else
            {
                rightCategoryValueID = SetValue(intervalStruct.rightBound);
                rightBracketType = intervalStruct.rightBoundType;
            }
            this.SetCategoryInterval(
                categoryID,
                leftCategoryValueID,
                rightCategoryValueID,
                leftBracketType,
                rightBracketType);
        }
 /// <summary>
 /// Method to convert SmartDataList to CategoriesStruct structure.
 /// </summary>
 /// <param name="dataList"></param>
 /// <returns></returns>
 private CategoriesStruct MyIceRunOut(FerdaSmartDataList dataList)
 {
     CategoriesStruct myCategoriesStruct = new CategoriesStruct();
     myCategoriesStruct.dateTimeIntervals = new DateTimeIntervalCategorySeq();
     myCategoriesStruct.enums = new EnumCategorySeq();
     myCategoriesStruct.floatIntervals = new FloatIntervalCategorySeq();
     myCategoriesStruct.longIntervals = new LongIntervalCategorySeq();
     ArrayList tempArray = new ArrayList();
     foreach (Category multiSet in dataList.Categories)
     {
         switch (multiSet.CatType)
         {
             case CategoryType.Interval:
                 foreach (Interval interval in multiSet.GetIntervals())
                 {
                     if (interval.intervalType == IntervalType.Long)
                     {
                         LongIntervalStruct newLong = new LongIntervalStruct();
                         newLong.leftBound = interval.lowerBound;
                         newLong.rightBound = interval.upperBound;
                         if (interval.lowerBoundType == IntervalBoundType.Round)
                         {
                             newLong.leftBoundType = BoundaryEnum.Round;
                         }
                         else
                         {
                             if (interval.lowerBoundType == IntervalBoundType.Sharp)
                             {
                                 newLong.leftBoundType = BoundaryEnum.Sharp;
                             }
                             else
                             {
                                 newLong.leftBoundType = BoundaryEnum.Infinity;
                             }
                         }
                         if (interval.upperBoundType == IntervalBoundType.Round)
                         {
                             newLong.rightBoundType = BoundaryEnum.Round;
                         }
                         else
                         {
                             if (interval.upperBoundType == IntervalBoundType.Sharp)
                             {
                                 newLong.rightBoundType = BoundaryEnum.Sharp;
                             }
                             else
                             {
                                 newLong.rightBoundType = BoundaryEnum.Infinity;
                             }
                         }
                         tempArray.Add(newLong);
                     }
                     else
                     {
                         if (interval.intervalType == IntervalType.Float)
                         {
                             FloatIntervalStruct newFloat = new FloatIntervalStruct();
                             newFloat.leftBound = interval.lowerBoundFl;
                             newFloat.rightBound = interval.upperBoundFl;
                             if (interval.lowerBoundType == IntervalBoundType.Round)
                             {
                                 newFloat.leftBoundType = BoundaryEnum.Round;
                             }
                             else
                             {
                                 if (interval.lowerBoundType == IntervalBoundType.Sharp)
                                 {
                                     newFloat.leftBoundType = BoundaryEnum.Sharp;
                                 }
                                 else
                                 {
                                     newFloat.leftBoundType = BoundaryEnum.Infinity;
                                 }
                             }
                             if (interval.upperBoundType == IntervalBoundType.Round)
                             {
                                 newFloat.rightBoundType = BoundaryEnum.Round;
                             }
                             else
                             {
                                 if (interval.upperBoundType == IntervalBoundType.Sharp)
                                 {
                                     newFloat.rightBoundType = BoundaryEnum.Sharp;
                                 }
                                 else
                                 {
                                     newFloat.rightBoundType = BoundaryEnum.Infinity;
                                 }
                             }
                             tempArray.Add(newFloat);
                         }
                     }
                 }
                 if (multiSet.GetIntervalType() == IntervalType.Long)
                 {
                     myCategoriesStruct.longIntervals.Add(multiSet.Name, (LongIntervalStruct[])tempArray.ToArray(typeof(LongIntervalStruct)));
                     tempArray.Clear();
                 }
                 else
                 {
                     if (multiSet.GetIntervalType() == IntervalType.Float)
                     {
                         myCategoriesStruct.floatIntervals.Add(multiSet.Name, (FloatIntervalStruct[])tempArray.ToArray(typeof(FloatIntervalStruct)));
                         tempArray.Clear();
                     }
                 }
                 break;
             case CategoryType.Enumeration:
                 tempArray = multiSet.Set.Values;
                 String[] tempString = new String[tempArray.Count];
                 for (int i = 0; i < tempArray.Count; i++)
                 {
                     tempString[i] = tempArray[i].ToString();
                 }
                 try
                 {
                     myCategoriesStruct.enums.Add(multiSet.Name, tempString);
                 }
                 catch (System.ArgumentException)
                 {
                     throw (new System.ApplicationException());
                 }
                 tempArray.Clear();
                 break;
             default:
                 break;
         }
     }
     return myCategoriesStruct;
 }
 public FloatCategory(string name, FloatIntervalStruct[] value)
 {
     Name = name;
     Value = value;
 }
        /// <summary>
        /// Method which composes WHERE clause for a category of the FloatInterval type.
        /// </summary>
        /// <param name="floatInterval">Category of float interval type</param>
        /// <param name="columnSelectExpression">Column select expression</param>
        /// <returns>WHERE clause</returns>
        private String GetWhereClauseFloat(FloatIntervalStruct[] floatIntervalSeq, String columnSelectExpression)
        {
            StringBuilder returnString = new StringBuilder();
            bool first = true;
            //replacing comma with dot
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("[,]");
            foreach (FloatIntervalStruct floatInterval in floatIntervalSeq)
            {
                if (first)
                {
                    first = false;
                    returnString.Append("(");
                }
                else
                {
                    returnString.Append(" OR(");
                }

                //if both bounds are infinity, no restriction is needed
                if ((floatInterval.leftBoundType == BoundaryEnum.Infinity) && (floatInterval.rightBoundType == BoundaryEnum.Infinity))
                    return "";

                returnString.Append(columnSelectExpression);
                bool left = false;

                if (floatInterval.leftBoundType == BoundaryEnum.Round)
                {
                    returnString.Append(" > " + r.Replace(floatInterval.leftBound.ToString(), "."));
                    left = true;
                }
                else
                {
                    if (floatInterval.leftBoundType == BoundaryEnum.Sharp)
                    {
                        returnString.Append(" >= " + r.Replace(floatInterval.leftBound.ToString(), "."));
                        left = true;
                    }
                    //Infinity is left, no restriction needed
                }
                if (floatInterval.rightBoundType == BoundaryEnum.Round)
                {
                    if (left)
                    {
                        returnString.Append(" AND " + columnSelectExpression);
                    }

                    returnString.Append(" < " + r.Replace(floatInterval.rightBound.ToString(), "."));
                }
                else
                {
                    if (floatInterval.rightBoundType == BoundaryEnum.Sharp)
                    {
                        if (left)
                        {
                            returnString.Append(" AND " + columnSelectExpression);
                        }
                        returnString.Append(" <= " + floatInterval.rightBound);
                    }
                    //Infinity is left, no restriction needed
                }
                returnString.Append(")");
            }
            return returnString.ToString();
        }
 private static GeneratedAttribute generateFloating(float from, float to, SidesEnum closedFrom, float length, ColumnInfo column)
 {
     FloatIntervalStruct intervalTemplate = new FloatIntervalStruct();
     char leftBound, rightBound;
     switch (closedFrom)
     {
         case SidesEnum.Left:
             intervalTemplate.leftBoundType = BoundaryEnum.Sharp;
             intervalTemplate.rightBoundType = BoundaryEnum.Round;
             leftBound = Constants.LeftClosedInterval;
             rightBound = Constants.RightOpenedInterval;
             break;
         case SidesEnum.Right:
             intervalTemplate.leftBoundType = BoundaryEnum.Round;
             intervalTemplate.rightBoundType = BoundaryEnum.Sharp;
             leftBound = Constants.LeftOpenedInterval;
             rightBound = Constants.RightClosedInterval;
             break;
         default:
             throw Ferda.Modules.Exceptions.SwitchCaseNotImplementedError(closedFrom);
     }
     CategoriesStruct result = new CategoriesStruct();
     result.floatIntervals = new FloatIntervalCategorySeq();
     float fromTmp = from;
     float toTmp = ((fromTmp + length) > to) ? to : fromTmp + length;
     for (; ; )
     {
         FloatIntervalStruct interval = intervalTemplate;
         interval.leftBound = fromTmp;
         interval.rightBound = toTmp;
         result.floatIntervals.Add(
             leftBound + fromTmp.ToString() + Constants.SeparatorInterval + toTmp.ToString() + rightBound,
             new FloatIntervalStruct[] { interval });
         if (toTmp == to)
             break;
         fromTmp = toTmp;
         toTmp = ((toTmp + length) > to) ? to : toTmp + length;
     }
     return new GeneratedAttribute(
         result,
         null,
         result.floatIntervals.Count);
 }