コード例 #1
0
        private ConfLimit GetConfLimit(string value, float frequency, float count)
        {
            StatisticsRepository.cFreq freq = new StatisticsRepository.cFreq();
            double lower = 0;
            double upper = 0;

            if (frequency == count)
            {
                lower = 1;
                upper = 1;
                if (count < 300)
                {
                    lower = 0;
                    freq.ExactCI(frequency, (double)count, 95.0, ref lower, ref upper);
                    upper = 1;
                }
            }
            else
            {
                if (count >= 300)
                {
                    freq.WILSON(frequency, (double)count, 1.96, ref lower, ref upper);
                }
                else
                {
                    freq.ExactCI(frequency, (double)count, 95.0, ref lower, ref upper);
                }
            }
            ConfLimit cl = new ConfLimit();

            cl.Lower = lower;
            cl.Upper = upper;
            cl.Value = value;
            return(cl);
        }
コード例 #2
0
ファイル: Mapper.cs プロジェクト: cdc-dpbrown/EWAV
        public static Dictionary <string, double> GetConfLimit(double frequency, double count)
        {
            StatisticsRepository.cFreq freq = new StatisticsRepository.cFreq();
            double lower = 0;
            double upper = 0;

            if (frequency == count)
            {
                lower = 1;
                upper = 1;
            }
            else
            {
                if (count > 300)
                {
                    freq.FLEISS(frequency, count, 1.96, ref lower, ref upper);
                }
                else
                {
                    freq.ExactCI(frequency, count, 95.0, ref lower, ref upper);
                }
            }

            Dictionary <string, double> cl = new Dictionary <string, double>();

            cl.Add("lower", lower);
            cl.Add("upper", upper);

            //ConfLimit cl = new ConfLimit();
            //cl.Lower = lower;
            //cl.Upper = upper;
            //cl.Value = value;
            return(cl);
        }
