Ejemplo n.º 1
0
        private TwoxTwoTableDTO CreateDTO(GadgetParameters gp, DashboardHelper dh, DataTable table)
        {
            int YesRowIndexExp = 1;
            int NoRowIndexExp  = 0;
            int YesRowIndexOut = 1;
            int NoRowIndexOut  = 2;

            if (dh.GetColumnType(gp.MainVariableName.ToString()).ToLower() != "system.string")
            {
                YesRowIndexExp = FindYesRowIndex(table);

                NoRowIndexExp = FindNoRowIndex(table);
            }


            if (dh.GetColumnType(gp.CrosstabVariableName.ToString()).ToLower() != "system.string")
            {
                YesRowIndexOut = FindYesColIndex(table);

                NoRowIndexOut = FindNoColIndex(table);
            }

            TwoxTwoTableDTO ttDTO = new TwoxTwoTableDTO
            {
                Yy = int.Parse(table.Rows[YesRowIndexExp][YesRowIndexOut].ToString()),
                Yn = int.Parse(table.Rows[YesRowIndexExp][NoRowIndexOut].ToString()),
                Ny = int.Parse(table.Rows[NoRowIndexExp][YesRowIndexOut].ToString()),
                Nn = int.Parse(table.Rows[NoRowIndexExp][NoRowIndexOut].ToString())
            };

            //Yy = int.Parse(table.Rows[1][1].ToString()),
            //               Yn = int.Parse(table.Rows[1][2].ToString()),
            //               Ny = int.Parse(table.Rows[0][1].ToString()),
            //               Nn = int.Parse(table.Rows[0][2].ToString())
            //ttDTO.Rows[0, 1] = int.Parse(table.Rows[0][1].ToString());
            //ttDTO.Rows[0, 2] = int.Parse(table.Rows[0][2].ToString());
            //ttDTO.Rows[1, 1] = int.Parse(table.Rows[1][1].ToString());
            //ttDTO.Rows[1, 2] = int.Parse(table.Rows[1][2].ToString());



            ttDTO.ColumnName1 = table.Columns[1].ColumnName;
            ttDTO.ColumnName2 = table.Columns[2].ColumnName;

            return(ttDTO);
        }
