Exemple #1
0
        private DataColumn AddColumnToDataTable(Expression expression)
        {
            DataColumn dc = null;
            string newColName = expression.ToString();
            if (!_dt.Columns.Contains(newColName))
            {
                dc = _dt.Columns.Add(newColName, typeof(double));
                dc.ExtendedProperties[VBCommon.Globals.OPERATION] = true;

                foreach (string var in expression.Variables)
                {
                    DataColumn dc2 = _dt.Columns[var];
                    if (dc2.ExtendedProperties.ContainsKey(VBCommon.Globals.TRANSFORM))
                    {
                        dc.ExtendedProperties.Add(VBCommon.Globals.TRANSFORM, true);
                        break;
                    }
                }
            }
            return dc;
        }
Exemple #2
0
 /// <summary>
 /// This function verifies that the expression contains a valid Operation and that the field(s) are included in the datatable
 /// </summary>
 /// <param name="expression">Expression to be verified</param>
 private bool ExecuteExpression(Expression expression)
 {
     switch (expression.Operation)
     {
         case Globals.Operations.MAX :
             MAXIMUM(expression);
             break;
         case Globals.Operations.MEAN:
             MEAN(expression);
             break;
         case Globals.Operations.PROD:
             PRODUCT(expression);
             break;
         case Globals.Operations.SUM:
             SUM(expression);
             break;
         case Globals.Operations.MIN:
             MINIMUM(expression);
             break;
     }
     return true;
 }
Exemple #3
0
        private bool VerifyExpression(Expression expression)
        {
            if (_dt == null)
                return false;

            foreach (string var in expression.Variables)
            {
                if (_dt.Columns.Contains(var) == false)
                    return false;
            }
            return true;
        }
Exemple #4
0
        /// <summary>
        /// Sum the values of all the fields in the expression
        /// </summary>
        /// <param name="expression"></param>
        private void SUM(Expression expression)
        {
            string newColName = expression.ToString();
            DataColumn dc = AddColumnToDataTable(expression);

            if (dc != null)
            {
                for (int i = 0; i < _dt.Rows.Count; i++)
                {
                    double sum = 0.0;
                    foreach (string var in expression.Variables)
                    {
                        sum += Convert.ToDouble(_dt.Rows[i][var]);
                    }
                    _dt.Rows[i][newColName] = sum;
                }
            }
        }
Exemple #5
0
 public ExpressionExecution(DataTable dt, Expression[] expressions)
 {
     _dt = dt.Copy();
     _expressions = expressions;
     Init();
 }
Exemple #6
0
        /// <summary>
        /// Multiply the values of all the fields in the expression
        /// </summary>
        /// <param name="expression"></param>
        private void PRODUCT(Expression expression)
        {
            string newColName = expression.ToString();
            DataColumn dc = AddColumnToDataTable(expression);

            if (dc != null)
            {
                for (int i = 0; i < _dt.Rows.Count; i++)
                {
                    double product = 1.0;
                    foreach (string var in expression.Variables)
                    {
                        product = product * Convert.ToDouble(_dt.Rows[i][var]);
                    }
                    _dt.Rows[i][newColName] = product;
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Select the mininum values of all the fields in the expression
        /// </summary>
        /// <param name="expression"></param>
        private void MINIMUM(Expression expression)
        {
            string newColName = expression.ToString();
            DataColumn dc = AddColumnToDataTable(expression);

            if (dc != null)
            {
                for (int i = 0; i < _dt.Rows.Count; i++)
                {
                    double min = double.PositiveInfinity;
                    foreach (string var in expression.Variables)
                    {
                        double current = Convert.ToDouble(_dt.Rows[i][var]);
                        if (current < min)
                            min = current;
                    }
                    _dt.Rows[i][newColName] = min;
                }
            }
        }
Exemple #8
0
 public Expression(Expression exp)
 {
     _operation = exp.Operation;
     lstVariables = exp.Variables.ToList();
     strExpressionString = exp.ExpressionString;
 }