Exemplo n.º 1
0
        /// <summary>
        /// Pivots the DataTable based on provided RowField, DataField, Aggregate Function and ColumnFields.//
        /// </summary>
        /// <param name="rowField">The column name of the Source Table which you want to spread into rows</param>
        /// <param name="dataField">The column name of the Source Table which you want to spread into Data Part</param>
        /// <param name="aggregate">The Aggregate function which you want to apply in case matching data found more than once</param>
        /// <param name="columnFields">The List of column names which you want to spread as columns</param>
        /// <returns>A DataTable containing the Pivoted Data</returns>
        public DataTable PivotData(string rowField, string dataField, AggregateFunction aggregate,
                                   params string[] columnFields)
        {
            DataTable dt = new DataTable();
            string Separator = ".";
            List<string> rowList = _Source.Select(x => x[rowField].ToString()).Distinct().ToList();
            // Gets the list of columns .(dot) separated.
            var colList =
                _Source.Select(
                    x => (columnFields.Select(n => x[n]).Aggregate((a, b) => a += Separator + b.ToString())).ToString())
                       .Distinct()
                       .OrderBy(m => m);

            dt.Columns.Add(rowField);
            foreach (var colName in colList)
                dt.Columns.Add(colName); // Cretes the result columns.//

            foreach (string rowName in rowList)
            {
                DataRow row = dt.NewRow();
                row[rowField] = rowName;
                foreach (string colName in colList)
                {
                    string strFilter = rowField + " = '" + rowName + "'";
                    string[] strColValues = colName.Split(Separator.ToCharArray(), StringSplitOptions.None);
                    for (int i = 0; i < columnFields.Length; i++)
                        strFilter += " and " + columnFields[i] + " = '" + strColValues[i] + "'";
                    row[colName] = GetData(strFilter, dataField, aggregate);
                }
                dt.Rows.Add(row);
            }
            return dt;
        }
Exemplo n.º 2
0
    /// <summary>
    /// Pivots the DataTable based on provided RowField, DataField, Aggregate Function and ColumnFields.//
    /// </summary>
    /// <param name="RowField">The column name of the Source Table which you want to spread into rows</param>
    /// <param name="DataField">The column name of the Source Table which you want to spread into Data Part</param>
    /// <param name="Aggregate">The Aggregate function which you want to apply in case matching data found more than once</param>
    /// <param name="ColumnFields">The List of column names which you want to spread as columns</param>
    /// <returns>A DataTable containing the Pivoted Data</returns>
    public DataTable PivotData(string RowField, string DataField, AggregateFunction Aggregate, params string[] ColumnFields)
    {
        DataTable dt = new DataTable();
        string Separator = ".";
        var RowList = (from x in _SourceTable.AsEnumerable() select new { Name = x.Field<object>(RowField) }).Distinct();
        // Gets the list of columns .(dot) separated.
        var ColList = (from x in _SourceTable.AsEnumerable()
                       select new { Name = ColumnFields.Select(n => x.Field<object>(n))
                           .Aggregate((a, b) => a += Separator + b.ToString()) })
                           .Distinct()
                           .OrderBy(m => m.Name);

        dt.Columns.Add(RowField);
        foreach (var col in ColList)
        {
            dt.Columns.Add(col.Name.ToString());  // Cretes the result columns.//
        }

        foreach (var RowName in RowList)
        {
            DataRow row = dt.NewRow();
            row[RowField] = RowName.Name.ToString();
            foreach (var col in ColList)
            {
                string strFilter = RowField + " = '" + RowName.Name + "'";
                string[] strColValues = col.Name.ToString().Split(Separator.ToCharArray(), StringSplitOptions.None);
                for (int i = 0; i < ColumnFields.Length; i++)
                    strFilter += " and " + ColumnFields[i] + " = '" + strColValues[i] + "'";
                row[col.Name.ToString()] = GetData(strFilter, DataField, Aggregate);
            }
            dt.Rows.Add(row);
        }
        return dt;
    }
Exemplo n.º 3
0
 private string convertFunctionToString(AggregateFunction aggregate)
 {
     string result = "";
     switch (aggregate) {
     case AggregateFunction.COUNT: {
         result = "COUNT";
         break;
     }
     case AggregateFunction.AVERAGE: {
         result = "AVG";
         break;
     }
     case AggregateFunction.MAX: {
         result = "MAX";
         break;
     }
     case AggregateFunction.MIN: {
         result = "MIN";
         break;
     }
     case AggregateFunction.SUM: {
         result = "SUM";
         break;
     }
     }
     return result;
 }