Ejemplo n.º 2
0
        //void Swap2x2RowValues(DataTable table)
        //{
        //    if (table.Rows.Count > 2 || table.Columns.Count > 3)
        //    {
        //        return; // cannot do an invalid 2x2 table
        //    }

        //    object row1Col1 = table.Rows[0][1];
        //    object row1Col2 = table.Rows[0][2];

        //    object row2Col1 = table.Rows[1][1];
        //    object row2Col2 = table.Rows[1][2];

        //    table.Rows[0][1] = row2Col1;
        //    table.Rows[0][2] = row2Col2;

        //    table.Rows[1][1] = row1Col1;
        //    table.Rows[1][2] = row1Col2;

        //    object firstRowName = table.Rows[0][0];
        //    table.Rows[0][0] = table.Rows[1][0];
        //    table.Rows[1][0] = firstRowName;
        //}

        //void Swap2x2ColValues(DataTable table)
        //{
        //    if (table.Rows.Count > 2 || table.Columns.Count > 3)
        //    {
        //        return; // cannot do an invalid 2x2 table
        //    }

        //    object row1Col1 = table.Rows[0][1];
        //    object row1Col2 = table.Rows[0][2];

        //    object row2Col1 = table.Rows[1][1];
        //    object row2Col2 = table.Rows[1][2];

        //    table.Rows[0][1] = row1Col2;
        //    table.Rows[0][2] = row1Col1;

        //    table.Rows[1][1] = row2Col2;
        //    table.Rows[1][2] = row2Col1;

        //    string firstColumnName = table.Columns[1].ColumnName;
        //    string secondColumnName = table.Columns[2].ColumnName;

        //    table.Columns[1].ColumnName = "_COL1_";
        //    table.Columns[2].ColumnName = "_COL2_";

        //    table.Columns[1].ColumnName = secondColumnName;
        //    table.Columns[2].ColumnName = firstColumnName;
        //}

        private TwoxTwoAndMxNResultsSet Setup2x2(GadgetParameters gadgetOptions, TwoxTwoAndMxNResultsSet resultSet)
        {
            GridCells gridCells = new GridCells();

            TwoxTwoTableDTO table = resultSet.TwoxTwoTableDTO;

            DataTable dt = resultSet.FreqResultsDataTable;

            if (table != null)  //      && table.Rows.Length != 0)
            {
                //if (gadgetOptions.InputVariableList.ContainsKey("smarttable") && gadgetOptions.InputVariableList["smarttable"].Equals("true"))
                //{
                //    CheckLabels(table);
                //}


                gridCells.yyVal = Convert.ToInt32(dt.Rows[0][1].ToString()); //table.Yy;
                gridCells.ynVal = Convert.ToInt32(dt.Rows[0][2].ToString()); //table.Yn;
                gridCells.nyVal = Convert.ToInt32(dt.Rows[1][1].ToString()); //table.Ny;
                gridCells.nnVal = Convert.ToInt32(dt.Rows[1][2].ToString()); //table.Nn;

                gridCells.ntVal = gridCells.nnVal + gridCells.nyVal;
                gridCells.ytVal = gridCells.yyVal + gridCells.ynVal;

                gridCells.ttVal = gridCells.ytVal + gridCells.ntVal;
                gridCells.tyVal = gridCells.yyVal + gridCells.nyVal;
                gridCells.tnVal = gridCells.ynVal + gridCells.nnVal;
                if (gridCells.ytVal != 0)
                {
                    gridCells.yyRowPct = 1.0 * gridCells.yyVal / gridCells.ytVal;
                    gridCells.ynRowPct = 1.0 * gridCells.ynVal / gridCells.ytVal;
                }
                if (gridCells.ntVal != 0)
                {
                    gridCells.nyRowPct = 1.0 * gridCells.nyVal / gridCells.ntVal;
                    gridCells.nnRowPct = 1.0 * gridCells.nnVal / gridCells.ntVal;
                }
                if (gridCells.tyVal != 0)
                {
                    gridCells.yyColPct = 1.0 * gridCells.yyVal / gridCells.tyVal;
                    gridCells.nyColPct = 1.0 * gridCells.nyVal / gridCells.tyVal;
                }
                if (gridCells.tnVal != 0)
                {
                    gridCells.ynColPct = 1.0 * gridCells.ynVal / gridCells.tnVal;
                    gridCells.nnColPct = 1.0 * gridCells.nnVal / gridCells.tnVal;
                }
                if (gridCells.ttVal != 0)
                {
                    gridCells.tyRowPct = 1.0 * gridCells.tyVal / gridCells.ttVal;
                    gridCells.tnRowPct = 1.0 * gridCells.tnVal / gridCells.ttVal;
                    gridCells.ytColPct = 1.0 * gridCells.ytVal / gridCells.ttVal;
                    gridCells.ntColPct = 1.0 * gridCells.ntVal / gridCells.ttVal;
                }
                if (gridCells.tyVal > 0 && gridCells.tnVal > 0 && gridCells.ytVal > 0 && gridCells.ntVal > 0)
                {
                    //gridCells.singleTableResults = new StatisticsRepository.cTable().SigTable(
                    //    (double)gridCells.yyVal, (double)gridCells.ynVal,
                    //    (double)gridCells.nyVal, (double)gridCells.nnVal, 0.95);
                    StatisticsRepository.cTable.SingleTableResults stab = new StatisticsRepository.cTable().SigTable(
                        (double)gridCells.yyVal, (double)gridCells.ynVal,
                        (double)gridCells.nyVal, (double)gridCells.nnVal, 0.95);

                    //gridCells.singleTableResults = new MySingleTableResults()
                    //{
                    //     ChiSquareMantel2P =  stab.ChiSquareMantel2P,
                    //      ChiSquareUncorrected2P = stab.ChiSquareUncorrected2P,
                    //       ChiSquareMantelVal = stab.ChiSquareMantel2P

                    //}

                    gridCells.singleTableResults = new MySingleTableResults()
                    {
                        ChiSquareMantel2P       = stab.ChiSquareMantel2P,
                        ChiSquareMantelVal      = stab.ChiSquareMantelVal,
                        ChiSquareUncorrected2P  = stab.ChiSquareUncorrected2P,
                        ChiSquareUncorrectedVal = stab.ChiSquareUncorrectedVal,
                        ChiSquareYates2P        = stab.ChiSquareYates2P,
                        ChiSquareYatesVal       = stab.ChiSquareYatesVal,
                        ErrorMessage            = stab.ErrorMessage,
                        FisherExact2P           = stab.FisherExact2P,
                        FisherExactP            = stab.FisherExactP,
                        MidP = stab.MidP,
                        OddsRatioEstimate       = stab.OddsRatioEstimate,
                        OddsRatioLower          = stab.OddsRatioLower,
                        OddsRatioMLEEstimate    = stab.OddsRatioMLEEstimate,
                        OddsRatioMLEFisherLower = stab.OddsRatioMLEFisherLower,
                        OddsRatioMLEFisherUpper = stab.OddsRatioMLEFisherUpper,
                        OddsRatioMLEMidPLower   = stab.OddsRatioMLEMidPLower,
                        OddsRatioMLEMidPUpper   = stab.OddsRatioMLEMidPUpper,
                        OddsRatioUpper          = stab.OddsRatioUpper,
                        RiskDifferenceEstimate  = stab.RiskDifferenceEstimate,
                        RiskDifferenceLower     = stab.RiskDifferenceLower,
                        RiskDifferenceUpper     = stab.RiskDifferenceUpper,
                        RiskRatioEstimate       = stab.RiskRatioEstimate,
                        RiskRatioLower          = stab.RiskRatioLower,
                        RiskRatioUpper          = stab.RiskRatioUpper
                    };
                }
            }

            if (gridCells.singleTableResults != null && !string.IsNullOrEmpty(gridCells.singleTableResults.ErrorMessage))
            {
                //this.Dispatcher.BeginInvoke(new SimpleCallback(ClearSingleResults));
                //this.Dispatcher.BeginInvoke(new ShowErrorMessage(ShowError), gridCells.singleTableResults.ErrorMessage);
                //  this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), gridCells.singleTableResults.ErrorMessage);
                //      RenderFinishWithError(gridCells.singleTableResults.ErrorMessage);
                //   resultSet.AddError(thisStringLiterals.RenderFinishWithError, gridCells.singleTableResults.ErrorMessage);
                //stopwatch.Stop();
                //Debug.Print("2x2 table gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + dashboardHelper.RecordCount.ToString() + " records and the following filters:");
                //Debug.Print(dashboardHelper.DataFilters.GenerateDataFilterString());
            }
            else
            {
                //    RenderGridCells(gridCells, table);
                //    RenderFinish();
                resultSet.GridCells = gridCells;
            }

            return(resultSet);
        }