コード例 #3
0
        /// <summary>
        /// Special method used to get the 95% confidence limit
        /// </summary>
        /// <param name="value">The value to run the CI on</param>
        /// <param name="frequency">The frequency of the value</param>
        /// <param name="count">The count</param>
        /// <returns>ConfLimit object containing the upper and lower limits</returns>
        private ConfLimit GetConfLimit(string value, double frequency, double count)
        {
            StatisticsRepository.cFreq freq = new StatisticsRepository.cFreq();
            double lower = 0;
            double upper = 0;

            if (frequency == count)
            {
                lower = 1;
                upper = 1;
            }
            else
            {
                if (count > 300)
                {
                    freq.FLEISS(frequency, (double)count, 1.96, ref lower, ref upper);
                }
                else
                {
                    freq.ExactCI(frequency, (double)count, 95.0, ref lower, ref upper);
                }
            }

            ConfLimit cl = new ConfLimit();
            cl.Lower = lower;
            cl.Upper = upper;
            cl.Value = value;
            return cl;
        }
        protected override void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            lock (syncLock)
            {
                this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToProcessingState));
                this.Dispatcher.BeginInvoke(new SimpleCallback(ClearResults));
                DrawFrequencyBordersDelegate drawBorders = new DrawFrequencyBordersDelegate(DrawOutputGridBorders);
                AddDataGridDelegate          addDataGrid = new AddDataGridDelegate(AddDataGrid);

                System.Collections.Generic.Dictionary <string, System.Data.DataTable> Freq_ListSet = new Dictionary <string, System.Data.DataTable>();

                try
                {
                    DataTable dt             = new DataTable();
                    bool      booleanResults = false;
                    int       fields         = -1;

                    if (Parameters.ColumnNames.Count > 0)
                    {
                        //if (DashboardHelper.GetAllGroupsAsList().Contains(freqVar))
                        //{
                        dt = DashboardHelper.GenerateCombinedFrequencyTable(Parameters as CombinedFrequencyParameters, ref booleanResults, ref fields);
                        //fields = DashboardHelper.GetVariablesInGroup(freqVar).Count;
                        //}
                    }
                    else
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), "Something that should never fail has failed.");
                        this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                        return;
                    }

                    if (dt == null || dt.Rows.Count == 0)
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.NO_RECORDS_SELECTED);
                        this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                        return;
                    }
                    else if (worker.CancellationPending)
                    {
                        this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), SharedStrings.DASHBOARD_GADGET_STATUS_OPERATION_CANCELLED);
                        this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                        Debug.Print("Combined frequency thread cancelled");
                        return;
                    }
                    else
                    {
                        string formatString = string.Empty;
                        double count        = Convert.ToDouble(dt.Compute("sum([count])", string.Empty));
                        string strataValue  = dt.TableName;
                        int    denominator  = DashboardHelper.RecordCount;

                        if (!string.IsNullOrEmpty(Parameters.CustomFilter.Trim()))
                        {
                            string globalFilter = DashboardHelper.DataFilters.GenerateDataFilterString(false);
                            string gadgetFilter = Parameters.CustomFilter.Trim();
                            if (DashboardHelper.DataFilters.Count > 0)
                            {
                                gadgetFilter = "(" + gadgetFilter + ") AND (" + globalFilter + ")";
                            }
                            denominator = DashboardHelper.DataSet.Tables[0].Select(gadgetFilter).Count();
                        }

                        if (!booleanResults)
                        {
                            denominator = denominator * fields;
                        }

                        dt.Columns[0].ColumnName = DashboardSharedStrings.COL_HEADER_VALUE;
                        dt.Columns[1].ColumnName = DashboardSharedStrings.COL_HEADER_FREQUENCY;
                        dt.Columns.Add(new DataColumn(DashboardSharedStrings.COL_HEADER_PERCENT, typeof(double)));

                        dt.Columns.Add("LCL", typeof(System.Double));
                        dt.Columns.Add("UCL", typeof(System.Double));
                        foreach (System.Data.DataRow row in dt.Rows)
                        {
                            if (!row[DashboardSharedStrings.COL_HEADER_VALUE].Equals(DBNull.Value))
                            {
                                double pct = 0;
                                if (denominator > 0)
                                {
                                    pct = Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]) / (double)denominator;
                                    row[DashboardSharedStrings.COL_HEADER_PERCENT] = pct;
                                    double lower = 0;
                                    double upper = 0;
                                    if (Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]) == (double)count)
                                    {
                                        lower = 0;
                                        freq.ExactCI(Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]), (double)denominator, 95.0, ref lower, ref upper);
                                        upper = 1;
                                    }
                                    else if (Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]) == 0.0)
                                    {
                                        upper = 0;
                                        freq.ExactCI(Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]), (double)denominator, 95.0, ref lower, ref upper);
                                        lower = 0;
                                    }
                                    else
                                    {
                                        if (denominator > 300)
                                        {
                                            freq.WILSON(Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]), (double)denominator, 1.96, ref lower, ref upper);
                                        }
                                        else
                                        {
                                            freq.ExactCI(Convert.ToDouble(row[DashboardSharedStrings.COL_HEADER_FREQUENCY]), (double)denominator, 95.0, ref lower, ref upper);
                                        }
                                    }
                                    row["LCL"] = lower;
                                    row["UCL"] = upper;
                                }
                            }
                        }

                        this.Dispatcher.BeginInvoke(addDataGrid, dt.AsDataView(), dt.TableName);
                        this.Dispatcher.BeginInvoke(new AddGridFooterDelegate(RenderFrequencyFooter), strataValue, denominator, fields, booleanResults);
                        //this.Dispatcher.BeginInvoke(drawBorders, strataValue);

                        this.Dispatcher.BeginInvoke(new SimpleCallback(RenderFinish));
                        //this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                    }
                }
                catch (Exception ex)
                {
                    this.Dispatcher.BeginInvoke(new RenderFinishWithErrorDelegate(RenderFinishWithError), ex.Message);
                    //this.Dispatcher.BeginInvoke(new SimpleCallback(SetGadgetToFinishedState));
                }
                finally
                {
                    //stopwatch.Stop();
                    //Debug.Print("Combined Frequency gadget took " + stopwatch.Elapsed.ToString() + " seconds to complete with " + dashboardHelper.RecordCount.ToString() + " records and the following filters:");
                    //Debug.Print(dashboardHelper.DataFilters.GenerateDataFilterString());
                }
            }
        }