コード例 #1
0
        public void Execute()
        {
            _regressionTable = new DataTable();
            _regressionTable.Columns.Add("SeriesName", typeof(string));
            _regressionTable.Columns.Add("Predictor", typeof(object));
            _regressionTable.Columns.Add("Response", typeof(double));

            Dictionary <string, string> config = Context.SetProperties;
            StringBuilder HTMLString           = new StringBuilder();

            System.Data.DataTable sourceTable = BuildTempContextTable();
            cDataSetHelper        dsHelper    = new cDataSetHelper();

            Dictionary <string, string> args = new Dictionary <string, string>();

            string strataVarValue = string.Empty;
            string objectElement  = string.Empty;

            SilverlightMarkup silverlight = new SilverlightMarkup();

            DataTable Strata_ValueList;

            if (string.IsNullOrEmpty(_strataVar))
            {
                Strata_ValueList = sourceTable.Clone();
                Strata_ValueList.Rows.Add(Strata_ValueList.NewRow());
            }
            else
            {
                Strata_ValueList = dsHelper.SelectDistinct("", sourceTable, _strataVar);
            }

            FilterStruct filter = new FilterStruct();

            filter.strataVarName = _strataVar;

            _independentValueTypesSame = true;
            if (_independentVariableArray.Length > 1)
            {
                for (int i = 0; (i + 1) < _independentVariableArray.Length; i++)
                {
                    if (sourceTable.Columns[_independentVariableArray[i]].DataType != sourceTable.Columns[_independentVariableArray[i + 1]].DataType)
                    {
                        _independentValueTypesSame = false;
                        break;
                    }
                }
            }

            _independentValuesAllBool = true;
            for (int i = 0; i < _independentVariableArray.Length; i++)
            {
                string indepVar = _independentVariableArray[i];

                if (sourceTable.Columns.Contains(indepVar))
                {
                    if (sourceTable.Columns[indepVar].DataType.Name != "Byte")
                    {
                        _independentValuesAllBool = false;
                        break;
                    }
                }
                else
                {
                    return;
                }
            }

            foreach (DataRow strataRow in Strata_ValueList.Rows)
            {
                if (string.IsNullOrEmpty(_strataVar) || strataRow[_strataVar] == DBNull.Value)
                {
                    filter.strataVarValue = "null";
                }
                else
                {
                    filter.strataVarValue = strataRow[_strataVar].ToString();
                }

                if (_graphType == SilverlightStatics.Scatter)
                {
                    if (_independentVariableArray.Length < 2)
                    {
                        throw new Exception("Scatter graphs must contain two (2) main variables.");
                    }

                    string categoryName = string.Empty;
                    Dictionary <object, double> indDepValuePairCollection = new Dictionary <object, double>();

                    List <string> StrataVarNameList  = new List <string>();
                    List <string> StrataVarValueList = new List <string>();

                    string regressor  = _independentVariableArray[0];
                    string regressand = _independentVariableArray[1];

                    StrataVarNameList.Add(filter.strataVarName);
                    StrataVarValueList.Add(filter.strataVarValue);

                    DataTable table = new DataTable();
                    table.Columns.Add(new DataColumn(sourceTable.Columns[regressor].ColumnName, sourceTable.Columns[regressor].DataType));
                    table.Columns.Add(new DataColumn(sourceTable.Columns[regressand].ColumnName, sourceTable.Columns[regressand].DataType));

                    foreach (DataRow row in sourceTable.Rows)
                    {
                        table.Rows.Add(row[regressor], row[regressand]);
                    }

                    foreach (DataRow row in table.Rows)
                    {
                        if (row[regressor] != DBNull.Value)
                        {
                            string seriesName       = string.Empty;
                            object independentValue = new object();

                            if (_independentValuesAllBool)
                            {
                                independentValue = regressor;
                                byte value = (byte)(row[regressor]);
                            }
                            else
                            {
                                independentValue = GetValue(regressor, row, config);
                            }

                            seriesName = string.Format("{0} x {1}", sourceTable.Columns[regressor].ColumnName, sourceTable.Columns[regressand].ColumnName);

                            if (string.IsNullOrEmpty(_weightVar))
                            {
                                double dependentVal;

                                if (double.TryParse(row[regressand].ToString(), out dependentVal))
                                {
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                            else
                            {
                                filter.independentVarValue = row[regressor];
                                filter.independentVarName  = regressor;
                                filter.weightVarName       = _weightVar;
                                double dependentVal = GetAggregateValue(sourceTable, filter);

                                _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                            }
                        }
                    }
                }
                else if (sourceTable.Columns.Contains(_graphCrossTab))
                {
                    string categoryName = string.Empty;
                    Dictionary <object, double> indDepValuePairCollection = new Dictionary <object, double>();

                    List <string> StrataVarNameList  = new List <string>();
                    List <string> StrataVarValueList = new List <string>();

                    foreach (string independentVariableName in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariableName,
                            _graphCrossTab,
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        foreach (DataColumn crossTabCandidate in workingTable.Columns)
                        {
                            if (crossTabCandidate.ColumnName != "__Values__" && crossTabCandidate.ColumnName != "__Count__")
                            {
                                Type crossTabDataType = sourceTable.Columns[_graphCrossTab].DataType;

                                string crossTabValue = crossTabCandidate.ColumnName;

                                if (crossTabDataType.Name == "Byte")
                                {
                                    if (crossTabCandidate.ColumnName == "0")
                                    {
                                        crossTabValue = config["RepresentationOfNo"];
                                    }
                                    else if (crossTabCandidate.ColumnName == "1")
                                    {
                                        crossTabValue = config["RepresentationOfYes"];
                                    }
                                }

                                string seriesName = string.Format("{0}={1}", _graphCrossTab, crossTabValue);

                                foreach (DataRow row in workingTable.Rows)
                                {
                                    double dependentVal;

                                    if (double.TryParse(row[crossTabCandidate.ColumnName].ToString(), out dependentVal))
                                    {
                                        if (row["__Values__"] != DBNull.Value)
                                        {
                                            string independentVariableTypeName = string.Empty;

                                            if (sourceTable.Columns.Contains(independentVariableName))
                                            {
                                                independentVariableTypeName = sourceTable.Columns[independentVariableName].DataType.Name;
                                            }

                                            categoryName = BuildCategoryName(independentVariableName, independentVariableTypeName, row, config);

                                            object independentValue = row["__Values__"];

                                            if (string.IsNullOrEmpty(_weightVar))
                                            {
                                                if (double.TryParse(row[crossTabCandidate.ColumnName].ToString(), out dependentVal))
                                                {
                                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                                }
                                            }
                                            else
                                            {
                                                object independentVariableValue = row["__Values__"];

                                                bool isValue = false;

                                                if (independentVariableValue != null)
                                                {
                                                    isValue = true;

                                                    if (independentVariableValue is string)
                                                    {
                                                        string candidate = ((string)independentVariableValue).Trim();
                                                        isValue = candidate != string.Empty;
                                                    }
                                                }

                                                if (isValue)
                                                {
                                                    filter.crossTabName        = _graphCrossTab;
                                                    filter.crossTabValue       = crossTabCandidate.ColumnName;
                                                    filter.independentVarName  = independentVariableName;
                                                    filter.independentVarValue = independentVariableValue;
                                                    filter.weightVarName       = _weightVar;
                                                    dependentVal = GetAggregateValue(sourceTable, filter);
                                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (_graphType == "EPICURVE" && _graphIntervalUnits != "")
                {
                    string categoryName = string.Empty;
                    Dictionary <object, double> indDepValuePairCollection = new Dictionary <object, double>();

                    List <string> StrataVarNameList  = new List <string>();
                    List <string> StrataVarValueList = new List <string>();

                    foreach (string independentVariable in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariable,
                            "",
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        DateTime intervalStart = DateTime.MinValue;
                        DateTime intervalEnd   = DateTime.MinValue;
                        DateTime dateTimeValue = DateTime.MinValue;
                        intervalStart = _graphStartFrom;

                        double   givenInterval = 1;
                        int      days = 0, hours = 0, minutes = 0, seconds = 0;
                        TimeSpan period = new TimeSpan(days, hours, minutes, seconds);

                        if (_graphInterval != "")
                        {
                            double.TryParse(_graphInterval, out givenInterval);
                        }

                        if (_graphIntervalUnits == "")
                        {
                            _graphIntervalUnits = "Hours";
                        }

                        foreach (DataRow row in workingTable.Rows)
                        {
                            if (row["__Values__"] != DBNull.Value)
                            {
                                dateTimeValue = (DateTime)row["__Values__"];

                                //if (intervalStart == DateTime.MinValue)
                                //{
                                //    intervalStart = dateTimeValue;
                                //    _graphStartFrom = dateTimeValue;
                                //}

                                while (dateTimeValue >= intervalEnd)
                                {
                                    if (intervalEnd != DateTime.MinValue)
                                    {
                                        intervalStart = intervalEnd;
                                    }

                                    switch (_graphIntervalUnits)
                                    {
                                    case "Years":
                                        intervalEnd = intervalStart.AddYears((int)givenInterval);
                                        break;

                                    case "Quarters":
                                        intervalEnd = intervalStart.AddDays(givenInterval * 365.25 / 4.0);
                                        break;

                                    case "Weeks":
                                        intervalEnd = intervalStart.AddDays(givenInterval * 7);
                                        break;

                                    case "Days":
                                        intervalEnd = intervalStart.AddDays(givenInterval);
                                        break;

                                    case "Hours":
                                        intervalEnd = intervalStart.AddHours(givenInterval);
                                        break;

                                    case "Minutes":
                                        intervalEnd = intervalStart.AddMinutes(givenInterval);
                                        break;

                                    case "Seconds":
                                        intervalEnd = intervalStart.AddSeconds(givenInterval);
                                        break;
                                    }
                                }

                                string seriesName       = string.Empty;
                                object independentValue = new object();

                                independentValue = BuildIndependentValue(independentVariable, row, config);

                                if (string.IsNullOrEmpty(seriesName))
                                {
                                    seriesName = SilverlightStatics.COUNT;

                                    if (_independentVariableArray.Length > 1)
                                    {
                                        seriesName = independentVariable;
                                    }

                                    if (string.IsNullOrEmpty(_aggregateFunction) == false)
                                    {
                                        seriesName = _aggregateFunction;
                                    }
                                }

                                if (string.IsNullOrEmpty(_weightVar))
                                {
                                    double dependentVal;

                                    if (double.TryParse(row["__Count__"].ToString(), out dependentVal))
                                    {
                                        if ((dateTimeValue >= intervalStart) && (dateTimeValue < intervalEnd))
                                        {
                                            string    expression = "Predictor = #" + intervalStart.ToString() + "#";
                                            DataRow[] foundRows  = _regressionTable.Select(expression);

                                            if (foundRows.Length == 0)
                                            {
                                                _regressionTable.Rows.Add(seriesName, intervalStart, dependentVal);
                                            }
                                            else
                                            {
                                                foundRows[0]["Response"] = (double)foundRows[0]["Response"] + dependentVal;
                                                _regressionTable.AcceptChanges();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    filter.independentVarValue = row["__Values__"];
                                    filter.independentVarName  = independentVariable;
                                    filter.weightVarName       = _weightVar;
                                    double dependentVal = GetAggregateValue(sourceTable, filter);
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                        }
                    }
                }
                else
                {
                    string categoryName = string.Empty;
                    Dictionary <object, double> indDepValuePairCollection = new Dictionary <object, double>();

                    List <string> StrataVarNameList  = new List <string>();
                    List <string> StrataVarValueList = new List <string>();

                    foreach (string independentVariable in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariable,
                            "",
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        foreach (DataRow row in workingTable.Rows)
                        {
                            if (row["__Values__"] != DBNull.Value)
                            {
                                string seriesName       = string.Empty;
                                object independentValue = new object();

                                if (!_independentValueTypesSame || _graphType == SilverlightStatics.Pie)
                                {
                                    independentValue = BuildIndependentValue(independentVariable, row, config);
                                }
                                else if (_independentValuesAllBool)
                                {
                                    independentValue = independentVariable;
                                    byte value = (byte)(row["__Values__"]);

                                    seriesName = row["__Values__"].ToString();

                                    if (value == 0)
                                    {
                                        seriesName = config["RepresentationOfNo"];
                                    }
                                    else if (value == 1)
                                    {
                                        seriesName = config["RepresentationOfYes"];
                                    }
                                }
                                else
                                {
                                    independentValue = BuildIndependentValue(independentVariable, row, config);
                                }

                                if (string.IsNullOrEmpty(seriesName))
                                {
                                    seriesName = SilverlightStatics.COUNT;

                                    if (_independentVariableArray.Length > 1)
                                    {
                                        seriesName = independentVariable;
                                    }

                                    if (string.IsNullOrEmpty(_aggregateFunction) == false)
                                    {
                                        seriesName = _aggregateFunction;
                                    }
                                }

                                if (string.IsNullOrEmpty(_weightVar))
                                {
                                    //
                                    if (independentValue.ToString().ToUpperInvariant() == "TRUE")
                                    {
                                        independentValue = config["RepresentationOfYes"];
                                    }
                                    if (independentValue.ToString().ToUpperInvariant() == "FALSE")
                                    {
                                        independentValue = config["RepresentationOfNo"];
                                    }
                                    //
                                    double dependentVal;

                                    if (double.TryParse(row["__Count__"].ToString(), out dependentVal))
                                    {
                                        if ((_graphType == "EPICURVE" && independentValue is DateTime && ((DateTime)independentValue) <= _graphStartFrom) == false)
                                        {
                                            _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                        }
                                    }
                                }
                                else
                                {
                                    //
                                    if (independentValue.ToString().ToUpperInvariant() == "TRUE")
                                    {
                                        independentValue = config["RepresentationOfYes"];
                                    }
                                    if (independentValue.ToString().ToUpperInvariant() == "FALSE")
                                    {
                                        independentValue = config["RepresentationOfNo"];
                                    }
                                    //
                                    filter.independentVarValue = row["__Values__"];
                                    filter.independentVarName  = independentVariable;
                                    filter.weightVarName       = _weightVar;
                                    double dependentVal = GetAggregateValue(sourceTable, filter);
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                        }
                    }
                }

                string graphTitle = _graphTitle;

                if (sourceTable.Columns.Contains(filter.strataVarName))
                {
                    Type   _strataVarDataType = sourceTable.Columns[filter.strataVarName].DataType;
                    string strataVarText      = filter.strataVarValue;

                    strataVarText = GetPrintValue(filter.strataVarName, _strataVarDataType.Name, filter.strataVarValue, config);

                    if (string.IsNullOrEmpty(_strataVar) == false)
                    {
                        graphTitle = string.Format("{0} {1}={2}", _graphTitle, filter.strataVarName, strataVarText);
                    }
                }

                DataView  view           = new DataView(_regressionTable);
                DataTable distinctValues = new DataTable();
                distinctValues = view.ToTable(true, "SeriesName");

                bool hideLegend = false;

                if (distinctValues.Rows.Count == 1 && distinctValues.Rows[0][0].ToString() == "COUNT")
                {
                    hideLegend = true;
                }

                objectElement = objectElement
                                + silverlight.Graph
                                (
                    _graphType,
                    graphTitle,
                    _graphIndependentAxisLabel,
                    _graphDependentAxisLabel,
                    "",
                    "",
                    _graphInterval,
                    _graphIntervalUnits,
                    _graphStartFrom,
                    _regressionTable,
                    hideLegend
                                );

                _regressionTable.Rows.Clear();
            }

            string data = string.Empty;

            if (objectElement != "")
            {
                data = objectElement + @"<hr/>";
            }
            else
            {
                data = SharedStrings.UNABLE_CREATE_GRAPH;
            }

            args.Add("COMMANDNAME", CommandNames.GRAPH);
            args.Add("DATA", data);
            args.Add("COMMANDTEXT", _commandText.Trim());
            Context.Display(args);
        }
コード例 #2
0
ファイル: Graph.cs プロジェクト: NALSS/epiinfo-82474
        public void Execute()
        {
            _regressionTable = new DataTable();
            _regressionTable.Columns.Add("SeriesName", typeof(string));
            _regressionTable.Columns.Add("Predictor", typeof(object));
            _regressionTable.Columns.Add("Response", typeof(double));

            Dictionary<string, string> config = Context.SetProperties;
            StringBuilder HTMLString = new StringBuilder();

            System.Data.DataTable sourceTable = BuildTempContextTable();
            cDataSetHelper dsHelper = new cDataSetHelper();

            Dictionary<string, string> args = new Dictionary<string, string>();

            string strataVarValue = string.Empty;
            string objectElement = string.Empty;

            SilverlightMarkup silverlight = new SilverlightMarkup();

            DataTable Strata_ValueList;

            if (string.IsNullOrEmpty(_strataVar))
            {
                Strata_ValueList = sourceTable.Clone();
                Strata_ValueList.Rows.Add(Strata_ValueList.NewRow());
            }
            else
            {
                Strata_ValueList = dsHelper.SelectDistinct("", sourceTable, _strataVar);
            }

            FilterStruct filter = new FilterStruct();
            filter.strataVarName = _strataVar;

            _independentValueTypesSame = true;
            if(_independentVariableArray.Length > 1)
            {
                for(int i = 0; (i + 1) < _independentVariableArray.Length ; i++)
                {
                    if (sourceTable.Columns[_independentVariableArray[i]].DataType != sourceTable.Columns[_independentVariableArray[i+1]].DataType )
                    {
                        _independentValueTypesSame = false;
                        break;
                    }
                }
            }

            _independentValuesAllBool = true;
            for (int i = 0; i < _independentVariableArray.Length; i++)
            {
                string indepVar = _independentVariableArray[i];

                if (sourceTable.Columns.Contains(indepVar))
                {
                    if (sourceTable.Columns[indepVar].DataType.Name != "Byte")
                    {
                        _independentValuesAllBool = false;
                        break;
                    }
                }
                else
                {
                    return;
                }
            }

            foreach (DataRow strataRow in Strata_ValueList.Rows)
            {
                if (string.IsNullOrEmpty(_strataVar) || strataRow[_strataVar] == DBNull.Value)
                {
                    filter.strataVarValue = "null";
                }
                else
                {
                    filter.strataVarValue = strataRow[_strataVar].ToString();
                }

                if (_graphType == SilverlightStatics.Scatter)
                {
                    if (_independentVariableArray.Length < 2)
                    {
                        throw new Exception("Scatter graphs must contain two (2) main variables.");
                    }

                    string categoryName = string.Empty;
                    Dictionary<object, double> indDepValuePairCollection = new Dictionary<object, double>();

                    List<string> StrataVarNameList = new List<string>();
                    List<string> StrataVarValueList = new List<string>();

                    string regressor = _independentVariableArray[0];
                    string regressand = _independentVariableArray[1];

                    StrataVarNameList.Add(filter.strataVarName);
                    StrataVarValueList.Add(filter.strataVarValue);

                    DataTable table = new DataTable();
                    table.Columns.Add(new DataColumn(sourceTable.Columns[regressor].ColumnName, sourceTable.Columns[regressor].DataType));
                    table.Columns.Add(new DataColumn(sourceTable.Columns[regressand].ColumnName, sourceTable.Columns[regressand].DataType));

                    foreach (DataRow row in sourceTable.Rows)
                    {
                        table.Rows.Add(row[regressor], row[regressand]);
                    }

                    foreach (DataRow row in table.Rows)
                    {
                        if (row[regressor] != DBNull.Value)
                        {
                            string seriesName = string.Empty;
                            object independentValue = new object();

                            if (_independentValuesAllBool)
                            {
                                independentValue = regressor;
                                byte value = (byte)(row[regressor]);
                            }
                            else
                            {
                                independentValue = GetValue(regressor, row, config);
                            }

                            seriesName = string.Format("{0} x {1}", sourceTable.Columns[regressor].ColumnName, sourceTable.Columns[regressand].ColumnName);

                            if (string.IsNullOrEmpty(_weightVar))
                            {
                                double dependentVal;

                                if (double.TryParse(row[regressand].ToString(), out dependentVal))
                                {
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                            else
                            {
                                filter.independentVarValue = row[regressor];
                                filter.independentVarName = regressor;
                                filter.weightVarName = _weightVar;
                                double dependentVal = GetAggregateValue(sourceTable, filter);

                                _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                            }
                        }
                    }
                }
                else if (sourceTable.Columns.Contains(_graphCrossTab))
                {
                    string categoryName = string.Empty;
                    Dictionary<object, double> indDepValuePairCollection = new Dictionary<object, double>();

                    List<string> StrataVarNameList = new List<string>();
                    List<string> StrataVarValueList = new List<string>();

                    foreach (string independentVariableName in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariableName,
                            _graphCrossTab,
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        foreach (DataColumn crossTabCandidate in workingTable.Columns)
                        {
                            if (crossTabCandidate.ColumnName != "__Values__" && crossTabCandidate.ColumnName != "__Count__")
                            {
                                Type crossTabDataType = sourceTable.Columns[_graphCrossTab].DataType;

                                string crossTabValue = crossTabCandidate.ColumnName;

                                if (crossTabDataType.Name == "Byte")
                                {
                                    if (crossTabCandidate.ColumnName == "0")
                                    {
                                        crossTabValue = config["RepresentationOfNo"];
                                    }
                                    else if (crossTabCandidate.ColumnName == "1")
                                    {
                                        crossTabValue = config["RepresentationOfYes"];
                                    }
                                }

                                string seriesName = string.Format("{0}={1}", _graphCrossTab, crossTabValue);

                                foreach (DataRow row in workingTable.Rows)
                                {
                                    double dependentVal;

                                    if (double.TryParse(row[crossTabCandidate.ColumnName].ToString(), out dependentVal))
                                    {
                                        if (row["__Values__"] != DBNull.Value)
                                        {
                                            string independentVariableTypeName = string.Empty;

                                            if (sourceTable.Columns.Contains(independentVariableName))
                                            {
                                                independentVariableTypeName = sourceTable.Columns[independentVariableName].DataType.Name;
                                            }

                                            categoryName = BuildCategoryName(independentVariableName, independentVariableTypeName, row, config);

                                            object independentValue = row["__Values__"];

                                            if (string.IsNullOrEmpty(_weightVar))
                                            {
                                                if (double.TryParse(row[crossTabCandidate.ColumnName].ToString(), out dependentVal))
                                                {
                                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                                }
                                            }
                                            else
                                            {
                                                object independentVariableValue = row["__Values__"];

                                                bool isValue = false;

                                                if (independentVariableValue != null)
                                                {
                                                    isValue = true;

                                                    if (independentVariableValue is string)
                                                    {
                                                        string candidate = ((string)independentVariableValue).Trim();
                                                        isValue = candidate != string.Empty;
                                                    }
                                                }

                                                if (isValue)
                                                {
                                                    filter.crossTabName = _graphCrossTab;
                                                    filter.crossTabValue = crossTabCandidate.ColumnName;
                                                    filter.independentVarName = independentVariableName;
                                                    filter.independentVarValue = independentVariableValue;
                                                    filter.weightVarName = _weightVar;
                                                    dependentVal = GetAggregateValue(sourceTable, filter);
                                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else if (_graphType == "EPICURVE" && _graphIntervalUnits != "")
                {
                    string categoryName = string.Empty;
                    Dictionary<object, double> indDepValuePairCollection = new Dictionary<object, double>();

                    List<string> StrataVarNameList = new List<string>();
                    List<string> StrataVarValueList = new List<string>();

                    foreach (string independentVariable in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariable,
                            "",
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        DateTime intervalStart = DateTime.MinValue;
                        DateTime intervalEnd = DateTime.MinValue;
                        DateTime dateTimeValue = DateTime.MinValue;
                        intervalStart = _graphStartFrom;

                        double givenInterval = 1;
                        int days = 0, hours = 0, minutes = 0, seconds = 0;
                        TimeSpan period = new TimeSpan(days, hours, minutes, seconds);

                        if (_graphInterval != "")
                        {
                            double.TryParse(_graphInterval, out givenInterval);
                        }

                        if (_graphIntervalUnits == "")
                        {
                            _graphIntervalUnits = "Hours";
                        }

                        foreach (DataRow row in workingTable.Rows)
                        {
                            if (row["__Values__"] != DBNull.Value)
                            {
                                dateTimeValue = (DateTime)row["__Values__"];

                                //if (intervalStart == DateTime.MinValue)
                                //{
                                //    intervalStart = dateTimeValue;
                                //    _graphStartFrom = dateTimeValue;
                                //}

                                while ( dateTimeValue >= intervalEnd)
                                {
                                    if (intervalEnd != DateTime.MinValue)
                                    {
                                        intervalStart = intervalEnd;
                                    }

                                    switch (_graphIntervalUnits)
                                    {
                                        case "Years":
                                            intervalEnd = intervalStart.AddYears((int)givenInterval);
                                            break;
                                        case "Quarters":
                                            intervalEnd = intervalStart.AddDays(givenInterval * 365.25 / 4.0);
                                            break;
                                        case "Weeks":
                                            intervalEnd = intervalStart.AddDays(givenInterval * 7);
                                            break;
                                        case "Days":
                                            intervalEnd = intervalStart.AddDays(givenInterval);
                                            break;
                                        case "Hours":
                                            intervalEnd = intervalStart.AddHours(givenInterval);
                                            break;
                                        case "Minutes":
                                            intervalEnd = intervalStart.AddMinutes(givenInterval);
                                            break;
                                        case "Seconds":
                                            intervalEnd = intervalStart.AddSeconds(givenInterval);
                                            break;
                                    }
                                }

                                string seriesName = string.Empty;
                                object independentValue = new object();

                                independentValue = BuildIndependentValue(independentVariable, row, config);

                                if (string.IsNullOrEmpty(seriesName))
                                {
                                    seriesName = SilverlightStatics.COUNT;

                                    if (_independentVariableArray.Length > 1)
                                    {
                                        seriesName = independentVariable;
                                    }

                                    if(string.IsNullOrEmpty(_aggregateFunction) == false)
                                    {
                                        seriesName = _aggregateFunction;
                                    }
                                }

                                if (string.IsNullOrEmpty(_weightVar))
                                {
                                    double dependentVal;

                                    if (double.TryParse(row["__Count__"].ToString(), out dependentVal))
                                    {
                                        if ((dateTimeValue >= intervalStart) && (dateTimeValue < intervalEnd))
                                        {
                                            string expression = "Predictor = #" + intervalStart.ToString() + "#";
                                            DataRow[] foundRows = _regressionTable.Select(expression);

                                            if (foundRows.Length == 0)
                                            {
                                                _regressionTable.Rows.Add(seriesName, intervalStart, dependentVal);
                                            }
                                            else
                                            {
                                                foundRows[0]["Response"] = (double)foundRows[0]["Response"] + dependentVal;
                                                _regressionTable.AcceptChanges();
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    filter.independentVarValue = row["__Values__"];
                                    filter.independentVarName = independentVariable;
                                    filter.weightVarName = _weightVar;
                                    double dependentVal = GetAggregateValue(sourceTable, filter);
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                        }
                    }
                }
                else
                {
                    string categoryName = string.Empty;
                    Dictionary<object, double> indDepValuePairCollection = new Dictionary<object, double>();

                    List<string> StrataVarNameList = new List<string>();
                    List<string> StrataVarValueList = new List<string>();

                    foreach (string independentVariable in _independentVariableArray)
                    {
                        StrataVarNameList.Add(filter.strataVarName);
                        StrataVarValueList.Add(filter.strataVarValue);

                        DataTable workingTable = cWorkingTable.CreateWorkingTable(
                            independentVariable,
                            "",
                            config,
                            sourceTable,
                            StrataVarNameList,
                            StrataVarValueList,
                            _weightVar);

                        foreach (DataRow row in workingTable.Rows)
                        {
                            if (row["__Values__"] != DBNull.Value)
                            {
                                string seriesName = string.Empty;
                                object independentValue = new object();

                                if (!_independentValueTypesSame || _graphType == SilverlightStatics.Pie )
                                {
                                    independentValue = BuildIndependentValue(independentVariable, row, config);
                                }
                                else if (_independentValuesAllBool)
                                {
                                    independentValue = independentVariable;
                                    byte value = (byte)(row["__Values__"]);

                                    seriesName = row["__Values__"].ToString();

                                    if (value == 0)
                                    {
                                        seriesName = config["RepresentationOfNo"];
                                    }
                                    else if (value == 1)
                                    {
                                        seriesName = config["RepresentationOfYes"];
                                    }
                                }
                                else
                                {
                                    independentValue = BuildIndependentValue(independentVariable, row, config);
                                }

                                if (string.IsNullOrEmpty(seriesName))
                                {
                                    seriesName = SilverlightStatics.COUNT;

                                    if (_independentVariableArray.Length > 1)
                                    {
                                        seriesName = independentVariable;
                                    }

                                    if(string.IsNullOrEmpty(_aggregateFunction) == false)
                                    {
                                        seriesName = _aggregateFunction;
                                    }
                                }

                                if (string.IsNullOrEmpty(_weightVar))
                                {
                                    //
                                    if (independentValue.ToString().ToUpper() == "TRUE")
                                    {
                                        independentValue = config["RepresentationOfYes"];
                                    }
                                    if (independentValue.ToString().ToUpper() == "FALSE")
                                    {

                                        independentValue = config["RepresentationOfNo"];
                                    }
                                    //
                                    double dependentVal;

                                    if (double.TryParse(row["__Count__"].ToString(), out dependentVal))
                                    {
                                        if ((_graphType == "EPICURVE" && independentValue is DateTime && ((DateTime)independentValue) <= _graphStartFrom) == false)
                                        {
                                            _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                        }
                                    }
                                }
                                else
                                {
                                    //
                                    if (independentValue.ToString().ToUpper() == "TRUE")
                                    {
                                        independentValue = config["RepresentationOfYes"];
                                    }
                                    if (independentValue.ToString().ToUpper() == "FALSE")
                                    {

                                        independentValue = config["RepresentationOfNo"];
                                    }
                                    //
                                    filter.independentVarValue = row["__Values__"];
                                    filter.independentVarName = independentVariable;
                                    filter.weightVarName = _weightVar;
                                    double dependentVal = GetAggregateValue(sourceTable, filter);
                                    _regressionTable.Rows.Add(seriesName, independentValue, dependentVal);
                                }
                            }
                        }
                    }
                }

                string graphTitle = _graphTitle;

                if (sourceTable.Columns.Contains(filter.strataVarName))
                {
                    Type _strataVarDataType = sourceTable.Columns[filter.strataVarName].DataType;
                    string strataVarText = filter.strataVarValue;

                    strataVarText = GetPrintValue(filter.strataVarName, _strataVarDataType.Name, filter.strataVarValue, config);

                    if (string.IsNullOrEmpty(_strataVar) == false)
                    {
                        graphTitle = string.Format("{0} {1}={2}", _graphTitle, filter.strataVarName, strataVarText);
                    }
                }

                DataView view = new DataView(_regressionTable);
                DataTable distinctValues = new DataTable();
                distinctValues = view.ToTable(true, "SeriesName");

                bool hideLegend = false;

                if (distinctValues.Rows.Count == 1 && distinctValues.Rows[0][0].ToString() == "COUNT")
                {
                    hideLegend = true;
                }

                objectElement = objectElement
                    + silverlight.Graph
                    (
                        _graphType,
                        graphTitle,
                        _graphIndependentAxisLabel,
                        _graphDependentAxisLabel,
                        "",
                        "",
                        _graphInterval,
                        _graphIntervalUnits,
                        _graphStartFrom,
                        _regressionTable,
                        hideLegend
                    );

                _regressionTable.Rows.Clear();
            }

            string data = string.Empty;

            if (objectElement != "")
            {
                data = objectElement + @"<hr/>";
            }
            else
            {
                data = SharedStrings.UNABLE_CREATE_GRAPH;
            }

            args.Add("COMMANDNAME", CommandNames.GRAPH);
            args.Add("DATA", data);
            args.Add("COMMANDTEXT", _commandText.Trim());
            Context.Display(args);
        }