예제 #1
0
        private static void TestWHO2006ComputeSpeed()
        {
            var who2006 = new AnthStat.Statistics.WHO2006();

            var sw = new System.Diagnostics.Stopwatch();

            var rnd            = new System.Random();
            int loopIterations = 1_000_000;

            int []    ageDays = new int[loopIterations];
            double [] bmis    = new double[loopIterations];
            Sex []    sexes   = new Sex[loopIterations];

            for (int i = 0; i < loopIterations; i++)
            {
                ageDays[i] = rnd.Next(0, 1856);
                bmis[i]    = rnd.NextDouble() * 25;
                sexes[i]   = ageDays[i] % 2 == 0 ? Sex.Female : Sex.Male;
            }

            sw.Start();

            for (int i = 0; i < loopIterations; i++)
            {
                double z = 0.0;
                who2006.TryCalculateZScore(Indicator.BodyMassIndexForAge, bmis[i], ageDays[i], sexes[i], ref z);
            }

            sw.Stop();

            Console.WriteLine($"[WHO 2006] - Computed {loopIterations} z-scores in {sw.Elapsed.TotalMilliseconds.ToString("N0")} milliseconds.");
        }
예제 #2
0
        public void CalculateZScoresWho2006()
        {
            var    who2006      = new AnthStat.Statistics.WHO2006();
            double ageDays      = double.Parse(TxtEdad.Text);
            double Weight       = double.Parse(TxtPeso.Text);
            double Lenght       = double.Parse(TxtTalla.Text);
            double CC           = double.Parse(TxtCC.Text);
            double CMB          = double.Parse(TxtCMB.Text);
            double Muac         = double.Parse(TxtTricep.Text);
            double LenghtMeters = Lenght / 100;
            double imc          = Weight / (LenghtMeters * LenghtMeters);

            TxtIMCCalculado.Text = Math.Round(imc, 2).ToString();

            double z = 0.0;
            double x = 0.0;
            double y = 0.0;
            double w = 0.0;

            if (txtSexo.Text == "Masculino" || txtSexo.Text == "Masculino\t")
            {
                if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: imc, measurement2: ageDays, sex: Sex.Male, z: ref z))
                {
                    TxtZIMC.Text = Math.Round(z, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(z);
                    TxtImc.Text = Math.Round(p, 1).ToString();
                }
                if (ageDays > 720)
                {
                    if (who2006.TryCalculateZScore(indicator: Indicator.WeightForHeight, measurement1: Weight, measurement2: Lenght, sex: Sex.Male, z: ref x))
                    {
                        TxtZPesoTalla.Text = Math.Round(x, 2).ToString();
                        double p = StatisticsHelper.CalculatePercentile(x);
                        TxtPesoTalla.Text = Math.Round(p, 1).ToString();
                    }
                }
                if (ageDays < 720)
                {
                    if (who2006.TryCalculateZScore(indicator: Indicator.WeightForLength, measurement1: Weight, measurement2: Lenght, sex: Sex.Male, z: ref x))
                    {
                        TxtZPesoTalla.Text = Math.Round(x, 2).ToString();
                        double p = StatisticsHelper.CalculatePercentile(x);
                        TxtPesoTalla.Text = Math.Round(p, 1).ToString();
                    }
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement1: Weight, measurement2: ageDays, sex: Sex.Male, z: ref y))
                {
                    TxtZPesoEdad.Text = Math.Round(y, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(y);
                    TxtPesoEdad.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.LengthForAge, measurement1: Lenght, measurement2: ageDays, sex: Sex.Male, z: ref w))
                {
                    TxtZTallaEdad.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtTallaEdad.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.HeadCircumferenceForAge, measurement1: CC, measurement2: ageDays, sex: Sex.Male, z: ref w))
                {
                    TxtZCC.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtCCP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.ArmCircumferenceForAge, measurement1: CMB, measurement2: ageDays, sex: Sex.Male, z: ref w))
                {
                    TxtZMuac.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtMuacP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.TricepsSkinfoldForAge, measurement1: double.Parse(TxtTricep.Text), measurement2: ageDays, sex: Sex.Male, z: ref w))
                {
                    TxtTSFZ.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtTSFP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.SubscapularSkinfoldForAge, measurement1: double.Parse(TxtSSF.Text), measurement2: ageDays, sex: Sex.Male, z: ref w))
                {
                    TxtSSFZ.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtSSFP.Text = Math.Round(p, 1).ToString();
                }
            }
            else if (txtSexo.Text == "Femenino" || txtSexo.Text == "Femenino\t")
            {
                if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: imc, measurement2: ageDays, sex: Sex.Female, z: ref z))
                {
                    TxtZIMC.Text = Math.Round(z, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(z);
                    TxtImc.Text = Math.Round(p, 1).ToString();
                }
                if (ageDays > 720)
                {
                    if (who2006.TryCalculateZScore(indicator: Indicator.WeightForHeight, measurement1: Weight, measurement2: Lenght, sex: Sex.Female, z: ref x))
                    {
                        TxtZPesoTalla.Text = Math.Round(x, 2).ToString();
                        double p = StatisticsHelper.CalculatePercentile(x);
                        TxtPesoTalla.Text = Math.Round(p, 1).ToString();
                    }
                }
                if (ageDays < 720)
                {
                    if (who2006.TryCalculateZScore(indicator: Indicator.WeightForLength, measurement1: Weight, measurement2: Lenght, sex: Sex.Female, z: ref x))
                    {
                        TxtZPesoTalla.Text = Math.Round(x, 2).ToString();
                        double p = StatisticsHelper.CalculatePercentile(x);
                        TxtPesoTalla.Text = Math.Round(p, 1).ToString();
                    }
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement1: Weight, measurement2: ageDays, sex: Sex.Female, z: ref y))
                {
                    TxtZPesoEdad.Text = Math.Round(y, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(y);
                    TxtPesoEdad.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.LengthForAge, measurement1: Lenght, measurement2: ageDays, sex: Sex.Female, z: ref w))
                {
                    TxtZTallaEdad.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtTallaEdad.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.HeadCircumferenceForAge, measurement1: CC, measurement2: ageDays, sex: Sex.Female, z: ref w))
                {
                    TxtZCC.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtCCP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.ArmCircumferenceForAge, measurement1: CMB, measurement2: ageDays, sex: Sex.Female, z: ref w))
                {
                    TxtZMuac.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtMuacP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.TricepsSkinfoldForAge, measurement1: double.Parse(TxtTricep.Text), measurement2: ageDays, sex: Sex.Female, z: ref w))
                {
                    TxtTSFZ.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtTSFP.Text = Math.Round(p, 1).ToString();
                }
                if (who2006.TryCalculateZScore(indicator: Indicator.SubscapularSkinfoldForAge, measurement1: double.Parse(TxtSSF.Text), measurement2: ageDays, sex: Sex.Female, z: ref w))
                {
                    TxtSSFZ.Text = Math.Round(w, 2).ToString();
                    double p = StatisticsHelper.CalculatePercentile(w);
                    TxtSSFP.Text = Math.Round(p, 1).ToString();
                }
            }
        }