Exemplo n.º 1
0
        public DescStats(DataTable dt, List <string> numericvars, List <string> groupingvars)
        {
            _numericvars  = numericvars;
            _groupingvars = groupingvars;
            _dt           = new DescStatsTable(_groupingvars);

            DataSubsets dataSubsets = new DataSubsets(dt, _numericvars, _groupingvars);

            foreach (DataSubset subset in dataSubsets.subsets)
            {
                //Loop through each var
                foreach (string v in _numericvars)
                {
                    DataRow datarow = GetRowOfStats(subset.dt, v);

                    //Assign the grouping vars to the row
                    foreach (ColumnValue colval in subset.cols_and_vals)
                    {
                        string colname  = colval.Colname;
                        string colvalue = colval.Colvalue;
                        datarow[colname] = colvalue;
                    }

                    _dt.Rows.Add(datarow);
                }
            }

            AddConstantCol();

            RemoveEmptyRows();

            Sort(_groupingvars);
        }
Exemplo n.º 2
0
        //Histogram
        public DxChartBatch(DxHistogramSettings mysettings, DataTable dt)
        {
            Initialize();
            _batchsettings = (DxChartSettings)mysettings;
            outputtype     = DxOutputtype.Histogram;
            layout         = mysettings.chartlayout;
            _vars          = mysettings.numvars;
            if (mysettings.agevars != null)
            {
                _vars.AddRange(mysettings.agevars);
            }

            mysettings.numvars.Remove("id");


            if (mysettings.panelvar == "none")
            {
                foreach (string v in _vars)
                {
                    mysettings.xaxisvar = v;
                    DxChart chart = new DxHistogram(mysettings, dt, v, 0);
                    charts.Add(chart);
                }
            }
            else              //Yes panels
            {
                List <string> varnames = new List <string>();
                varnames.AddRange(_vars);
                varnames.Add(mysettings.xaxisvar);
                varnames.Add(mysettings.colorvar);
                varnames.RemoveAll(item => item == "variable");
                varnames.RemoveAll(item => item == "none");


                DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                    mysettings.panelvar
                });

                foreach (DataSubset subset in subsets.subsets)
                {
                    foreach (string v in mysettings.numvars)
                    {
                        _batchsettings.xaxisvar = v;
                        DxChart chart = new DxHistogram(mysettings, subset.dt, v, 0);
                        chart.AddTitles(subset.Cols_and_Vals_ToString());
                        charts.Add(chart);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public DxHistogram(DxHistogramSettings settings, DataTable mydt, string var, int colorindex)
        {
            _settings = settings;

            //Based on the settings create the histogram
            if (_settings.colorvar != "none")
            {
                DataSubsets subsets = new DataSubsets(mydt, new List <string> {
                    var
                }, new List <string> {
                    _settings.colorvar
                });

                CreateHistogram_withPanes(subsets.subsets, "", var);
            }
            else
            {
                //subtitle is empty string by default
                CreateHistogram(mydt);                 //, "", var, dxcharts.color(colorindex), dxcharts.numbins, dxcharts.histIsRotated);
            }
        }
Exemplo n.º 4
0
        public List_O_PCA(DPData dpdata, List <string> numvars, string method, string groupingvar)
        {
            _pcas = new List <PCA>();
            DataSubsets subsets = new DataSubsets(dpdata.dt, numvars, groupingvar);

            foreach (DataSubset subset in subsets.subsets)
            {
                if (subset.dt != null)
                {
                    if (subset.dt.Rows.Count > 0)
                    {
                        DataTable mydt = dpdata.Data_SelectColumns(subset.dt, numvars, false, true);
                        if (mydt != null)
                        {
                            PCA pca = new PCA(mydt, numvars, method, subset.Cols_and_Vals_ToString());
                            if (pca.final_N > 0)
                            {
                                _pcas.Add(pca);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        //Scatterplot
        public DxChartBatch(DxScatterplotSettings mysettings, DataTable dt)
        {
            Initialize();

            _batchsettings = (DxChartSettings)mysettings;

            outputtype = DxOutputtype.Scatterplot;
            layout     = mysettings.chartlayout;

            _vars = mysettings.analysisvars();


            //Define the sets of scatterplots to create.



            //// **** NO REPEATED MEASURES ****
            ////Square matrix
            //if (mysettings.repeatedmeasVarname == "none" & mysettings.analysisvarsX() == mysettings.analysisvarsY())
            //{
            //	XYpairs pairs = new XYpairs(mysettings.analysisvarsX()); //, mysettings.colors[0]);

            //	foreach (XYpair pair in pairs.pairs)
            //	{
            //		DxChart chart = new DxScatterplot(mysettings, dt, pair);
            //		if(chart.n > 1) charts.Add(chart);
            //	}
            //}
            ////Rectangle matrix
            //else if (mysettings.repeatedmeasVarname == "none" & mysettings.analysisvarsX() != mysettings.analysisvarsY())
            //{
            //	XYpairs pairs = new XYpairs(mysettings.analysisvarsX(), mysettings.analysisvarsY()); //, mysettings.colors[0]);

            //	if(mysettings.chartlayout == DxLayout.Horizontal)
            //	{
            //		mysettings.chartlayout = DxLayout.Vertical;
            //		mysettings.maxRow = mysettings.analysisvarsY().Count;
            //	}
            //	else if (mysettings.chartlayout == DxLayout.Vertical)
            //	{
            //		mysettings.chartlayout = DxLayout.Horizontal;
            //		mysettings.maxCol = mysettings.analysisvarsX().Count;
            //	}

            //	foreach (XYpair pair in pairs.pairs)
            //	{
            //		DxChart chart = new DxScatterplot(mysettings, dt, pair);
            //		if (chart.n > 1) charts.Add(chart);
            //	}
            //}
            //// **** YES REPEATED MEASURES ****
            //else
            if (true)
            {
                //List<string> repeatedmeas_levels = mysettings.rptmeasLevels(dt); //.AsEnumerable().Select(f => f.Field<string>(mysettings.repeatedmeasVarname)).Distinct().ToList();
                //List<string> analysisvars = mysettings.analysisvars();
                List <string> idvars = new List <string> {
                    "id"
                };

                if (mysettings.colorvar != "none")
                {
                    idvars.Add(mysettings.colorvar);
                }
                if (mysettings.panelvar != "none")
                {
                    idvars.Add(mysettings.panelvar);
                }

                idvars.Remove(mysettings.repeatedmeasVarname);



                List <string> keepvars = new List <string>();
                if (mysettings.repeatedmeasVarname != "none")
                {
                    keepvars.Add(mysettings.repeatedmeasVarname);
                }
                keepvars.AddRange(mysettings.analysisvars());
                keepvars.AddRange(idvars);

                DataTable dtwide;
                if (mysettings.repeatedmeasVarname != "none")
                {
                    // Widen the data using the repeated measure value
                    DataSubsets subsets = new DataSubsets(dt, keepvars, new List <string> {
                        mysettings.repeatedmeasVarname
                    });
                    dtwide = subsets.FullOuterJoinDataTables(idvars);
                }
                else
                {
                    dtwide = dt.Copy();
                }
                List <string> colnames = dtwide.ColumnNames();

                XYpairs pairs = new XYpairs(mysettings.analysisvars(), mysettings.rptmeasLevels(dt), mysettings.current_xypairtype);

                //pairs.RemoveInverse();

                foreach (XYpair pair in pairs.pairs)
                {
                    DxChart chart = new DxScatterplot(mysettings, dtwide, pair);
                    if (chart.n > 1)
                    {
                        charts.Add(chart);
                    }
                    //new RowColIndex( )
                    //chart.rowcolIndex(new
                }
            }
        }
Exemplo n.º 6
0
        public void ProcessOrder(DxChartOrder order)
        {
            if (order.isOrderFilled)             //Already have batches
            {
                order.batches.Clear();
            }

            //Skip the_dpdata stuff if _dt is already populated
            if (_dt == null)
            {
                bool hassameworksheet = order.HasSameWorksheet(_dpdata);

                if (!hassameworksheet)
                {
                    //Need new DPData
                    _dataproject.selectedsheet = order.worksheet;
                    _dpdata = new DPData(_dataproject, order.filter);
                }


                bool hassamefilter = order.HasSameFilter(_dpdata);

                if (!hassamefilter)
                {
                    _dpdata.filter = order.filter;
                }

                _dt = _dpdata.dt;
            }

            //Each order will result in a list of batches
            //List<DxBatchOcharts> batchlist = new List<DxBatchOcharts>();
            List <DxChartBatch> batchlist = new List <DxChartBatch>();

            if (order.list_settings != null)
            {
                foreach (DxChartSettings settings in order.list_settings)
                {
                    #region Histogram
                    if (settings.outputtype == DxOutputtype.Histogram)
                    {
                        DxHistogramSettings mysettings = (DxHistogramSettings)settings;
                        DxChartBatch        batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Barchart
                    else if (settings.outputtype == DxOutputtype.Barchart)
                    {
                        DxBarchartSettings mysettings = (DxBarchartSettings)settings;
                        DxChartBatch       batch      = new DxChartBatch(mysettings, dt);
                        PrepareBatch(batch, settings);
                        batchlist.Add(batch);
                    }
                    #endregion

                    #region Scatterplot
                    else if (settings.outputtype == DxOutputtype.Scatterplot)
                    {
                        DxScatterplotSettings mysettings = (DxScatterplotSettings)settings;

                        if (mysettings.repeatedmeasVarname == "none")
                        {
                            //DxChartBatch batch = new DxChartBatch(mysettings, dt);
                            //PrepareBatch(batch, settings);
                            //batchlist.Add(batch);

                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }
                            }
                        }
                        else if (mysettings.repeatedmeasVarname != "none")
                        {
                            List <string> repeatedmeas_levels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                            List <string> analysisvars = new List <string>();
                            analysisvars.AddRange(mysettings.numvars);
                            if (mysettings.agevars != null)
                            {
                                analysisvars.AddRange(mysettings.agevars);
                            }

                            int n_rptmeas      = repeatedmeas_levels.Count;
                            int n_analysisvars = analysisvars.Count;

                            int ncol1 = utilStats.TriangleNumber(n_rptmeas);


                            List <string> tmpvars  = mysettings.analysisvars();
                            List <string> tmpvarsX = mysettings.analysisvarsX();
                            List <string> tmpvarsY = mysettings.analysisvarsY();


                            #region Process By Mode
                            foreach (XYpairType mode in mysettings.xypairtypes)
                            {
                                if (mode == XYpairType.AllVars_IgnoreLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.maxCol = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout         = DxLayout.Horizontal;
                                    mysettings.repeatedmeasVarname = "none";

                                    DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                    PrepareBatch(batch1, (DxChartSettings)mysettings);
                                    batch1.batchtitle = String.Format("All variables (IGNORE Time/RptMeas)");
                                    batch1.maxCol     = batch1.charts.Count;
                                    batchlist.Add(batch1);
                                }

                                if (mode == XYpairType.SameVar_AcrossLevelsOfRptMeas)
                                {
                                    mysettings.current_xypairtype = mode;
                                    mysettings.maxCol             = ncol1;
                                    //mysettings.maxRow = tmpvars.Count;
                                    mysettings.chartlayout = DxLayout.Horizontal;

                                    //Loop over vars, make a batch for each one
                                    foreach (string v in tmpvars)
                                    {
                                        mysettings.manualXandYvars = true;
                                        mysettings.xvars           = new List <string> {
                                            v
                                        };
                                        mysettings.yvars = new List <string> {
                                            v
                                        };
                                        DxChartBatch batch1 = new DxChartBatch(mysettings, dt);
                                        PrepareBatch(batch1, (DxChartSettings)mysettings);
                                        batch1.batchtitle = String.Format("{0} ACROSS levels of {1}", v, mysettings.repeatedmeasVarname);
                                        batch1.maxCol     = batch1.charts.Count;
                                        batchlist.Add(batch1);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_WithinLevelsOfRptMeas)
                                {
                                    //#2 - treat it as square
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars = null;
                                    mysettings.yvars = null;

                                    mysettings.chartlayout = DxLayout.Upper;
                                    mysettings.maxRow      = tmpvars.Count;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname)).Distinct().ToList();

                                    List <string> tmpvars_with_id = new List <string>();
                                    tmpvars_with_id.AddRange(tmpvars);
                                    tmpvars_with_id.Add("id");

                                    DataSubsets dt_rptmeas = new DataSubsets(dt, tmpvars_with_id, mysettings.repeatedmeasVarname);

                                    //Loop across levels of the RptMeas
                                    foreach (DataSubset subset in dt_rptmeas.subsets)
                                    {
                                        DxChartBatch batch2 = new DxChartBatch(mysettings, subset.dt);
                                        PrepareBatch(batch2, (DxChartSettings)mysettings);
                                        batch2.batchtitle = String.Format("Variables WITHIN {0}: {1}", mysettings.repeatedmeasVarname, subset.Vals_ToString());
                                        batch2.maxCol     = batch2.charts.Count;
                                        batchlist.Add(batch2);
                                    }
                                }

                                if (mode == XYpairType.DiffVar_AcrossLevelsOfRptMeas)
                                {
                                    //#2 - back to original
                                    mysettings.current_xypairtype = mode;
                                    //mysettings.numvars = tmpvars;
                                    mysettings.xvars           = tmpvarsX;
                                    mysettings.yvars           = tmpvarsY;
                                    mysettings.manualXandYvars = true;
                                    mysettings.chartlayout     = DxLayout.Horizontal;

                                    List <string> rptmeasLevels = dt.AsEnumerable().Select(f => f.Field <string>(mysettings.repeatedmeasVarname))
                                                                  .Distinct().ToList();
                                    //HERE!!!!

                                    for (int i = 0; i < (rptmeasLevels.Count - 1); i++)
                                    {
                                        for (int j = i + 1; j < rptmeasLevels.Count; j++)
                                        {
                                            DataView dv = new DataView(dt);                                             // dt.AsDataView();
                                            dv.RowFilter = String.Format("{0} IN ('{1}','{2}')", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                            DataTable dt_sub = dv.ToTable();

                                            if (dt_sub.Rows.Count > 1)
                                            {
                                                DxChartBatch batch3 = new DxChartBatch(mysettings, dt_sub);
                                                PrepareBatch(batch3, (DxChartSettings)mysettings);
                                                batch3.batchtitle = String.Format("Variables ACROSS {0}:{1} & {2}", mysettings.repeatedmeasVarname, rptmeasLevels[i], rptmeasLevels[j]);
                                                batch3.maxCol     = batch3.charts.Count;
                                                batchlist.Add(batch3);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    #endregion

                    #region Actogram
                    else if (settings.outputtype == DxOutputtype.Actogram)
                    {
                        DxActogramSettings mysettings = (DxActogramSettings)settings;
                        mysettings.outputtype = DxOutputtype.Actogram;

                        List <string> varnames = new List <string>()
                        {
                            "id"
                        };
                        varnames.AddRange(mysettings.numvars);
                        varnames.Add(mysettings.xaxisvar);
                        varnames.Add(mysettings.colorvar);
                        varnames.RemoveAll(item => item == "variable");
                        varnames.RemoveAll(item => item == "none");


                        DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                            mysettings.panelvar
                        });

                        DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Actogram, mysettings);

                        foreach (DataSubset subset in subsets.subsets)
                        {
                            mysettings.date_txt = subset.dt.AsEnumerable().Min(f => f.Field <string>("report_date"));

                            DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                            foreach (DxChart sub in subbatch.charts)
                            {
                                batch2.charts.Add(sub);
                            }
                        }
                        PrepareBatch(batch2, mysettings);
                        batchlist.Add(batch2);
                    }
                    #endregion

                    #region Lineplot
                    else if (settings.outputtype == DxOutputtype.Lineplot)
                    {
                        DxLineplotSettings mysettings = (DxLineplotSettings)settings;

                        //NO Panels
                        if (mysettings.panelvar == "none" | mysettings.panelvar == "variable")
                        {
                            DxChartBatch batch1 = new DxChartBatch(mysettings, dt, " ");
                            PrepareBatch(batch1, settings);
                            batchlist.Add(batch1);
                        }
                        else
                        {
                            List <string> varnames = new List <string>()
                            {
                                "id"
                            };
                            varnames.AddRange(mysettings.numvars);
                            varnames.Add(mysettings.xaxisvar);
                            varnames.Add(mysettings.colorvar);
                            varnames.RemoveAll(item => item == "variable");
                            varnames.RemoveAll(item => item == "none");


                            DataSubsets subsets = new DataSubsets(dt, varnames, new List <string> {
                                mysettings.panelvar
                            });

                            DxChartBatch batch2 = new DxChartBatch(DxOutputtype.Lineplot, mysettings);
                            batch2.vars = mysettings.numvars;
                            foreach (DataSubset subset in subsets.subsets)
                            {
                                DxChartBatch subbatch = new DxChartBatch(mysettings, subset.dt, subset.Cols_and_Vals_ToString());

                                foreach (DxChart sub in subbatch.charts)
                                {
                                    batch2.charts.Add(sub);
                                }
                            }
                            PrepareBatch(batch2, mysettings);
                            batchlist.Add(batch2);
                        }
                    }
                    #endregion
                }
            }

            order.batches.AddRange(batchlist);

            //The invoice serves as a table of contents for what was actually created
            order.PrepareInvoice();
        }