Exemplo n.º 4
0
        public AggregateToken(AggregateFunction function, QueryToken parent)
            : base(parent)
        {
            if (function == AggregateFunction.Count)
                throw new ArgumentException("function should not different than Count for this overload");

            if (parent == null)
                throw new ArgumentNullException("parent");

            this.AggregateFunction = function;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AggregateResult"/> class.
        /// </summary>
        /// <param name="value">The value of the result.</param>
        /// <param name="count">The number of arguments used for the calculation of the result.</param>
        /// <param name="function">Function that generated the result.</param>
        /// <exception cref="ArgumentNullException"><c>function</c> is null.</exception>
        public AggregateResult(object value, int count, AggregateFunction function)
        {
            if (function == null)
            {
                throw new ArgumentNullException("function");
            }

            aggregateValue = value;
            itemCount = count;
            this.function = function;
        }
Exemplo n.º 6
0
        public AggregateToken(AggregateFunction function, object queryName)
            : base(null)
        {
            if (function != AggregateFunction.Count)
                throw new ArgumentException("function should be Count for this overload");

            if (queryName == null)
                throw new ArgumentNullException("queryName");

            this.queryName = queryName;
            this.AggregateFunction = function;
        }
Exemplo n.º 7
0
    public DataTable CreateSpec(string[] DataFields, AggregateFunction[] Aggregate, string[] RowFields, string[] ColumnFields, double NSigma = 3)
    {
        DataTable dt = new DataTable();
        try
        {
            var RowList = _SourceTable.DefaultView.ToTable(true, RowFields.Concat(ColumnFields).ToArray()).AsEnumerable().ToList();
            for (int index = RowFields.Count() - 1; index >= 0; index--)
                RowList = RowList.OrderBy(x => x.Field<object>(RowFields[index])).ToList();

            //dt.Columns.Add(RowFields);
            foreach (string s in RowFields)
                dt.Columns.Add(s);

            dt.Columns.Add("null"); //Extra column to seperate the input and output

            Hashtable FunHash = new Hashtable();
            foreach (var fun in Aggregate)
                FunHash[fun] = "_" + fun.ToString();
            FunHash[AggregateFunction.Average] = "_Typical";

            foreach (string Data in DataFields)
            {
                foreach (var fun in Aggregate)
                    if (!fun.ToString().Contains("Spec")) dt.Columns.Add(Data + FunHash[fun].ToString());  // Cretes the result columns.//
                dt.Columns.Add(Data + "_Delta"); //Correction factor
            }

            foreach (var RowName in RowList)
            {
                DataRow row = dt.NewRow();
                string strFilter = string.Empty;
                string strSpecFilter = string.Empty;

                foreach (string Field in RowFields)
                {
                    row[Field] = RowName[Field];
                    strFilter += " and " + Field + " = '" + RowName[Field].ToString() + "'";
                }
                strFilter = strFilter.Substring(5);

                foreach (var fun in Aggregate)
                {
                    string filter = strFilter;
                    foreach (string Data in DataFields)
                        if (!fun.ToString().Contains("Spec")) row[Data + FunHash[fun].ToString()] = GetData(new string[] { filter }, Data, fun);
                }
                dt.Rows.Add(row);
            }
        }
        catch (Exception ex) { errormsg = errormsg + "," + ex.Message; }
        return dt;
    }
Exemplo n.º 8
0
        public bool Delete(AggregateFunction entity)
        {
            Contract.Requires(entity != null);
            Contract.Requires(entity.Id >= 0);

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<AggregateFunction> repo = uow.GetRepository<AggregateFunction>();

                entity = repo.Reload(entity);
                //relation to DataContainer is managed by the other end
                repo.Delete(entity);
                uow.Commit();
            }
            // if any problem was detected during the commit, an exception will be thrown!
            return (true);
        }
Exemplo n.º 9
0
        public AggregateFunction Create(string name, string description)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(name));
            Contract.Ensures(Contract.Result<AggregateFunction>() != null && Contract.Result<AggregateFunction>().Id >= 0);

            AggregateFunction u = new AggregateFunction()
            {
                Name = name,
                Description = description,
            };

            using (IUnitOfWork uow = this.GetUnitOfWork())
            {
                IRepository<AggregateFunction> repo = uow.GetRepository<AggregateFunction>();
                repo.Put(u);
                uow.Commit();
            }
            return (u);
        }
        /// <summary>
        /// Renders aggregate function as SQL element.
        /// </summary>
        /// <param name="aggregateFunction">Aggregate function.</param>
        /// <param name="dbms">Target DBMS.</param>
        /// <param name="output">StringBuilder to which SQL is appended.</param>
        /// <param name="allParameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        public void Render(AggregateFunction aggregateFunction, DbmsType dbms, StringBuilder output, DbParameterCollection allParameters)
        {
            output.Append(aggregateFunction.Name);
            output.Append("(");
            if (aggregateFunction.Distinct)
                output.Append("DISTINCT ");

            if (aggregateFunction.FunctionArguments.Count > 0)
            {
                for (int paramIdx = 0; paramIdx < aggregateFunction.FunctionArguments.Count - 1; paramIdx++)
                {
                    aggregateFunction.FunctionArguments[paramIdx].Render(dbms, output, allParameters);
                    output.Append(", ");
                }

                aggregateFunction.FunctionArguments[aggregateFunction.FunctionArguments.Count - 1].Render(dbms, output, allParameters);
            }

            output.Append(")");
        }
 /// <exception cref="ArgumentException">
 /// Provided <paramref name="enumerableExpression"/>'s <see cref="Expression.Type"/> is not <see cref="IEnumerable{T}"/>
 /// </exception>
 protected AggregateFunctionExpressionBuilderBase(Expression enumerableExpression, AggregateFunction function)
     : base(ExtractItemTypeFromEnumerableType(enumerableExpression.Type))
 {
     this.enumerableExpression = enumerableExpression;
     this.function = function;
 }
 /// <summary>
 /// Defining how a property of MainTableDataSource should be rendered as a column's cell.
 /// </summary>
 /// <param name="aggregateFunction">Using predefined aggregate functions.</param>
 public AggregateFunctionAttribute(AggregateFunction aggregateFunction)
 {
     AggregateFunction = aggregateFunction;
 }
Exemplo n.º 13
0
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(RedemptionCodeFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, null, null, null));
 }
