public void CalculateZScoresWho2007() { var who2007 = new AnthStat.Statistics.WHO2007(); double ageMonths = double.Parse(TxtEdadMeses.Text); double Weight = double.Parse(TxtPeso.Text); double Lenght = double.Parse(TxtTalla.Text); double LenghtMeters = Lenght / 100; double imc = Weight / (LenghtMeters * LenghtMeters); double z = 0.0; double x = 0.0; double y = 0.0; TxtIMCCalculado.Text = Math.Round(imc, 2).ToString(); if (txtSexo.Text == "Masculino" || txtSexo.Text == "Masculino\t") { if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Male, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString(); TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Male, z: ref x)) { double p = StatisticsHelper.CalculatePercentile(x); TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString(); TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Male, z: ref y)) { double p = StatisticsHelper.CalculatePercentile(y); TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString(); TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString(); } } else if (txtSexo.Text == "Femenino" || txtSexo.Text == "Femenino\t") { if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: imc, age: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); TxtIMCEdadWho2007Z.Text = Math.Round(z, 2).ToString(); TxtIMCEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.WeightForAge, measurement: Weight, age: ageMonths, sex: Sex.Female, z: ref x)) { double p = StatisticsHelper.CalculatePercentile(x); TxtPesoEdadWho2007Z.Text = Math.Round(x, 2).ToString(); TxtPesoEdadWho2007P.Text = Math.Round(p, 2).ToString(); } if (who2007.TryCalculateZScore(indicator: Indicator.HeightForAge, measurement: Lenght, age: ageMonths, sex: Sex.Female, z: ref y)) { double p = StatisticsHelper.CalculatePercentile(y); TxtTallaEdadWho2007Z.Text = Math.Round(y, 2).ToString(); TxtTallaEdadWho2007P.Text = Math.Round(p, 2).ToString(); } } }
private static void TestWHO2007ComputeSpeed(bool forceInterpolate) { var who2007 = new AnthStat.Statistics.WHO2007(); var sw = new System.Diagnostics.Stopwatch(); var rnd = new System.Random(); int loopIterations = 1_000_000; double [] ageMonths = new double[loopIterations]; double [] bmis = new double[loopIterations]; Sex [] sexes = new Sex[loopIterations]; for (int i = 0; i < loopIterations; i++) { ageMonths[i] = rnd.Next(61, 228); if (forceInterpolate) { ageMonths[i] += 0.25; } bmis[i] = rnd.NextDouble() * 25; sexes[i] = ageMonths[i] % 2 == 0 ? Sex.Female : Sex.Male; } sw.Start(); for (int i = 0; i < loopIterations; i++) { double z = 0.0; bool success = who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: bmis[i], age: ageMonths[i], sex: sexes[i], z: ref z); } sw.Stop(); Console.WriteLine($"[WHO 2007] - Computed {loopIterations} z-scores in {sw.Elapsed.TotalMilliseconds.ToString("N0")} milliseconds [interpolate = {forceInterpolate}]"); }