private IActionResult Calculate(Sex sex, Indicator indicator, double measurement1, double measurement2) { double z = default(double); bool success = _whoReference.TryCalculateZScore(Indicator.BodyMassIndexForAge, measurement1, measurement2, sex, ref z); if (success) { var scoreResult = new ZScoreResult() { Z = z, P = StatisticsHelper.CalculatePercentile(z), Reference = "WHO2007", Sex = sex, Indicator = indicator, InputMeasurement1 = measurement1, InputMeasurement2 = measurement2 }; return(Ok(scoreResult)); } else { return(BadRequest()); } }
static void Main(string[] args) { var cdc2000 = new CDC2000(); var who2006 = new WHO2006(); var who2007 = new WHO2007(); // Calculates a BMI-for-age z-score using CDC 2000 double ageMonths = 26; double z = 0.0; double bmi = 18.0; if (cdc2000.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: bmi, measurement2: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[CDC 2000] - {ageMonths} month old female with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in months for the CDC 2000 BMI-for-age indicator."); } // Calculates a BMI-for-age z-score using WHO 2006 double ageDays = 32; bmi = 16; if (who2006.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement1: bmi, measurement2: ageDays, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[WHO 2006] - {ageDays} day old female with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in days for the WHO 2006 BMI-for-age indicator."); } // Calculates a BMI-for-age z-score using WHO 2007 ageMonths = 64; bmi = 17; if (who2007.TryCalculateZScore(indicator: Indicator.BodyMassIndexForAge, measurement: bmi, age: ageMonths, sex: Sex.Female, z: ref z)) { double p = StatisticsHelper.CalculatePercentile(z); z = Math.Round(z, 2); p = Math.Round(p, 2); Console.WriteLine($"[WHO 2007] - {ageMonths} month old male with BMI = {bmi} has z-score of {z} and percentile of {p}"); } else { Console.WriteLine($"{ageMonths} is a valid age in months for the WHO 2007 BMI-for-age indicator."); } Console.WriteLine(); // If interested in performance tests, see below TestCDC2000ComputeSpeed(true); // forces test to use interpolation of L, M, and S values (more computationally expensive) TestCDC2000ComputeSpeed(false); // forces test to never use interpolation Console.WriteLine(); TestWHO2006ComputeSpeed(); // WHO 2006 standard doesn't typically need interpolation since age is measured in days, and trying to interpolate LMS values between e.g. day 66 and 67 is not worthwhile Console.WriteLine(); TestWHO2007ComputeSpeed(true); // forces test to use interpolation of L, M, and S values (more computationally expensive) TestWHO2007ComputeSpeed(false); // forces test to never use interpolation }