Exemplo n.º 14
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(RedemptionCodeFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 15
0
    public DataTable PivotData(string DataField, AggregateFunction[] Aggregate, string[] RowFields, string[] ColumnFields, double NSigma = 3)
    {
        DataTable dt = new DataTable();
        try
        {
            string Separator = "~";
            var RowList = _SourceTable.DefaultView.ToTable(true, RowFields).AsEnumerable().ToList();
            for (int index = RowFields.Count() - 1; index >= 0; index--)
                RowList = RowList.OrderBy(x => x.Field<object>(RowFields[index])).ToList();
            // Gets the list of columns .(dot) separated.
            var ColListFormula = (from x in _SourceTable.AsEnumerable()
                                  select new
                                  {
                                      Name = ColumnFields.Select(n => x.Field<object>(n))
                                          .Aggregate((a, b) => a += Separator + b.ToString())
                                  })
                               .Distinct()
                               .OrderBy(m => m.Name);

            List<string> ColList = new List<string>();
            if (!(ColumnFields == null)) if (ColumnFields.Length > 0) foreach (var col in ColListFormula) ColList.Add(col.Name.ToString());

            //Include Spec filter
            DataColumnCollection Speccolumns = _SpecTable.Columns;

            bool ColumnFiledHasSpec = false;
            foreach (string col in ColumnFields) if (Speccolumns.Contains(col)) ColumnFiledHasSpec = true;

            //Add a column for Parameter and Unit
            dt.Columns.Add("Parameter");

            //dt.Columns.Add(RowFields);
            foreach (string s in RowFields)
                dt.Columns.Add(s);

            bool SpecNeeded = false;
            foreach (var fun in Aggregate) if (fun.ToString().Contains("Spec")) SpecNeeded = true;
            if ((!ColumnFiledHasSpec) & SpecNeeded)
            {
                if (Aggregate.Contains(AggregateFunction.SpecMin)) dt.Columns.Add("SpecMin");
                if (Aggregate.Contains(AggregateFunction.SpecMax)) dt.Columns.Add("SpecMax");
                if (Aggregate.Contains(AggregateFunction.SpecTypical)) dt.Columns.Add("SpecTypical");
            }

            if (ColumnFields.Length > 0)
                foreach (string col in ColList)
                {
                    foreach (var fun in Aggregate)
                        if (!fun.ToString().Contains("Spec")) dt.Columns.Add(col + '#' + fun.ToString());  // Cretes the result columns.//
                }
            else
            {
                foreach (var fun in Aggregate)
                    if (!fun.ToString().Contains("Spec")) dt.Columns.Add(fun.ToString());  // Cretes the result columns.//
            }
            if (RowFields.Length > 0)
            {
                foreach (var RowName in RowList)
                {
                    DataRow row = dt.NewRow();
                    row["Parameter"] = DataField;
                    string strFilter = string.Empty;
                    string strSpecFilter = string.Empty;

                    foreach (string Field in RowFields)
                    {
                        row[Field] = RowName[Field];
                        strFilter += " and " + Field + " = '" + RowName[Field].ToString() + "'";

                        if (Speccolumns.Contains(Field)) strSpecFilter += " and " + Field + " = '" + RowName[Field].ToString() + "'";
                    }
                    strFilter = strFilter.Substring(5);
                    if (strSpecFilter.Length > 5) strSpecFilter = strSpecFilter.Substring(5);

                    if (ColumnFields.Length > 0)
                    {
                        if ((!ColumnFiledHasSpec) & SpecNeeded)
                        {
                            string filter = strSpecFilter;
                            if (Aggregate.Contains(AggregateFunction.SpecMin)) row["SpecMin"] = IncludeSpec(filter, DataField, "SpecMin");
                            if (Aggregate.Contains(AggregateFunction.SpecMax)) row["SpecMax"] = IncludeSpec(filter, DataField, "SpecMax");
                            if (Aggregate.Contains(AggregateFunction.SpecTypical)) row["SpecTypical"] = IncludeSpec(filter, DataField, "SpecTypical");
                        }

                        foreach (string col in ColList)
                        {
                            string filter = strFilter;
                            string[] strColValues = col.Split(Separator.ToCharArray(), StringSplitOptions.None);
                            for (int i = 0; i < ColumnFields.Length; i++)
                                filter += " and " + ColumnFields[i] + " = '" + strColValues[i] + "'";
                            foreach (var fun in Aggregate)
                            {
                                if (!fun.ToString().Contains("Spec"))
                                {
                                    if (fun.ToString().Contains("CPK"))
                                    {
                                        object spec_max = IncludeSpec("", DataField, "SpecMax");
                                        object spec_min = IncludeSpec("", DataField, "SpecMin");
                                        if (spec_max.ToString() == "No Spec" || spec_min.ToString() == "No Spec")
                                            row[fun.ToString()] = "No Spec";
                                        else
                                            row[fun.ToString()] = ObtainCPK(double.Parse(spec_max.ToString()), double.Parse(spec_min.ToString()), new string[] { filter }, DataField, NSigma);
                                    }
                                    else
                                        row[col + '#' + fun.ToString()] = GetData(new string[] { filter }, DataField, fun, NSigma);
                                }
                                else
                                {
                                    //filter = strSpecFilter;
                                    //row[col + '#' + fun.ToString()] = IncludeSpec(filter, DataField, fun.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (var fun in Aggregate)
                        {
                            string filter = strFilter;
                            if (!fun.ToString().Contains("Spec"))
                            {
                                if (fun.ToString().Contains("CPK"))
                                {
                                    object spec_max = IncludeSpec("", DataField, "SpecMax");
                                    object spec_min = IncludeSpec("", DataField, "SpecMin");
                                    if (spec_max.ToString() == "No Spec" || spec_min.ToString() == "No Spec")
                                        row[fun.ToString()] = "No Spec";
                                    else
                                        row[fun.ToString()] = ObtainCPK(double.Parse(spec_max.ToString()), double.Parse(spec_min.ToString()), new string[] { filter }, DataField, NSigma);
                                }
                                else
                                    row[fun.ToString()] = GetData(new string[] { filter }, DataField, fun, NSigma);
                            }
                            else
                            {
                                filter = strSpecFilter;
                                row[fun.ToString()] = IncludeSpec(filter, DataField, fun.ToString());
                            }
                        }
                    }
                    dt.Rows.Add(row);
                } // foreach (var RowName in RowList)
            } //if (RowFields.Length > 0)
            else
            {
                DataRow row = dt.NewRow();
                string strFilter = string.Empty;
                string strSpecFilter = string.Empty;

                if ((!ColumnFiledHasSpec) & SpecNeeded)
                {
                    string filter = strSpecFilter;
                    if (Aggregate.Contains(AggregateFunction.SpecMin)) row["SpecMin"] = IncludeSpec(filter, DataField, "SpecMin");
                    if (Aggregate.Contains(AggregateFunction.SpecMax)) row["SpecMax"] = IncludeSpec(filter, DataField, "SpecMax");
                    if (Aggregate.Contains(AggregateFunction.SpecTypical)) row["SpecTypical"] = IncludeSpec(filter, DataField, "SpecTypical");
                }

                foreach (string col in ColList)
                {
                    string filter = strFilter;
                    string[] strColValues = col.Split(Separator.ToCharArray(), StringSplitOptions.None);
                    for (int i = 0; i < ColumnFields.Length; i++)
                        filter += " and " + ColumnFields[i] + " = '" + strColValues[i] + "'";

                    filter = filter.Substring(5);
                    if (strSpecFilter.Length > 5) strSpecFilter = strSpecFilter.Substring(5);

                    foreach (var fun in Aggregate)
                    {
                        if (!fun.ToString().Contains("Spec"))
                        {
                            if (fun.ToString().Contains("CPK"))
                            {
                                object spec_max = IncludeSpec("", DataField, "SpecMax");
                                object spec_min = IncludeSpec("", DataField, "SpecMin");
                                if (spec_max.ToString() == "No Spec" || spec_min.ToString() == "No Spec")
                                    row[fun.ToString()] = "No Spec";
                                else
                                    row[fun.ToString()] = ObtainCPK(double.Parse(spec_max.ToString()), double.Parse(spec_min.ToString()), new string[] { filter }, DataField, NSigma);
                            }
                            else
                                row[col + '#' + fun.ToString()] = GetData(new string[] { filter }, DataField, fun, NSigma);
                        }
                        else
                        {
                            //filter = strSpecFilter;
                            //row[col + '#' + fun.ToString()] = IncludeSpec(filter, DataField, fun.ToString());
                        }
                    }
                }
                dt.Rows.Add(row);
            }
        }
        catch (Exception ex) { errormsg = errormsg + "," + ex.Message; }
        return dt;
    }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateResult"/> class.
 /// </summary>
 /// <param name="value">The value of the result.</param>
 /// <param name="function"><see cref="AggregateFunction"/> that generated the result.</param>
 public AggregateResult(object value, AggregateFunction function)
     : this(value, default(int), function)
 {
 }
Exemplo n.º 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="alias">The alias.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(TableSchema.TableColumn column, string alias, AggregateFunction aggregateType)
 {
     _columnName = column.QualifiedName;
     _alias = alias;
     _aggregateType = aggregateType;
 }
Exemplo n.º 18
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(AuditDataMessageRelatedFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 19
0
        private void CalculateAggregatesForInt(IEnumerable <TEntity> grouping, Func <TEntity, int> item, AggregateFunction function, string propertyName)
        {
            switch (function)
            {
            case AggregateFunction.Average:
                _aggregateProperties[propertyName] = grouping.Average(t => item(t));
                break;

            case AggregateFunction.Max:
                _aggregateProperties[propertyName] = grouping.Max(t => item(t));
                break;

            case AggregateFunction.Min:
                _aggregateProperties[propertyName] = grouping.Min(t => item(t));
                break;

            case AggregateFunction.Sum:
                _aggregateProperties[propertyName] = grouping.Sum(t => item(t));
                break;
            }
        }
Exemplo n.º 20
0
 public override string ToString()
 {
     return(AggregateFunction.NiceToString());
 }
        /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
        /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
        /// <param name="expressionToExecute">The expression to execute. Can be null</param>
        /// <param name="aggregateToApply">Aggregate function to apply. </param>
        /// <param name="filter">The filter to apply to retrieve the scalar</param>
        /// <param name="relations">The relations to walk</param>
        /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
        /// <returns>the scalar value requested</returns>
        public virtual object GetScalar(ProductSubcategoryFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
        {
            EntityFields fields = new EntityFields(1);

            fields[0] = EntityFieldFactory.Create(fieldIndex);
            if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null))
            {
                fields[0].ExpressionToApply = expressionToExecute;
            }
            if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None))
            {
                fields[0].AggregateFunctionToApply = aggregateToApply;
            }
            ProductSubcategoryDAO dao = DAOFactory.CreateProductSubcategoryDAO();

            return(dao.GetScalar(fields, base.Transaction, filter, relations, groupByClause));
        }
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(ProductSubcategoryFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, null, null, null));
 }
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(ProductSubcategoryFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 24
0
        public static DataSyncAction DropAggregateFunction(DataContext sourceDataContext, DataContext targetDataContext, AggregateFunction aggregateFunction)
        {
            var builder = new StringBuilder();

            builder.Append(StartThe)
            .Append(aggregateFunction.Description)
            .Append(Space)
            .Append(aggregateFunction.Namespace)
            .Append(EndDropped);
            Func <string> script = () => ContextScriptFactory.DropAggregateFunction(sourceDataContext, targetDataContext, aggregateFunction);

            if (string.IsNullOrEmpty(script.Invoke()))
            {
                return(null);
            }
            return(new DataSyncAction(
                       aggregateFunction
                       , aggregateFunction.Namespace
                       , builder.ToString()
                       , DataSyncOperationType.DropAggregateFunction
                       , script
                       ));
        }
Exemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="columnName">Name of the column.</param>
 /// <param name="alias">The alias.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(string columnName, string alias, AggregateFunction aggregateType)
 {
     _columnName = columnName;
     _aggregateType = aggregateType;
     _alias = alias;
 }
Exemplo n.º 26
0
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <param name="filter">The filter to apply to retrieve the scalar</param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(AuditDataMessageRelatedFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, filter, null, null));
 }
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(VendorContactFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, null, null, null));
 }
Exemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="columnName">ColumnName of the column.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(string columnName, AggregateFunction aggregateType)
 {
     ColumnName     = columnName;
     _aggregateType = aggregateType;
     Alias          = String.Concat(GetFunctionType(this), "Of", columnName);
 }
 public MembersAggregate(string name, Hierarchy hier, AggregateFunction aggr)
     : base(name, hier)
 {
     _aggregation=aggr ;
     this.Initialize(name);
 }
Exemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="columnName">ColumnName of the column.</param>
 /// <param name="alias">The alias.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(string columnName, string alias, AggregateFunction aggregateType)
 {
     ColumnName     = columnName;
     _aggregateType = aggregateType;
     Alias          = alias;
 }
Exemplo n.º 31
0
        public void CreateModule(
            Catalog catalog,
            IDataRecord reader)
        {
            var schemaName           = Convert.ToString(reader[SchemaNameOrdinal]);
            var objectName           = Convert.ToString(reader[ObjectNameOrdinal]);
            var typeDescription      = Convert.ToString(reader[TypeDescriptionOrdinal]);
            var definition           = Convert.ToString(reader[DefinitionOrdinal]);
            var usesAnsiNulls        = Convert.ToBoolean(reader[UsesAnsiNullsOrdinal]);
            var usesQuotedIdentifier = Convert.ToBoolean(reader[UsesQuotedIdentifierOrdinal]);
            var isDisabled           = Convert.ToBoolean(reader[IsDisabledOrdinal]);
            var isNotForReplication  = Convert.ToBoolean(reader[IsNotForReplicationOrdinal]);
            var triggerForSchema     = Convert.ToString(reader[TriggerForSchemaOrdinal]);
            var triggerForObjectName = Convert.ToString(reader[TriggerForObjectNameOrdinal]);

            var schema = catalog.Schemas[schemaName];

            if (schema == null)
            {
                return;
            }

            switch (typeDescription)
            {
            case "AGGREGATE_FUNCTION":
                var aggregateFunction = new AggregateFunction
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.AggregateFunctions.Add(aggregateFunction);
                return;

            case "SQL_INLINE_TABLE_VALUED_FUNCTION":
                var inlineTableValuedFunction = new InlineTableValuedFunction
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.InlineTableValuedFunctions.Add(inlineTableValuedFunction);
                return;

            case "SQL_SCALAR_FUNCTION":
            case "FUNCTION":
                var scalarFunction = new ScalarFunction
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.ScalarFunctions.Add(scalarFunction);
                return;

            case "SQL_STORED_PROCEDURE":
            case "PROCEDURE":
                var storedProcedure = new StoredProcedure
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.StoredProcedures.Add(storedProcedure);
                return;

            case "SQL_TABLE_VALUED_FUNCTION":
                var tableValuedFunction = new TableValuedFunction
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.TableValuedFunctions.Add(tableValuedFunction);
                return;

            case "SQL_TRIGGER":
            case "TRIGGER":
                var trigger = new Trigger
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier,
                    IsDisabled           = isDisabled,
                    IsNotForReplication  = isNotForReplication,
                    TriggerForSchema     = triggerForSchema,
                    TriggerForObjectName = triggerForObjectName
                };

                schema.Triggers.Add(trigger);
                return;

            case "VIEW":
                var view = new View
                {
                    Schema               = schema,
                    ObjectName           = objectName,
                    Definition           = definition,
                    UsesAnsiNulls        = usesAnsiNulls,
                    UsesQuotedIdentifier = usesQuotedIdentifier
                };

                schema.Views.Add(view);
                return;
                //case "CLR_SCALAR_FUNCTION":
                //case "CLR_STORED_PROCEDURE":
                //case "CLR_TABLE_VALUED_FUNCTION":
                //case "CLR_TRIGGER":
            }
        }
Exemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(IDBObject column, AggregateFunction aggregateType)
 {
     ColumnName     = column.QualifiedName;
     _aggregateType = aggregateType;
     Alias          = String.Concat(GetFunctionType(this), "Of", column.Name);
 }
Exemplo n.º 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="alias">The alias.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(IDBObject column, string alias, AggregateFunction aggregateType)
 {
     ColumnName     = column.QualifiedName;
     Alias          = alias;
     _aggregateType = aggregateType;
 }
Exemplo n.º 34
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(ShipperFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 35
0
 private new void LoadFromXml(System.Xml.XmlElement xmlEl)
 {
     base.LoadFromXml(xmlEl);
     _aggregation = (AggregateFunction)System.Enum.Parse(typeof(AggregateFunction), xmlEl.GetAttribute("F"));
     Initialize(_name);
 }
Exemplo n.º 36
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(UriComponentFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 37
0
        private static object GetData(DataTable _SourceTable, string Filter, string DataField, AggregateFunction Aggregate)
        {
            try
            {
                DataRow[] FilteredRows = _SourceTable.Select(Filter);
                List<object> objList =
                 FilteredRows.Select(x => x.Field<object>(DataField)).ToList();

                switch (Aggregate)
                {
                    case AggregateFunction.Average:
                        {
                            for (int i = 0; i < objList.Count(); i++)
                                if (IsNumber(objList[i]) == false)
                                    objList.Remove(objList[i]);

                            return objList.Average(x => float.Parse(x.ToString()));
                        }
                    case AggregateFunction.Count:
                        return objList.Count();
                    case AggregateFunction.Exists:
                        return (objList.Count() == 0) ? "False" : "True";
                    case AggregateFunction.First:
                        return objList.FirstOrDefault();
                    case AggregateFunction.Last:
                        return objList.LastOrDefault();
                    case AggregateFunction.Max:
                        return objList.Max();
                    case AggregateFunction.Min:
                        return objList.Min();
                    case AggregateFunction.Sum:
                        {
                            for (int i = 0; i < objList.Count(); i++)
                                if (IsNumber(objList[i]) == false)
                                    objList[i] = 0;

                            return objList.Sum(x => float.Parse(x.ToString()));
                        }
                    default:
                        return null;
                }
            }
            catch (Exception ex)
            {
                return "#Error";
            }
        }
Exemplo n.º 38
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CampaignItemFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 39
0
 public MembersAggregate(string name, Hierarchy hier, AggregateFunction aggr) : base(name, hier)
 {
     _aggregation = aggr;
     this.Initialize(name);
 }
Exemplo n.º 40
0
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CampaignItemFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, null, null, null));
 }
