public void TestAddTargetSignificanceDoesNothingIfTargetSignificanceIsAlreadySet()
 {
     var comparer = new SingleValueTargetComparer(SingleValueTargetComparerTest.Config(PolarityIds.RagLowIsGood));
     var data = new CoreDataSet{Value = 1};
     data.Significance.Add(ComparatorIds.Target, (int)Significance.Better);
     TargetComparer.AddTargetSignificance(data, comparer);
 }
 private void SetCoreData(CoreDataSet data, string key)
 {
     if (data != null && data.IsValueValid)
     {
         IndicatorToValue[key] = data;
     }
 }
        public override Significance Compare(CoreDataSet data, CoreDataSet comparator, IndicatorMetadata metadata)
        {
            if (CanComparisonGoAhead(data, comparator) == false || !data.IsDenominatorValid)
            {
                return Significance.None;
            }

            double unitValue = metadata.Unit.Value;

            double P1 = data.Value / unitValue;
            double numerator = P1;

            double confidenceVariableSquared = Math.Pow(ConfidenceVariable, 2.0);
            double P0 = comparator.Value / unitValue;
            double N1 = data.Denominator;
            double E1 = N1 * P0;

            // B
            double Bs1 = 1.0 - (E1 / N1);
            double Bs2 = 4.0 * E1 * Bs1;
            double Bs3 = confidenceVariableSquared + Bs2;
            double B = ConfidenceVariable * Math.Sqrt(Bs3);

            // Control limits
            double A = (2.0 * E1) + confidenceVariableSquared;
            double C = 2.0 * (N1 + confidenceVariableSquared);
            double L3SD = (A - B) / C;
            double U3SD = (A + B) / C;

            return GetSignificanceFromSDs(numerator, L3SD, U3SD);
        }
 public void TestAddSignificanceIgnoresDuplicateAdditions()
 {
     var data = new CoreDataSet();
     data.AddSignificance(1, Significance.Better);
     data.AddSignificance(1, Significance.None);
     Assert.AreEqual((int)Significance.Better, data.Significance.Values.First());
 }
        public override Significance CompareAgainstTarget(CoreDataSet data)
        {
            if (CanComparisonGoAhead(data) == false)
            {
                return Significance.None;
            }

            var val = data.Value;
            Significance significance = Significance.Worse;

            if (PolarityId == PolarityIds.RagLowIsGood)
            {
                if (val <= Config.LowerLimit)
                {
                    significance = Significance.Better;
                }
            }
            else
            {
                if (val >= Config.LowerLimit)
                {
                    significance = Significance.Better;
                }
            }

            return significance;
        }
        public void TestDenominatorInvalid()
        {
            CoreDataSet comparator = new CoreDataSet { Value = 10 };
            IndicatorMetadata metadata = new IndicatorMetadata();

            Significance sig = New95_0().Compare(new CoreDataSet
            {
                Value = 10,
                LowerCI = 11,
                UpperCI = 12,
                Denominator = 0
            },
            comparator, metadata
            );

            Assert.AreEqual(Significance.None, sig);

            sig = New95_0().Compare(new CoreDataSet
            {
                Value = 10,
                LowerCI = 11,
                UpperCI = 12,
                Denominator = -1
            },
            comparator, metadata
            );

            Assert.AreEqual(Significance.None, sig);
        }
 public void TestFormatAndTruncateData()
 {
     var data = new CoreDataSet { Value = Number };
     DataProcessor().FormatAndTruncate(data);
     Assert.AreEqual("1.11", data.ValueFormatted);
     AssertValueTruncatedAsExpected(data);
 }
        public void TestSame()
        {
            CoreDataSet parent = new CoreDataSet { Value = 3.0 };
            CoreDataSet data = new CoreDataSet { Value = 3.05, LowerCI = 2.7, UpperCI = 3.1 };

            Assert.AreEqual(Significance.Same, Compare(data, parent, 0));
        }
 public void TestFormatAndTruncateCoreDataList()
 {
     var data = new CoreDataSet { Value = Number };
     CoreDataProcessor().FormatAndTruncateList(new List<CoreDataSet> { data });
     AssertValueTrucatedAsExpected(data);
     Assert.AreEqual("1.11", data.ValueFormatted);
 }
        public override Significance CompareAgainstTarget(CoreDataSet data)
        {

            if (UpperTargetPercentileBenchmarkData == null 
                || LowerTargetPercentileBenchmarkData == null 
                || CanComparisonGoAhead(data) == false 
                || UpperTargetPercentileBenchmarkData.IsValueValid == false 
                || LowerTargetPercentileBenchmarkData.IsValueValid == false)
            {
                return Significance.None;
            }

            if (Config.PolarityId == 1)
            {
                return data.Value < LowerTargetPercentileBenchmarkData.Value
                    ? Significance.Worse
                    : (data.Value >= UpperTargetPercentileBenchmarkData.Value ? Significance.Better : Significance.Same);
            }

            if (Config.PolarityId == 0)
            {
                return data.Value < LowerTargetPercentileBenchmarkData.Value
                    ? Significance.Better
                    : (data.Value >= UpperTargetPercentileBenchmarkData.Value ? Significance.Worse : Significance.Same);

            }
            return Significance.None;
        }
 private Significance Compare(CoreDataSet data, CoreDataSet parent, int polarity)
 {
     var comparer = new DoubleOverlappingCIsComparer
     {
         PolarityId = polarity
     };
     return comparer.Compare(data, parent, null);
 }
        public void TestMinusOneParent()
        {
            CoreDataSet parent = new CoreDataSet { Value = CoreDataSet.NullValue };
            CoreDataSet data = new CoreDataSet { Value = 2.5, LowerCI = 2.2, UpperCI = 2.8 };

            Assert.AreEqual(Significance.None, Compare(data, parent, 0));
            Assert.AreEqual(Significance.None, Compare(data, parent, 1));
        }
        public void TestLower()
        {
            CoreDataSet parent = new CoreDataSet { Value = 3.0 };
            CoreDataSet data = new CoreDataSet { Value = 2.5, LowerCI = 2.2, UpperCI = 2.8 };

            Assert.AreEqual(Significance.Better, Compare(data, parent, 0));
            Assert.AreEqual(Significance.Worse, Compare(data, parent, 1));
        }
 /// <summary>
 /// Helper method to set the target significance. Only used to reduce duplicated code.
 /// </summary>
 public static void AddTargetSignificance(CoreDataSet data, TargetComparer targetComparer)
 {
     if (data != null && targetComparer != null)
     {
         Significance significance = targetComparer.CompareAgainstTarget(data);
         data.AddSignificance(ComparatorIds.Target, significance);
     }
 }
        public void TestSameExactly()
        {
            CoreDataSet parent = new CoreDataSet { Value = 11 };
            CoreDataSet data = new CoreDataSet { Value = 11, LowerCI = 10, UpperCI = 12 };

            Assert.AreEqual(Significance.Same, Compare(data, parent, 0));
            Assert.AreEqual(Significance.Same, Compare(data, parent, 1));
        }
        public void TestAreCIsValidFalseIfNoUpperCI()
        {
            var data = new CoreDataSet
            {
                LowerCI = 1,
                UpperCI = ValueData.NullValue
            };

            Assert.IsFalse(data.AreCIsValid);
        }
        public void TestDifferent()
        {
            // Different data > parent
            CoreDataSet d1 = new CoreDataSet { Value = 3.0, LowerCI = 2.7, UpperCI = 3.1 };
            CoreDataSet d2 = new CoreDataSet { Value = 4.0, LowerCI = 3.5, UpperCI = 4.5 };
            Assert.AreEqual(Significance.Worse, Compare(d2, d1, 0));

            // Different data < parent
            Assert.AreEqual(Significance.Better, Compare(d1, d2, 0));
        }
        public void TestAreCIsValidTrue()
        {
            var data = new CoreDataSet
            {
                LowerCI = 1,
                UpperCI = 1
            };

            Assert.IsTrue(data.AreCIsValid);
        }
        public void TestCanFormatDataWithoutStats()
        {
            CoreDataSet data = new CoreDataSet()
            {
                Value = 100
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), null);
            formatter.Format(data);
        }
 public TrendDataPoint(CoreDataSet coreDataSet)
 {
     Value = coreDataSet.Value;
     ValueF = coreDataSet.ValueFormatted;
     LowerCIF = coreDataSet.LowerCIF;
     UpperCIF = coreDataSet.UpperCIF;
     ValueNoteId = coreDataSet.ValueNoteId;
     Count = coreDataSet.Count;
     Significance = new Dictionary<int, Significance>();
 }
        public void TestCoreDataSetValueMinusOne()
        {
            CoreDataSet data = new CoreDataSet()
            {
                Value = -1
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), null);
            formatter.Format(data);
            Assert.AreEqual(NumericFormatter.NoValue, data.ValueFormatted);
        }
        public void TestCanFormatWithoutStatsLessThanOne()
        {
            CoreDataSet data = new CoreDataSet()
            {
                Value = 0.1234
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), null);
            formatter.Format(data);
            Assert.AreEqual("0.123", data.ValueFormatted);
        }
 public void TestFormatCIs()
 {
     var data = new CoreDataSet
     {
         UpperCI = 2.222222222,
         LowerCI = Number
     };
     CoreDataProcessor().FormatAndTruncate(data);
     Assert.AreEqual("1.11", data.LowerCIF);
     Assert.AreEqual("2.22", data.UpperCIF);
 }
        public void TestCanFormatWithoutStats100s()
        {
            CoreDataSet data = new CoreDataSet
            {
                Value = 200.122
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), null);
            formatter.Format(data);
            Assert.AreEqual("200.1", data.ValueFormatted);
        }
        public void TestCoreDataSetZero()
        {
            CoreDataSet data = new CoreDataSet()
            {
                Value = 0
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), null);
            formatter.Format(data);

            Assert.AreEqual("0.0", data.ValueFormatted);
        }
        public void TestCoreDataSet1000s()
        {
            CoreDataSet data = new CoreDataSet()
            {
                Value = 4567.77777
            };

            NumericFormatter formatter = NumericFormatterFactory.NewWithLimits(GetMetadata(), GetStats(5000));
            formatter.Format(data);

            Assert.AreEqual("4568", data.ValueFormatted);
        }
        private void Add(CoreDataSet data)
        {
            if (displayedEthnicity > 0)
            {
                sb.Append(", ");
            }

            displayedEthnicity += data.Value;

            sb.Append(Percentage(data.Value));

            var category = categories.First(x => x.Id == data.CategoryId);
            sb.Append(category.ShortName.ToLower());
        }
        public void TestNoCIsReturnNoneSignificance()
        {
            // No Lower CI
            CoreDataSet d1 = new CoreDataSet { Value = 3.0, LowerCI = ValueWithCIsData.NullValue, UpperCI = 3.1 };
            CoreDataSet d2 = new CoreDataSet { Value = 4.0, LowerCI = 3.5, UpperCI = 4.5 };
            Assert.AreEqual(Significance.None, Compare(d2, d1, 0));
            Assert.AreEqual(Significance.None, Compare(d1, d2, 0));

            // No Upper CI
            d1 = new CoreDataSet { Value = 3.0, LowerCI = 2.9, UpperCI = ValueWithCIsData.NullValue };
            d2 = new CoreDataSet { Value = 4.0, LowerCI = 3.5, UpperCI = 4.5 };
            Assert.AreEqual(Significance.None, Compare(d2, d1, 0));
            Assert.AreEqual(Significance.None, Compare(d1, d2, 0));
        }
        public override Significance CompareAgainstTarget(CoreDataSet data)
        {
            // Note: Polarity is not considered

            if (BenchmarkData == null ||
                CanComparisonGoAhead(data) == false ||
                BenchmarkData.IsValueValid == false)
            {
                return Significance.None;
            }

            return data.Value < BenchmarkData.Value
                ? Significance.Worse
                : Significance.Better;
        }
        /// <summary>
        /// Gets the significance of the data value against the benchmark 
        /// or against a target 
        /// or the category a value falls in, e.g. quintile
        /// </summary>
        /// <param name="data">The data that the comparison will be made against</param>
        /// <param name="benchmarkData">Is not required if the comparison is against a target or to determine the category a value falls in</param>
        public int GetSignificance(CoreDataSet data, CoreDataSet benchmarkData)
        {
            if (targetComparer != null)
            {
                return (int)targetComparer.CompareAgainstTarget(data);
            }

            ICategoryComparer categoryComparer = comparer as ICategoryComparer;
            if (categoryComparer != null)
            {
                return categoryComparer.GetCategory(data);
            }

            return (int)comparer.Compare(data, benchmarkData, indicatorMetadata);
        }