Ejemplo n.º 3
0
        public TwoxTwoAndMxNResultsSet EvaluateData(GadgetParameters clientGadgetOptions, List <EwavDataFilterCondition> ewavDataFilters, List <EwavRule_Base> rules)
        {
            TwoxTwoAndMxNResultsSet twoxTwoResultsSet = new TwoxTwoAndMxNResultsSet();
            bool exceededMaxColumns = false;

            twoxTwoResultsSet.exceededMaxColumns = exceededMaxColumns;

            try
            {
                GadgetParameters gadgetOptions = new GadgetParameters();
                gadgetOptions = Utilities.Clone <GadgetParameters>(clientGadgetOptions);
                gadgetOptions.ShouldIncludeFullSummaryStatistics = false;
                gadgetOptions.ShouldSortHighToLow        = false;
                gadgetOptions.ShouldUseAllPossibleValues = false;
                gadgetOptions.StrataVariableNames        = new List <string>();

                if (gadgetOptions.InputVariableList.ContainsKey("smarttable"))
                {
                    smartTable = Convert.ToBoolean(gadgetOptions.InputVariableList["smarttable"].ToString());
                }

                DashboardHelper dashboardHelper = new DashboardHelper(gadgetOptions, ewavDataFilters, rules);

                var candidateRules = rules.Where(rule => rule.VaraiableName == gadgetOptions.MainVariableName); // before push > deprecate the use of MainVariableName

                List <string> groupVariables = new List <string>();

                if (candidateRules.Count() > 0)
                {
                    var groupVariableCandidate = candidateRules.ToList()[0]; // before push > interate through list

                    if (groupVariableCandidate.VaraiableDataType == "GroupVariable")
                    {
                        groupVariables = ((EwavRule_GroupVariable)groupVariableCandidate).Items.Select(i => i.VarName).ToList();
                    }
                }

                List <string> allGroupFields = dashboardHelper.GetAllGroupsAsList();

                string firstColumnName = string.Empty;
                int    columnCount     = gadgetOptions.ColumnNames.Count;
                if (gadgetOptions.ColumnNames.Count() > 0)
                {
                    firstColumnName = gadgetOptions.ColumnNames[0].VarName;
                }

                Dictionary <DataTable, List <DescriptiveStatistics> > stratifiedFrequencyTables = new Dictionary <DataTable, List <DescriptiveStatistics> >();


                if (groupVariables.Count == 0)
                {
                    groupVariables.Add(gadgetOptions.MainVariableName);
                }

                gadgetOptions.MainVariableNames = new List <string>();

                Dictionary <DataTable, List <DescriptiveStatistics> > tableDictionary = new Dictionary <DataTable, List <DescriptiveStatistics> >();
                foreach (string groupVariableName in groupVariables)
                {
                    gadgetOptions.MainVariableNames.Add(groupVariableName);
                    gadgetOptions.MainVariableName = groupVariableName;

                    tableDictionary = dashboardHelper.GenerateFrequencyTable(gadgetOptions);

                    if (tableDictionary.Count > 0)
                    {
                        foreach (KeyValuePair <DataTable, List <DescriptiveStatistics> > kvp in tableDictionary)
                        {
                            stratifiedFrequencyTables.Add(kvp.Key, kvp.Value);
                        }

                        if (tableDictionary.Count > 0)
                        {
                            var table = tableDictionary.First().Key;

                            if (table.Rows.Count == 2 && table.Columns.Count == 3)
                            {
                                twoxTwoResultsSet.Is2x2 = true;
                            }
                            else
                            {
                                twoxTwoResultsSet.Is2x2 = false;
                            }
                        }
                    }
                }

                if (stratifiedFrequencyTables == null || stratifiedFrequencyTables.Count == 0)
                {
                    return(twoxTwoResultsSet);
                }
                else
                {
                    List <DescriptiveStatistics> statsList = new List <DescriptiveStatistics>();
                    DataTable table;

                    foreach (KeyValuePair <DataTable, List <DescriptiveStatistics> > tableKvp in stratifiedFrequencyTables)
                    {
                        statsList = tableKvp.Value;
                        table     = tableKvp.Key;

                        CreateSmartTable(table);

                        twoxTwoResultsSet.FreqResultsDataTable = table;

                        TwoxTwoTableDTO twoxTwoTableDTO = this.CreateDTO(gadgetOptions, dashboardHelper, table);
                        twoxTwoResultsSet.TwoxTwoTableDTO = twoxTwoTableDTO;
                        twoxTwoResultsSet = this.Setup2x2(clientGadgetOptions, twoxTwoResultsSet);

                        twoxTwoResultsSet.AddResult(table, gadgetOptions.CrosstabVariableName, statsList, twoxTwoResultsSet.GridCells);

                        double count = 0;
                        foreach (DescriptiveStatistics ds in tableKvp.Value)
                        {
                            count = count + ds.Observations;
                        }

                        if (count == 0 && stratifiedFrequencyTables.Count == 1)
                        {
                            return(twoxTwoResultsSet);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                twoxTwoResultsSet.Errors.Add(new MyString(ex.Message));
            }
            return(twoxTwoResultsSet);
        }
Ejemplo n.º 4
0
 //      public void PortThistoClient(StringLiterals sl) { }
 public void PortClassToClient4(TwoxTwoTableDTO gp)
 {
 }