Exemplo n.º 41
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="columnName">Name of the column.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(string columnName, AggregateFunction aggregateType)
 {
     _columnName = columnName;
     _aggregateType = aggregateType;
     _alias = String.Concat(GetFunctionType(this), "Of", columnName);
 }
Exemplo n.º 42
0
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <param name="filter">The filter to apply to retrieve the scalar</param>
 /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CampaignItemFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IGroupByCollection groupByClause)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, filter, null, groupByClause));
 }
Exemplo n.º 43
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Aggregate"/> class.
 /// </summary>
 /// <param name="column">The column.</param>
 /// <param name="aggregateType">Type of the aggregate.</param>
 public Aggregate(TableSchema.TableColumn column, AggregateFunction aggregateType)
 {
     _columnName = column.QualifiedName;
     _aggregateType = aggregateType;
     _alias = String.Concat(GetFunctionType(this), "Of", column.ColumnName);
 }
Exemplo n.º 44
0
    public DataTable PullPivotData(string DataField, AggregateFunction[] Aggregate, string[] RowFields, string[] ColumnFields, double NSigma = 3, int[] CurrentPosition = null)
    {
        DataTable dt = new DataTable();
        DataTable dtp = new DataTable();
        try
        {
            string Separator = "$#";
            var RowList = _SourceTable.DefaultView.ToTable(true, RowFields).AsEnumerable().ToList();
            for (int index = RowFields.Count() - 1; index >= 0; index--)
                RowList = RowList.OrderBy(x => x.Field<object>(RowFields[index])).ToList();
            // Gets the list of columns .(dot) separated.
            var ColList = (from x in _SourceTable.AsEnumerable()
                           select new
                           {
                               Name = ColumnFields.Select(n => x.Field<object>(n))
                                   .Aggregate((a, b) => a += Separator + b.ToString())
                           })
                               .Distinct()
                               .OrderBy(m => m.Name);

            //dt.Columns.Add(RowFields);
            foreach (string s in RowFields)
                dt.Columns.Add(s);

            if (ColumnFields.Length > 0)
                foreach (var col in ColList)
                    foreach (var fun in Aggregate)
                        dt.Columns.Add(col.Name.ToString() + '#' + fun.ToString());  // Cretes the result columns.//
            else
                foreach (var fun in Aggregate)
                    dt.Columns.Add(fun.ToString());  // Cretes the result columns.//

            //Add Column names from Raw data
            foreach (DataColumn col in _SourceTable.Columns)
                dtp.Columns.Add(col.ColumnName.ToString());

            int rowCount = 0;
            foreach (var RowName in RowList)
            {
                DataRow row = dt.NewRow();
                rowCount++;
                string strFilter = string.Empty;

                foreach (string Field in RowFields)
                {
                    row[Field] = RowName[Field];
                    strFilter += " and " + Field + " = '" + RowName[Field].ToString() + "'";
                }
                strFilter = strFilter.Substring(5);

                if (ColumnFields.Length > 0)
                    foreach (var col in ColList)
                    {
                        string filter = strFilter;
                        string[] strColValues = col.Name.ToString().Split(Separator.ToCharArray(), StringSplitOptions.None);
                        for (int i = 0; i < ColumnFields.Length; i++)
                            filter += " and " + ColumnFields[i] + " = '" + strColValues[i] + "'";
                        if (rowCount == CurrentPosition[0] + 1)
                        {
                            DataRow[] FilteredRows = _SourceTable.Select(filter);
                            foreach (DataRow rowEntry in FilteredRows)
                            {
                                dtp.ImportRow(rowEntry);
                            }
                        }
                    }
                else
                {
                    string filter = strFilter;
                    if (rowCount == CurrentPosition[0] + 1)
                    {
                        DataRow[] FilteredRows = _SourceTable.Select(filter);
                        foreach (DataRow rowEntry in FilteredRows)
                        {
                            dtp.ImportRow(rowEntry);
                        }
                    }
                }
                //dt.Rows.Add(row);
            }
        }
        catch (Exception ex) { }
        return dtp;
    }
Exemplo n.º 45
0
        /// <summary>
        /// Adds new aggregate result to collection.
        /// </summary>
        /// <param name="group">The group.</param>
        /// <param name="result">The aggregate result.</param>
        /// <param name="func">The aggregate function.</param>
        private static void AddAggregateResult(QueryableCollectionViewGroup group, Veyron.SharedTypes.AggregateResult result, AggregateFunction func)
        {
            var aggregateResult = new AggregateResult(result.Value, func);

            var r = result;
            var columnAggregates = group.AggregateResults
                .SkipWhile(x => !x.FunctionName.StartsWith(r.ColumnName, StringComparison.Ordinal))
                .TakeWhile(x => x.FunctionName.StartsWith(r.ColumnName, StringComparison.Ordinal))
                .ToList();

            if (!columnAggregates.Any())
                group.AggregateResults.Add(aggregateResult);
            else
            {
                var index = columnAggregates.TakeWhile(x =>
                        AggregateHelper.GetAttribute(
                            AggregateHelper.GetTypeByFullName(x.Caption.Replace(":", null))).Order <
                        AggregateHelper.GetAttribute(result.SummaryType).Order).Count();

                if (columnAggregates.Count <= index)
                {
                    var lastItemIndex = group.AggregateResults.IndexOf(columnAggregates.Last());

                    if (lastItemIndex == group.AggregateResults.Count - 1)
                        group.AggregateResults.Add(aggregateResult);
                    else
                        group.AggregateResults.Insert(lastItemIndex + 1, aggregateResult);
                }
                else
                {
                    var itemIndex = group.AggregateResults.IndexOf(columnAggregates[index]);
                    group.AggregateResults.Insert(itemIndex, aggregateResult);
                }
            }
        }
Exemplo n.º 46
0
 public DataAttribute AddAggregateFunction(DataContainer container, AggregateFunction aggregateFunction)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 47
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateResult"/> class.
 /// </summary>
 /// <param name="function"><see cref="AggregateFunction"/> that generated the result.</param>
 /// <exception cref="ArgumentNullException"><c>function</c> is null.</exception>
 public AggregateResult(AggregateFunction function)
     : this(null, function)
 {
 }
Exemplo n.º 48
0
 private void initializeFunction(AggregateFunction aggregateFunction)
 {
     switch (aggregateFunction)
     {
         case AggregateFunction.Average:
             ColumnAggregateFunction = new Average { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.Maximum:
             ColumnAggregateFunction = new Maximum { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.Minimum:
             ColumnAggregateFunction = new Minimum { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.StdDev:
             ColumnAggregateFunction = new StdDev { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.Sum:
             ColumnAggregateFunction = new Sum { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.Variance:
             ColumnAggregateFunction = new Variance { DisplayFormatFormula = DisplayFormatFormula };
             break;
         case AggregateFunction.Empty:
             ColumnAggregateFunction = new Empty { DisplayFormatFormula = DisplayFormatFormula };
             break;
         default:
             throw new NotSupportedException("Please select a defined IAggregateFunction.");
     }
 }
 private new void LoadFromXml(System.Xml.XmlElement xmlEl )
 {
     base.LoadFromXml (xmlEl);
     _aggregation=(AggregateFunction)System.Enum.Parse(typeof(AggregateFunction) , xmlEl.GetAttribute("F"));
     Initialize(_name);
 }
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(VendorContactFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 51
0
    /// <summary>
    /// Retrives the data for matching RowField value and ColumnFields values with Aggregate function applied on them.
    /// </summary>
    /// <param name="Filter">DataTable Filter condition as a string</param>
    /// <param name="DataField">The column name which needs to spread out in Data Part of the Pivoted table</param>
    /// <param name="Aggregate">Enumeration to determine which function to apply to aggregate the data</param>
    /// <returns></returns>
    public object GetData(string[] Filters, string DataField, AggregateFunction Aggregate, double NSigma = 3)
    {
        try
        {
            List<DataRow[]> FilteredRows = new List<DataRow[]>();
            foreach (string filter in Filters)
            {
                FilteredRows.Add(_SourceTable.Select(filter));
            }
            object[] objList = FilteredRows.Select(x => x.Select(y => y.Field<object>(DataField))).SelectMany(i => i).ToArray();
            switch (Aggregate)
            {
                case AggregateFunction.Average:
                    return GetAverage(objList);
                case AggregateFunction.Count:
                    return objList.Count();
                case AggregateFunction.Exists:
                    return (objList.Count() == 0) ? "False" : "True";
                case AggregateFunction.First:
                    return GetFirst(objList);
                case AggregateFunction.Last:
                    return GetLast(objList);
                case AggregateFunction.Max:
                    return GetMax(objList);
                case AggregateFunction.Min:
                    return GetMin(objList);
                case AggregateFunction.Sum:
                    return GetSum(objList);
                case AggregateFunction.Stdev:
                    return GetStdev(objList);
                case AggregateFunction.NSigmaPos:
                    return GetNSigmaPos(objList, NSigma);
                case AggregateFunction.NSigmaNeg:
                    return GetNSigmaNeg(objList, NSigma);
                case AggregateFunction.FullArray:
                    return GetFullArray(objList);
                case AggregateFunction.NSigmaNegMin:
                    List<object> minimumNSigmaNeg = new List<object>();
                    foreach (var e in FilteredRows)
                    {
                        minimumNSigmaNeg.Add(GetNSigmaNeg(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                    }
                    return GetMin(minimumNSigmaNeg.ToArray());
                case AggregateFunction.NSigmaPosMax:
                    List<object> maximumNSigmaPos = new List<object>();
                    foreach (var e in FilteredRows)
                    {
                        maximumNSigmaPos.Add(GetNSigmaPos(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                    }
                    return GetMax(maximumNSigmaPos.ToArray());
                case AggregateFunction.NSigmaNegCorrespondingStdDev:
                    List<Tuple<object, object>> correspondingNSigmaNeg = new List<Tuple<object, object>>();
                    foreach (var e in FilteredRows)
                    {
                        Tuple<object, object> stdDevNSigmaNed = new Tuple<object, object>(GetStdev(e.Select(y => y.Field<object>(DataField)).ToArray()), GetNSigmaNeg(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                        correspondingNSigmaNeg.Add(stdDevNSigmaNed);
                    }
                    return correspondingNSigmaNeg.OrderBy(x => x.Item2).ToList()[0].Item1;
                case AggregateFunction.NSigmaPosCorrespondingStdDev:
                    List<Tuple<object, object>> correspondingPSigmaPos = new List<Tuple<object, object>>();
                    foreach (var e in FilteredRows)
                    {
                        Tuple<object, object> stdDevNSigmaPos = new Tuple<object, object>(GetStdev(e.Select(y => y.Field<object>(DataField)).ToArray()), GetNSigmaPos(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                        correspondingPSigmaPos.Add(stdDevNSigmaPos);
                    }
                    return correspondingPSigmaPos.OrderByDescending(x => x.Item2).ToList()[0].Item1;

                case AggregateFunction.NSigmaNegCorrespondingAvg:
                    List<Tuple<object, object>> correspondingNSigmaAvg = new List<Tuple<object, object>>();
                    foreach (var e in FilteredRows)
                    {
                        Tuple<object, object> stdDevNSigmaNed = new Tuple<object, object>(GetAverage(e.Select(y => y.Field<object>(DataField)).ToArray()), GetNSigmaNeg(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                        correspondingNSigmaAvg.Add(stdDevNSigmaNed);
                    }
                    return correspondingNSigmaAvg.OrderBy(x => x.Item2).ToList()[0].Item1;
                case AggregateFunction.NSigmaPosCorrespondingAvg:
                    List<Tuple<object, object>> correspondingPSigmaAvg = new List<Tuple<object, object>>();
                    foreach (var e in FilteredRows)
                    {
                        Tuple<object, object> stdDevNSigmaPos = new Tuple<object, object>(GetAverage(e.Select(y => y.Field<object>(DataField)).ToArray()), GetNSigmaPos(e.Select(y => y.Field<object>(DataField)).ToArray(), NSigma));
                        correspondingPSigmaAvg.Add(stdDevNSigmaPos);
                    }
                    return correspondingPSigmaAvg.OrderByDescending(x => x.Item2).ToList()[0].Item1;
                default:
                    return null;
            }
        }
        catch (Exception ex)
        {
            return "#Error";
        }
    }
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CustomerCustomerDemoFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 53
0
        /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
        /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
        /// <param name="expressionToExecute">The expression to execute. Can be null</param>
        /// <param name="aggregateToApply">Aggregate function to apply. </param>
        /// <param name="filter">The filter to apply to retrieve the scalar</param>
        /// <param name="relations">The relations to walk</param>
        /// <param name="groupByClause">The groupby clause to apply to retrieve the scalar</param>
        /// <returns>the scalar value requested</returns>
        public virtual object GetScalar(CampaignItemFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
        {
            EntityFields fields = new EntityFields(1);

            fields[0] = EntityFieldFactory.Create(fieldIndex);
            if ((fields[0].ExpressionToApply == null) || (expressionToExecute != null))
            {
                fields[0].ExpressionToApply = expressionToExecute;
            }
            if ((fields[0].AggregateFunctionToApply == AggregateFunction.None) || (aggregateToApply != AggregateFunction.None))
            {
                fields[0].AggregateFunctionToApply = aggregateToApply;
            }
            return(DAOFactory.CreateCampaignItemDAO().GetScalar(fields, this.Transaction, filter, relations, groupByClause));
        }
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CustomerCustomerDemoFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, null, null, null));
 }
Exemplo n.º 55
0
        private Expression BindAggregate(Type resultType, AggregateFunction aggregateFunction, Expression source, LambdaExpression selector)
        {
            MetaProjectorExpression mp = AsProjection(Visit(source));
            if (selector == null)
                return mp.Projector;

            Expression projector = MapAndVisit(selector, mp);
            return projector;
        }
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(OrderDetailFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }
Exemplo n.º 57
0
 /// <summary>
 /// Predefined aggregate functions provider
 /// </summary>
 /// <param name="aggregateFunction">A set of a predefined aggregate functions.</param>
 public AggregateProvider(AggregateFunction aggregateFunction)
 {
     initializeFunction(aggregateFunction);
 }
 /// <summary> Gets a scalar value, calculated with the aggregate and expression specified. the field index specified is the field the expression and aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="expressionToExecute">The expression to execute. Can be null</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <param name="filter">The filter to apply to retrieve the scalar</param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(OrderDetailFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter)
 {
     return(GetScalar(fieldIndex, expressionToExecute, aggregateToApply, filter, null, null));
 }
Exemplo n.º 59
0
 /// <summary>Creates the specified field on the position indexInResultset in the resultset.</summary>
 /// <param name="fieldToDefine">The specification of the field to create.</param>
 /// <param name="indexInResultset">The position in the resultset where the field will be created on</param>
 /// <param name="alias">The alias to use for this field in the resultset</param>
 /// <param name="entityAlias">The alias to use for the entity this field belongs to. Required to specify multiple times the same entity in a typed list</param>
 /// <param name="aggregateFunctionToApply">the aggregate function to apply to this field.</param>
 public void DefineField(ProductFieldIndex fieldToDefine, int indexInResultset, string alias, string entityAlias, AggregateFunction aggregateFunctionToApply)
 {
     IEntityField2 fieldToAdd = EntityFieldFactory.Create(fieldToDefine);
     fieldToAdd.Alias = alias;
     fieldToAdd.ObjectAlias = entityAlias;
     fieldToAdd.AggregateFunctionToApply = aggregateFunctionToApply;
     base[indexInResultset] = fieldToAdd;
 }
Exemplo n.º 60
0
 /// <summary> Gets a scalar value, calculated with the aggregate. the field index specified is the field the aggregate are applied on.</summary>
 /// <param name="fieldIndex">Field index of field to which to apply the aggregate function and expression</param>
 /// <param name="aggregateToApply">Aggregate function to apply. </param>
 /// <returns>the scalar value requested</returns>
 public object GetScalar(CountryRegionFieldIndex fieldIndex, AggregateFunction aggregateToApply)
 {
     return(GetScalar(fieldIndex, null, aggregateToApply, null, null, null));
 }